SHBrowseForFolder question

Started by
5 comments, last by darkchrono4 19 years, 7 months ago
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.
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.
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."
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
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.
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;}
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
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?
Nevermind, I used GetWindowText() in the BFFM_VALIDATEFAILED message and got what I needed.

This topic is closed to new replies.

Advertisement