FolderBrowseEx.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef NULLSOFT_FOLDERBROWSE_EXTENDED_DIALOG_HEADER
  2. #define NULLSOFT_FOLDERBROWSE_EXTENDED_DIALOG_HEADER
  3. #include <windows.h>
  4. #include <shlobj.h>
  5. /// Standart controls
  6. #define IDC_TV_FOLDERS 0x3741
  7. #define IDC_SB_GRIPPER 0x3747
  8. #define IDC_LBL_FOLDER 0x3748
  9. #define IDC_LBL_CAPTION 0x3742
  10. #define IDC_EDT_PATH 0x3744
  11. typedef struct _BFPATH
  12. {
  13. int empty;
  14. int type;
  15. void *value;
  16. }BFPATH;
  17. class FolderBrowseEx
  18. {
  19. public:
  20. FolderBrowseEx(LPCITEMIDLIST pidlRoot, UINT ulFlags, LPCWSTR lpszCaption, LPCWSTR lpszTitle);
  21. FolderBrowseEx(UINT ulFlags, LPCWSTR lpszCaption, LPCWSTR lpszTitle);
  22. FolderBrowseEx(UINT ulFlags, LPCWSTR lpszTitle);
  23. FolderBrowseEx(void);
  24. virtual ~FolderBrowseEx(void);
  25. public:
  26. virtual LPITEMIDLIST Browse(HWND hwndOwner);
  27. LPITEMIDLIST GetPIDL(void) { return pidl; }
  28. INT GetImage(void) { return image; }
  29. LPCWSTR GetDislpayName(void) { return pszDisplayName; }
  30. HRESULT ParseDisplayName(LPCWSTR lpszPath, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut);
  31. HWND GetDlgItem(int nIDDlgItem) { return ::GetDlgItem(hwnd, nIDDlgItem); }
  32. void SetRoot(LPCITEMIDLIST pidlRoot) { this->pidlRoot = pidlRoot; }
  33. void SetFlags(UINT ulFlags) { this->ulFlags = ulFlags; }
  34. void SetSelection(LPCITEMIDLIST pidlSelect);
  35. void SetSelection(LPCWSTR lpszSelect);
  36. void SetExpanded(LPCITEMIDLIST pidlExpand);
  37. void SetExpanded(LPCWSTR lpszExpand);
  38. void SetCaption(LPCWSTR lpszCaption);
  39. void SetTitle(LPCWSTR lpszTitle);
  40. protected:
  41. HWND GetHandle(void) { return hwnd; }
  42. INT_PTR CallWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
  43. void SetDialogResult(LRESULT result);
  44. LRESULT SendMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { return ::SendMessageW(hwnd, uMsg, wParam, lParam); }
  45. void SetWindowText(LPCWSTR lpText) { ::SetWindowTextW(hwnd, lpText); }
  46. void EnableOK(BOOL enable) { SendMessage(BFFM_ENABLEOK, 0, (LPARAM)enable); }
  47. void SetOKText(LPCWSTR lpText) { SendMessage(BFFM_SETOKTEXT, 0, (LPARAM)lpText); }
  48. void SetStatusText(LPCWSTR lpText) { SendMessage(BFFM_SETSTATUSTEXTW, 0, (LPARAM)lpText); }
  49. virtual void OnInitialized(void);
  50. virtual void OnIUnknown(IUnknown *lpiu) {}
  51. virtual void OnSelectionChanged(LPCITEMIDLIST pidl);
  52. virtual BOOL OnValidateFailed(LPCWSTR lpName) { return FALSE; }
  53. virtual void OnSelectionDone(LPCITEMIDLIST pidl) { }
  54. virtual INT BrowseCallback(UINT uMsg, LPARAM lParam);
  55. virtual INT_PTR DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
  56. protected:
  57. LPCITEMIDLIST pidlRoot;
  58. BFPATH pathSelection;
  59. BFPATH pathExpanded;
  60. LPWSTR lpszCaption;
  61. LPWSTR lpszTitle;
  62. UINT ulFlags;
  63. INT image;
  64. WCHAR pszDisplayName[MAX_PATH];
  65. BOOL expand;
  66. LPITEMIDLIST pidl;
  67. private:
  68. HWND hwnd;
  69. LONG_PTR oldProc;
  70. friend static int WINAPI BrowseCallback_Helper(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);
  71. friend static LRESULT WINAPI WindowProc_Helper(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  72. friend static void Initialize(FolderBrowseEx *lpfbx, LPCITEMIDLIST pidlRoot, UINT ulFlags, LPCWSTR lpszCaption, LPCWSTR lpszTitle);
  73. };
  74. #endif //NULLSOFT_FOLDERBROWSE_EXTENDED_DIALOG_HEADER