TNB Library
TnbMfcFileDialogEx.h
[詳解]
1#pragma once
11#include "TnbDef.h"
12
13
14
15#ifndef _TnbDOXYGEN //Document作成用シンボル
16#if (_WIN32_WINNT >= 0x0500) && defined(CFileDialog) && defined(__MSVCPP6__)
17
18#undef CFileDialog
19
20// commdlg.h の OPENFILENAME と同じ
21struct TOpenFileName
22{
23 DWORD lStructSize;
24 HWND hwndOwner;
25 HINSTANCE hInstance;
26 LPCTSTR lpstrFilter;
27 LPTSTR lpstrCustomFilter;
28 DWORD nMaxCustFilter;
29 DWORD nFilterIndex;
30 LPTSTR lpstrFile;
31 DWORD nMaxFile;
32 LPTSTR lpstrFileTitle;
33 DWORD nMaxFileTitle;
34 LPCTSTR lpstrInitialDir;
35 LPCTSTR lpstrTitle;
36 DWORD Flags;
37 WORD nFileOffset;
38 WORD nFileExtension;
39 LPCTSTR lpstrDefExt;
40 LPARAM lCustData;
41 LPOFNHOOKPROC lpfnHook;
42 LPCTSTR lpTemplateName;
43};
44
45// AfxDlgs.h のそれと同じ
46class CFileDialog : public CCommonDialog
47{
48 DECLARE_DYNAMIC(CFileDialog)
49
50public:
51// Attributes
52 TOpenFileName m_ofn; // open file parameter block
53
54// Constructors
55 CFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
56 LPCTSTR lpszDefExt = NULL,
57 LPCTSTR lpszFileName = NULL,
58 DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
59 LPCTSTR lpszFilter = NULL,
60 CWnd* pParentWnd = NULL);
61
62// Operations
63 virtual int DoModal();
64
65 // Helpers for parsing file name after successful return
66 // or during Overridable callbacks if OFN_EXPLORER is set
67 CString GetPathName() const; // return full path and filename
68 CString GetFileName() const; // return only filename
69 CString GetFileExt() const; // return only ext
70 CString GetFileTitle() const; // return file title
71 BOOL GetReadOnlyPref() const; // return TRUE if readonly checked
72
73 // Enumerating multiple file selections
74 POSITION GetStartPosition() const;
75 CString GetNextPathName(POSITION& pos) const;
76
77 // Helpers for custom templates
78 void SetTemplate(UINT nWin3ID, UINT nWin4ID);
79 void SetTemplate(LPCTSTR lpWin3ID, LPCTSTR lpWin4ID);
80
81 // Other operations available while the dialog is visible
82 CString GetFolderPath() const; // return full path
83 void SetControlText(int nID, LPCSTR lpsz);
84 void HideControl(int nID);
85 void SetDefExt(LPCSTR lpsz);
86
87// Overridable callbacks
88protected:
89 friend UINT CALLBACK _AfxCommDlgProc(HWND, UINT, WPARAM, LPARAM);
90 virtual UINT OnShareViolation(LPCTSTR lpszPathName);
91 virtual BOOL OnFileNameOK();
92 virtual void OnLBSelChangedNotify(UINT nIDBox, UINT iCurSel, UINT nCode);
93
94 // only called back if OFN_EXPLORER is set
95 virtual void OnInitDone();
96 virtual void OnFileNameChange();
97 virtual void OnFolderChange();
98 virtual void OnTypeChange();
99
100// Implementation
101#ifdef _DEBUG
102public:
103 virtual void Dump(CDumpContext& dc) const;
104#endif
105
106protected:
107 BOOL m_bOpenFileDialog; // TRUE for file open, FALSE for file save
108 CString m_strFilter; // filter string
109 // separate fields with '|', terminate with '||\0'
110 TCHAR m_szFileTitle[64]; // contains file title after return
111 TCHAR m_szFileName[_MAX_PATH]; // contains full path name after return
112
113 OPENFILENAME* m_pofnTemp;
114
115 virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
116};
117#endif // _WIN32_WINNT >= 0x0500
118#endif //_TnbDOXYGEN
119
120
121
122//TNB Library
123namespace TNB {
124namespace MFC {
125
126
127
172class CFileDialogEx : public CFileDialog
173{
174 DEFSUPER(CFileDialog);
175 enum { E_BufferLength = 100000 };
176public:
177
240 CFileDialogEx(BOOL bOpenFileDialog,
241 LPCTSTR lpszDefExt = NULL,
242 LPCTSTR lpszFileName = NULL,
243 DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
244 LPCTSTR lpszFilter = NULL,
245 CWnd* pParentWnd = NULL,
246 BOOL bVistaStyle = FALSE
247#if _MSC_VER < 1400
248 ) : _super(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
249#else
250 ) : _super(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd, 0, bVistaStyle)
251#endif
252 {
253 m_strNameBuffer = lpszFileName;
254 m_ofn.nMaxFile = E_BufferLength;
255 m_ofn.lpstrFile = m_strNameBuffer.GetBuffer(E_BufferLength + 1);
256 }
257
263 void SetInitialPath(LPCTSTR lpszPath)
264 {
265 m_initialPath = lpszPath;
266 m_ofn.lpstrInitialDir = m_initialPath;
267 }
268
275 INT_PTR GetPathNames(CStringArray& _astrNames)
276 {
277 _astrNames.RemoveAll();
278 POSITION pos = GetStartPosition();
279 while ( pos != NULL )
280 {
281 _astrNames.Add(GetNextPathName(pos));
282 }
283 return _astrNames.GetSize();
284 }
285
291 CString GetPathName(void) const
292 {
293 return _super::GetPathName();
294 }
295
296protected:
297
306 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
307 {
308 if ( message == WM_INITDIALOG )
309 {
310 GetNextWindow(GW_HWNDPREV)->ShowWindow(SW_HIDE);
311 }
312 return _super::WindowProc(message, wParam, lParam);
313 }
314
315private:
316 CString m_strNameBuffer;
317 CString m_initialPath;
318};
319
320
321
322}; // MFC
323}; // TNB
TNBライブラリの定義ヘッダ
ウィンドウ管理.
ファイル選択コモンダイアログ
CString GetPathName(void) const
[取得] 選択フルパス名取得.
INT_PTR GetPathNames(CStringArray &_astrNames)
[取得] 選択フルパス名取得.
void SetInitialPath(LPCTSTR lpszPath)
[設定] 最初のディレクトリ指定.
CFileDialogEx(BOOL bOpenFileDialog, LPCTSTR lpszDefExt=NULL, LPCTSTR lpszFileName=NULL, DWORD dwFlags=OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter=NULL, CWnd *pParentWnd=NULL, BOOL bVistaStyle=FALSE)
コンストラクタ
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
TNB Library
Definition: TnbDoxyTitle.txt:2