Leaked source code of windows server 2003
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.

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