Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.0 KiB

  1. //
  2. // Browse.C
  3. //
  4. #include "sigverif.h"
  5. // Global browse buffer that is used until user click OK or Cancel
  6. TCHAR g_szBrowsePath[MAX_PATH];
  7. //
  8. // This callback function handles the initialization of the browse dialog and when
  9. // the user changes the selection in the tree-view. We want to keep updating the
  10. // g_szBrowsePath buffer with selection changes until the user clicks OK.
  11. //
  12. int CALLBACK BrowseCallbackProc( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData )
  13. {
  14. int iRet = 0;
  15. TCHAR PathName[MAX_PATH];
  16. LPTSTR lpPathName = PathName;
  17. LPITEMIDLIST lpid;
  18. switch(uMsg)
  19. {
  20. case BFFM_INITIALIZED: // Initialize the dialog with the OK button and g_szBrowsePath
  21. SendMessage(hwnd, BFFM_ENABLEOK, (WPARAM) 0, (LPARAM) 1);
  22. SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM) TRUE, (LPARAM) g_szBrowsePath);
  23. break;
  24. case BFFM_SELCHANGED: lpid = (LPITEMIDLIST) lParam;
  25. if (SHGetPathFromIDList(lpid, lpPathName))
  26. {
  27. // If the path is good, then update g_szBrowsePath
  28. lstrcpy(g_szBrowsePath, lpPathName);
  29. }
  30. SendMessage(hwnd, BFFM_ENABLEOK, (WPARAM) 0, (LPARAM) 1);
  31. break;
  32. }
  33. return iRet;
  34. }
  35. //
  36. // This uses SHBrowseForFolder to get the directory the user wants to search.
  37. // We specify a callback function that updates g_szBrowsePath until the user clicks OK or Cancel.
  38. // If they clicked OK, then we update the string passed in to us as lpszBuf.
  39. //
  40. //
  41. BOOL BrowseForFolder(HWND hwnd, LPTSTR lpszBuf) {
  42. BROWSEINFO bi;
  43. TCHAR szBuffer[MAX_PATH],
  44. szMessage[256];
  45. LPITEMIDLIST lpid;
  46. // Check if the lpszBuf path is valid, if so use that as the browse dialog's initial directory.
  47. // If it isn't valid, initialize g_szBrowsePath with the Windows directory.
  48. if (!SetCurrentDirectory(lpszBuf))
  49. {
  50. MyGetWindowsDirectory(g_szBrowsePath, MAX_PATH);
  51. } else lstrcpy(g_szBrowsePath, lpszBuf);
  52. // Start the root of the browse dialog in the CSIDL_DRIVES namespace
  53. if ( !SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES, &lpid)) )
  54. return FALSE;
  55. // This loads in the "Please select a directory" text into the dialog.
  56. MyLoadString(szMessage, IDS_SELECTDIR);
  57. //
  58. // Setup the BrowseInfo struct.
  59. //
  60. bi.hwndOwner = hwnd;
  61. bi.pidlRoot = lpid;
  62. bi.pszDisplayName = szBuffer;
  63. bi.lpszTitle = szMessage;
  64. bi.ulFlags = BIF_RETURNONLYFSDIRS;
  65. bi.lpfn = (BFFCALLBACK) BrowseCallbackProc;
  66. bi.lParam = 0x123;
  67. if (SHBrowseForFolder(&bi) == NULL)
  68. return FALSE;
  69. // The user must have clicked OK, so we can update lpszBuf with g_szBrowsePath!
  70. lstrcpy(lpszBuf, g_szBrowsePath);
  71. return TRUE;
  72. }