|
It may be that my problem is not very clear. code show as below:
static TCHAR szdir[MAX_PATH];
INT CALLBACK BrowseCallbackProc(HWND hwnd,
UINT uMsg,
LPARAM lp,
LPARAM pData)
{
DWORD dwResult;
To
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);
To
GetTempPath(MAX_PATH,TempDirectory); // 2222
MessageBox(NULL,TempDirectory,NULL,MB_OK);
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)TempDirectory);
break;
To
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;
To
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;
To
pidlSelected = SHBrowseForFolder(&bi);
To
if (!pidlSelected)
return 1; // user selected cancel
To
pMalloc->lpVtbl->Free(pMalloc,pidlSelected);
pMalloc->lpVtbl->Release(pMalloc);
return 0;
}
Now when the browse folder window is opened, the default focus is on "My Computer", the system disk C drive is open, but the system temp directory (ie TempDirectory) is not selected by default. |
|