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.

103 lines
2.2 KiB

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