# 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.

## 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 on other sites
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 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 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 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 on other sites
That does the trick for the file path in the edit box. How do I get the text out of the edit box if the user types in a path that doesn't exist?

##### Share on other sites
Nevermind, I used GetWindowText() in the BFFM_VALIDATEFAILED message and got what I needed.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46