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.

114 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(
  13. HWND hwnd,
  14. UINT uMsg,
  15. LPARAM lParam,
  16. LPARAM lpData
  17. )
  18. {
  19. int iRet = 0;
  20. TCHAR PathName[MAX_PATH];
  21. LPTSTR lpPathName = PathName;
  22. LPITEMIDLIST lpid;
  23. switch (uMsg) {
  24. case BFFM_INITIALIZED:
  25. //
  26. // Initialize the dialog with the OK button and g_szBrowsePath
  27. //
  28. SendMessage(hwnd, BFFM_ENABLEOK, (WPARAM) 0, (LPARAM) 1);
  29. SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM) TRUE, (LPARAM) g_szBrowsePath);
  30. break;
  31. case BFFM_SELCHANGED:
  32. lpid = (LPITEMIDLIST) lParam;
  33. if (SHGetPathFromIDList(lpid, lpPathName)) {
  34. //
  35. // If the path is good, then update g_szBrowsePath
  36. //
  37. lstrcpy(g_szBrowsePath, lpPathName);
  38. }
  39. SendMessage(hwnd, BFFM_ENABLEOK, (WPARAM) 0, (LPARAM) 1);
  40. break;
  41. }
  42. return iRet;
  43. }
  44. //
  45. // This uses SHBrowseForFolder to get the directory the user wants to search.
  46. // We specify a callback function that updates g_szBrowsePath until the user clicks OK or Cancel.
  47. // If they clicked OK, then we update the string passed in to us as lpszBuf.
  48. //
  49. //
  50. BOOL BrowseForFolder(HWND hwnd, LPTSTR lpszBuf) {
  51. BROWSEINFO bi;
  52. TCHAR szBuffer[MAX_PATH],
  53. szMessage[MAX_PATH];
  54. LPITEMIDLIST lpid;
  55. //
  56. // Check if the lpszBuf path is valid, if so use that as the browse dialog's initial directory.
  57. // If it isn't valid, initialize g_szBrowsePath with the Windows directory.
  58. //
  59. if (!SetCurrentDirectory(lpszBuf)) {
  60. MyGetWindowsDirectory(g_szBrowsePath, MAX_PATH);
  61. } else {
  62. lstrcpy(g_szBrowsePath, lpszBuf);
  63. }
  64. //
  65. // Start the root of the browse dialog in the CSIDL_DRIVES namespace
  66. //
  67. if (!SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES, &lpid))) {
  68. return FALSE;
  69. }
  70. //
  71. // This loads in the "Please select a directory" text into the dialog.
  72. //
  73. MyLoadString(szMessage, IDS_SELECTDIR);
  74. //
  75. // Setup the BrowseInfo struct.
  76. //
  77. bi.hwndOwner = hwnd;
  78. bi.pidlRoot = lpid;
  79. bi.pszDisplayName = szBuffer;
  80. bi.lpszTitle = szMessage;
  81. bi.ulFlags = BIF_RETURNONLYFSDIRS;
  82. bi.lpfn = (BFFCALLBACK) BrowseCallbackProc;
  83. bi.lParam = 0x123;
  84. if (SHBrowseForFolder(&bi) == NULL) {
  85. return FALSE;
  86. }
  87. //
  88. // The user must have clicked OK, so we can update lpszBuf with g_szBrowsePath!
  89. //
  90. lstrcpy(lpszBuf, g_szBrowsePath);
  91. return TRUE;
  92. }