-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFolderDlg.h
209 lines (162 loc) · 6.67 KB
/
FolderDlg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/////////////////////////////////////////////////////////////////////////////
/*
DESCRIPTION:
CFolderDialog - Folder Selection Dialog Class
http://www.codeproject.com/dialog/cfolderdialog.asp
NOTES:
Copyright(C) Armen Hakobyan, 2002
mailto:[email protected]
VERSION HISTORY:
24 Mar 2002 - First release
30 Mar 2003 - Some minor changes
- Added missing in old Platform SDK new flag definitions
- Added support for both MFC 6.0 and 7.0
- Added OnIUnknown handler for Windows XP folder filtration
- Added SetExpanded and SetOKText and GetSelectedFolder functions
24 May 2003 - Added OnSelChanged implementation
14 Jul 2003 - Added custom filtration for Windows XP, thanks to Arik Poznanski
29 Nov 2003 - Added SetRootFolder, thanks to Eckhard Schwabe ( and Jose Insa )
02 Jan 2004 - Added GetRootFolder, uncomment if needed
*/
/////////////////////////////////////////////////////////////////////////////
#ifndef __FOLDERDLG_H__
#define __FOLDERDLG_H__
#if defined( _MSC_VER ) && ( _MSC_VER >= 1020 )
#pragma once
#endif
/////////////////////////////////////////////////////////////////////////////
#ifndef __AFXDLGS_H__
#include < AfxDlgs.h >
#endif
#ifndef __ATLCONV_H__
#include < AtlConv.h > // MBCS/Unicode Conversion Macros
#endif
// Uncomment if using GetRootFolder
//#ifndef _INC_SHLWAPI
// #include < shlwapi.h >
//#endif
//#pragma comment( lib, "shlwapi.lib" )
/////////////////////////////////////////////////////////////////////////////
#ifndef BFFM_SETOKTEXT // Version 5.0 or later
#define BFFM_SETOKTEXT ( WM_USER + 105 ) // Unicode only, req. BIF_USENEWUI
#define BFFM_SETEXPANDED ( WM_USER + 106 ) // Unicode only, req. BIF_USENEWUI
#endif
#ifndef BIF_NEWDIALOGSTYLE // Version 5.0 or later
#define BIF_NEWDIALOGSTYLE 0x0040
#define BIF_BROWSEINCLUDEURLS 0x0080
#define BIF_UAHINT 0x0100 // Req. BIF_NEWDIALOGSTYLE
#define BIF_NONEWFOLDERBUTTON 0x0200
#define BIF_NOTRANSLATETARGETS 0x0400
#define BIF_SHAREABLE 0x8000 // Req. BIF_USENEWUI
#define BIF_USENEWUI ( BIF_NEWDIALOGSTYLE | BIF_EDITBOX )
#endif
/////////////////////////////////////////////////////////////////////////////
#ifndef _delete2
#define _delete2( p ) { if( p ){ delete[] p; p = NULL; } }
#endif
#ifndef _releaseInterface
#define _releaseInterface( p ) { if( p ){ p->Release(); p = NULL; } }
#endif
#ifndef _coTaskMemFree
#define _coTaskMemFree( p ) { if( p ){ ::CoTaskMemFree( (LPVOID)p ); p = NULL; } }
#endif
#ifndef _NOINLINE
#if ( _MSC_VER < 1700 )
#define _NOINLINE
#else
#define _NOINLINE __declspec( noinline )
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
class CFolderDialog : public CCommonDialog
{
DECLARE_DYNAMIC( CFolderDialog )
public:
CFolderDialog( IN LPCTSTR pszTitle = NULL,
IN LPCTSTR pszSelPath = NULL,
IN CWnd* pWndParent = NULL,
IN UINT uFlags = BIF_RETURNONLYFSDIRS );
virtual ~CFolderDialog( void );
public:
#if ( _MFC_VER >= 0x0700 )
virtual INT_PTR DoModal( void );
#else
virtual INT DoModal( void );
#endif
BOOL SetRootFolder( IN LPCTSTR pszPath );
BOOL GetRootFolder( IN OUT LPTSTR pszPath );
public:
AFX_INLINE BOOL SetSelectedFolder( IN LPCTSTR pszPath );
AFX_INLINE LPCTSTR GetFolderPath( void ) const;
AFX_INLINE LPCTSTR GetFolderName( void ) const;
AFX_INLINE INT GetFolderImage( void ) const;
AFX_INLINE LPCTSTR GetSelectedFolder( void ) const;
AFX_INLINE BROWSEINFO& GetBI( void );
AFX_INLINE const BROWSEINFO& GetBI( void ) const;
protected:
BROWSEINFO m_bi;
TCHAR m_szSelPath[ MAX_PATH ];
TCHAR m_szFolPath[ MAX_PATH ];
protected:
DECLARE_MESSAGE_MAP()
virtual void OnInitialized( void );
virtual void OnSelChanged( IN LPITEMIDLIST pItemIDList );
virtual INT OnValidateFailed( IN LPCTSTR /*pszPath*/ );
protected: // Windows XP or later
virtual void OnIUnknown( IN IUnknown* /*pIUnknown*/ );
protected: // Shell version 5.0 or later:
_NOINLINE void SetExpanded( IN LPCTSTR pszPath );
_NOINLINE void SetOKText( IN LPCTSTR pszText );
protected: // Valid to call only from the above handlers
AFX_INLINE void EnableOK( IN BOOL bEnable = TRUE );
AFX_INLINE void SetSelection( IN LPITEMIDLIST pItemIDList );
AFX_INLINE void SetSelection( IN LPCTSTR pszPath );
AFX_INLINE void SetStatusText( IN LPCTSTR pszText );
protected: // Shell version 5.0 or later:
AFX_INLINE void SetExpanded( IN LPITEMIDLIST pItemIDList );
private:
HWND m_hWnd; // used only in the callback function
static INT CALLBACK BrowseCallbackProc(
IN HWND hWnd, IN UINT uMsg, IN LPARAM lParam, IN LPARAM lpData
);
};
/////////////////////////////////////////////////////////////////////////////
AFX_INLINE BOOL CFolderDialog::SetSelectedFolder( IN LPCTSTR pszPath )
{ ASSERT( AfxIsValidString( pszPath, MAX_PATH ) );
return( ::lstrcpy( m_szSelPath, pszPath ) != NULL ); }
AFX_INLINE LPCTSTR CFolderDialog::GetSelectedFolder( void ) const
{ return m_szSelPath; }
AFX_INLINE BROWSEINFO& CFolderDialog::GetBI( void )
{ return m_bi; }
AFX_INLINE const BROWSEINFO& CFolderDialog::GetBI( void ) const
{ return m_bi; }
/////////////////////////////////////////////////////////////////////////////
// Filled after a call to DoModal
AFX_INLINE LPCTSTR CFolderDialog::GetFolderPath( void ) const
{ return m_szFolPath; }
AFX_INLINE LPCTSTR CFolderDialog::GetFolderName( void ) const
{ return m_bi.pszDisplayName; }
AFX_INLINE INT CFolderDialog::GetFolderImage( void ) const
{ return m_bi.iImage; }
/////////////////////////////////////////////////////////////////////////////
// Commands, valid to call only from handlers
AFX_INLINE void CFolderDialog::EnableOK( IN BOOL bEnable /*TRUE*/ )
{ ASSERT( m_hWnd != NULL );
::SendMessage( m_hWnd, BFFM_ENABLEOK, (WPARAM)bEnable, 0L );}
AFX_INLINE void CFolderDialog::SetSelection( IN LPITEMIDLIST pItemIDList )
{ ASSERT( m_hWnd != NULL );
::SendMessage( m_hWnd, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pItemIDList ); }
AFX_INLINE void CFolderDialog::SetSelection( IN LPCTSTR pszPath )
{ ASSERT( m_hWnd != NULL );
ASSERT( AfxIsValidString( pszPath, MAX_PATH ) );
::SendMessage( m_hWnd, BFFM_SETSELECTION, (WPARAM)TRUE, (LPARAM)pszPath ); }
AFX_INLINE void CFolderDialog::SetStatusText( IN LPCTSTR pszText )
{ ASSERT( m_hWnd != NULL );
::SendMessage( m_hWnd, BFFM_SETSTATUSTEXT, (WPARAM)0, (LPARAM)pszText ); }
// Shell version 5.0 or later:
AFX_INLINE void CFolderDialog::SetExpanded( IN LPITEMIDLIST pItemIDList )
{ ASSERT( m_hWnd != NULL );
::SendMessage( m_hWnd, BFFM_SETEXPANDED, (WPARAM)FALSE, (LPARAM)pItemIDList ); }
/////////////////////////////////////////////////////////////////////////////
#endif // __FOLDERDLG_H__
/////////////////////////////////////////////////////////////////////////////