Jump to content
  • Advertisement
Sign in to follow this  
darkchrono4

SHBrowseForFolder question

This topic is 5474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use the BIF_EDITBOX flag, but I don't know how to set the text or get it back. The rest of the dialog works as it should. This is with Win32 and straight C.

Share this post


Link to post
Share on other sites
Advertisement
Nobody? Just trying to do a little installer and use the edit box for the user to enter a folder that doesn't exist. But unless the folder passed in the BROWSEINFO exists the edit box just says 'My Computer' and even if the folder does exist it does show the complete path just the folder name.

Share this post


Link to post
Share on other sites
I think you have to use the BROWSEINFO::lpfn member to set an "Address of an application-defined function that the dialog box calls when an event occurs. For more information, see the BrowseCallbackProc function."

Share this post


Link to post
Share on other sites
I do that to set the starting folder the dialog opens up with. But say the path is C:\test1\test2 only test2 shows up in the edit box. And still if the folder does not exist My Computer is displayed in the edit box.

Share this post


Link to post
Share on other sites
Something like this?

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlobj.h>

int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM pData)
{
const int iEditMagicItemId = 0x3744;

switch (uMsg)
{
case BFFM_INITIALIZED:
{
SendMessage(hWnd, BFFM_SETSELECTION, TRUE, pData);
HWND hEdit = GetDlgItem(hWnd, iEditMagicItemId);
if (hEdit)
SetWindowText(hEdit, LPCTSTR(pData));
}
break;
case BFFM_IUNKNOWN:
break;
case BFFM_SELCHANGED:
{
char szPath[MAX_PATH];
SHGetPathFromIDList(LPITEMIDLIST(lParam), szPath);
HWND hEdit = GetDlgItem(hWnd, iEditMagicItemId);
if (hEdit)
SetWindowText(hEdit, szPath);
}
break;
case BFFM_VALIDATEFAILED:
break;
default:
break;
}

return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iShowCmd)
{
IMalloc* pMalloc = NULL;
SHGetMalloc(&pMalloc);
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(bi));
bi.ulFlags = BIF_EDITBOX;
bi.lParam = LPARAM("C:\\Path\\That\\Does\\Not\\Exist");
bi.lpfn = &BrowseCallbackProc;
ITEMIDLIST* pItemIdList = SHBrowseForFolder(&bi);
pMalloc->Free(pItemIdList);
pMalloc->Release();
return 0;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!