| |

VerySource

 Forgot password?
 Register
Search
View: 818|Reply: 6

How can the initial path of SHBrowseForFolder be set to the system temp directory

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-29 00:20:01
| Show all posts |Read mode
As the title, the default directory is initialized in the BFFM_INITIALIZED message in the callback function:
SendMessage (hwnd, BFFM_SETSELECTION, TRUE, (LPARAM) "d:\\aaa\\");
It can be implemented correctly, but it cannot be implemented if the default directory is the system temp directory obtained using GetTempPath. The estimated reason is that there will be hidden directories when reaching the system temp directory.
Reply

Use magic Report

0

Threads

21

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 Canada

Post time: 2020-3-8 17:45:01
| Show all posts
use SHGetSpecialLocaion to get the pidl of temp path and pass it to the dialog
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 Invalid IP Address

Post time: 2020-3-22 13:30:01
| Show all posts
CString GetSpecialPath (int CSIDL)
{
   LPITEMIDLIST pidl;
   CString str = "";
   HRESULT r = SHGetSpecialFolderLocation (0, CSIDL,&pidl);
   if (r == NOERROR)
   {
      TCHAR szPath [INFO_BUFFER_SIZE];
      if (SHGetPathFromIDList (pidl, szPath))
      {
         str = CString (szPath);
      }
   }
   return str;
}
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-7-23 19:00:01
| Show all posts
Thank you upstairs, but the CSIDL value of the system temp directory was not found in shloj.h.
Please also give pointers.
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-7-28 11:15:01
| Show all posts
Are you talking about the\Windows\Temp directory?

GetWindowsDirectory and then add it manually
Reply

Use magic Report

0

Threads

45

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 United States

Post time: 2020-7-28 12:00:02
| Show all posts
Or use environment variables

ExpandEnvironmentStrings

There should be no problem with GetTempPath, right? Use GetLastError to see what the error is.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-7-31 16:15:01
| Show all posts
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.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list