|
楼主 |
发表于 2020-7-31 16:15:01
|
显示全部楼层
可能是我的问题描述的不很清楚。代码如下:
static TCHAR szdir[MAX_PATH];
INT CALLBACK BrowseCallbackProc(HWND hwnd,
UINT uMsg,
LPARAM lp,
LPARAM pData)
{
DWORD dwResult;
switch(uMsg)
{
case BFFM_INITIALIZED:
// WParam is TRUE since you are passing a path.
// It would be FALSE if you were passing a pidl.
dwResult = ExpandEnvironmentStrings(
"%TMP%",
TempDirectory,
MAX_PATH); // 1111
MessageBox(NULL,TempDirectory,NULL,MB_OK);
GetTempPath(MAX_PATH,TempDirectory); // 2222
MessageBox(NULL,TempDirectory,NULL,MB_OK);
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)TempDirectory);
break;
case BFFM_SELCHANGED:
// Set the status window to the currently selected path.
if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szdir))
{
SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szdir);
}
break;
}
return 0;
}
int BrowseForFolder(int first)
{
LPITEMIDLIST pidlSelected = NULL;
BROWSEINFO bi = {0};
LPMALLOC pMalloc = NULL;
SHGetMalloc(&pMalloc);
ZeroMemory(&bi,sizeof(bi));
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = 0;
if (first)
bi.lpszTitle = "Setting temp folder, you may change it from menu.";
else
bi.lpszTitle = "Change Temp Directory";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
bi.lpfn = BrowseCallbackProc;
bi.lParam = 0;
pidlSelected = SHBrowseForFolder(&bi);
if (!pidlSelected)
return 1; // user selected cancel
pMalloc->lpVtbl->Free(pMalloc,pidlSelected);
pMalloc->lpVtbl->Release(pMalloc);
return 0;
}
现在浏览文件夹窗口打开后默认焦点在“我的电脑”上,系统盘C盘是打开状态的,但是没有默认选中系统temp目录(即TempDirectory)。 |
|