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.

97 lines
2.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: browsedi.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // BrowseDir.cpp
  12. //
  13. #include "stdafx.h"
  14. #include <shlobj.h>
  15. int
  16. InitStartDir(
  17. HWND hwnd,
  18. UINT uMsg,
  19. LPARAM, // lParam
  20. LPARAM lpData)
  21. {
  22. // we just capture Init Message
  23. if (BFFM_INITIALIZED == uMsg)
  24. {
  25. // we expect lpData to be our start path
  26. SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, lpData);
  27. }
  28. return 0;
  29. }
  30. BOOL
  31. BrowseForDirectory(
  32. HWND hwndParent,
  33. LPCTSTR pszInitialDir,
  34. LPTSTR pszBuf,
  35. int cchBuf,
  36. LPCTSTR pszDialogTitle)
  37. {
  38. LPITEMIDLIST pItem = NULL;
  39. TCHAR szPath[MAX_PATH+1];
  40. BOOL bGotLocation = FALSE;
  41. BROWSEINFO bi;
  42. ZeroMemory(&bi, sizeof(bi));
  43. bi.hwndOwner = hwndParent;
  44. // initial folder
  45. if (pszInitialDir != NULL)
  46. {
  47. bi.lpfn = InitStartDir;
  48. bi.lParam = (LPARAM)pszInitialDir;
  49. }
  50. bi.pszDisplayName = szPath;
  51. bi.lpszTitle = pszDialogTitle;
  52. bi.ulFlags = BIF_RETURNONLYFSDIRS; // return only directories in the filesystem, not other folders
  53. pItem = SHBrowseForFolder(&bi);
  54. if (pItem == NULL)
  55. goto Ret;
  56. bGotLocation = SHGetPathFromIDList(pItem, szPath);
  57. if (!bGotLocation)
  58. goto Ret;
  59. ASSERT((_tcslen(szPath)+1)*sizeof(TCHAR) <= (UINT)cchBuf);
  60. if ((_tcslen(szPath)+1)*sizeof(TCHAR) > (UINT)cchBuf)
  61. return FALSE;
  62. _tcscpy(pszBuf, szPath);
  63. Ret:
  64. LPMALLOC pMalloc;
  65. if (SUCCEEDED(SHGetMalloc(&pMalloc)))
  66. {
  67. if (pItem)
  68. pMalloc->Free(pItem);
  69. if (bi.pidlRoot)
  70. pMalloc->Free((ITEMIDLIST*)bi.pidlRoot);
  71. pMalloc->Release();
  72. }
  73. return bGotLocation;
  74. }