TNB Library
TnbMfcModelessDialog.h
[詳解]
1#pragma once
11#include "TnbMfcCommon.h"
12
13
14
15//TNB Library
16namespace TNB {
17namespace MFC {
18
19
20
77template<typename DLG, bool HASTASK = true>
79{
80public:
81
84 {
85 }
86
89 {
90 Destroy();
91 }
92
100 void SetParentMenu(HWND hWnd, UINT menuItem, UINT msg = 0)
101 {
102 m_dlg.SetParentMenu(hWnd, menuItem, msg);
103 }
104
110 bool IsViewing(void) const
111 {
112 return IsVisible();
113 }
114
120 bool IsVisible(void) const
121 {
122 return ::IsWindow(m_dlg.m_hWnd) && ::IsWindowVisible(m_dlg.m_hWnd);
123 }
124
130 void Show(void)
131 {
132 m_CreateDlg();
133 m_dlg.ShowWindow(SW_SHOW);
134 }
135
142 void Hide(void)
143 {
144 m_CreateDlg();
145 if ( IsViewing() )
146 {
147 m_dlg.ShowWindow(SW_HIDE);
148 }
149 }
150
155 void Toggle(void)
156 {
157 if ( IsViewing() )
158 {
159 Hide();
160 }
161 else
162 {
163 Show();
164 }
165 }
166
171 void Destroy(void)
172 {
173 if ( ::IsWindow(m_dlg.m_hWnd) )
174 {
175 m_dlg.DestroyWindow();
176 }
177 }
178
183 const DLG* operator->(void) const
184 {
185 return &m_dlg;
186 }
187
192 DLG* operator->(void)
193 {
194 return &m_dlg;
195 }
196
201 operator HWND(void)
202 {
203 return m_dlg;
204 }
205
211 void DisableWmClose(void)
212 {
213 m_dlg.DisableWmClose();
214 }
215
216private:
217 void m_CreateDlg(void)
218 {
219 if ( ! ::IsWindow(m_dlg.m_hWnd) )
220 {
221 m_dlg.CreateDlg(DLG::IDD, HASTASK ? CWnd::GetDesktopWindow() : NULL);
222 }
223 }
225 class CInner : public DLG
226 {
227 DEFSUPER(DLG);
228 public:
230 CInner(void) : m_hParentWnd(NULL)
231 , m_parentMenuItem(0), m_parentMsg(0), m_isPosChanging(false), m_isCreating(false), m_isEnableWmClose(true)
232 {
233 }
234 void CreateDlg(DWORD dw, CWnd* pParent)
235 {
236 if ( ! ::IsWindow(_super::m_hWnd) )
237 {
238 m_isCreating = true;
239 _super::Create(dw, pParent);
240// DWORD mov = WS_CHILD | WS_BORDER | WS_DLGFRAME | WS_VISIBLE;
241// DWORD add = WS_POPUP | WS_CAPTION;
242 DWORD mov = WS_CHILD | WS_VISIBLE;
243 DWORD add = WS_POPUP;
244 _super::ModifyStyle(mov, add, SWP_FRAMECHANGED);
245 m_isCreating = false;
246 }
247 }
254 void SetParentMenu(HWND hWnd, UINT menuItem, UINT msg)
255 {
256 m_hParentWnd = hWnd;
257 m_parentMenuItem = menuItem;
258 m_parentMsg = msg;
259 }
261 void DisableWmClose(void)
262 {
263 m_isEnableWmClose = false;
264 }
265 protected:
275 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
276 {
277 switch ( message )
278 {
279#ifndef _WIN32_WCE
280 case WM_WINDOWPOSCHANGING:
281 if ( ! m_isCreating )
282 {
283 m_isPosChanging = true;
284 }
285 break;
286 case WM_WINDOWPOSCHANGED:
287 if ( m_isPosChanging )
288 {
289 m_isPosChanging = false;
290 WINDOWPOS* P = reinterpret_cast<WINDOWPOS*>(lParam);
291 if ( (P->flags & SWP_HIDEWINDOW) != 0 )
292 {
293 m_NotifyParent(0);
294 }
295 }
296 break;
297 case WM_SHOWWINDOW:
298 if ( ! m_isCreating )
299 {
300 m_isPosChanging = false;
301 m_NotifyParent(wParam);
302 }
303 break;
304#endif // _WIN32_WCE
305 case WM_CLOSE:
306 if ( m_isEnableWmClose )
307 {
308 ShowWindow(SW_HIDE);
309 }
310// return true;
311 break;
312 }
313 return _super::WindowProc(message, wParam, lParam);
314 }
315 private:
316 HWND m_hParentWnd;
317 UINT m_parentMenuItem;
318 UINT m_parentMsg;
319 bool m_isPosChanging;
320 bool m_isCreating;
321 bool m_isEnableWmClose;
322#ifndef _WIN32_WCE
323 void m_NotifyParent(WPARAM wParam)
324 {
325 if ( m_parentMenuItem != 0 )
326 {
327 HMENU h = ::GetMenu(m_hParentWnd);
328 if ( h != NULL )
329 {
330 UINT r = (wParam != 0) ? MF_CHECKED : MF_UNCHECKED;
331 ::CheckMenuItem(h, m_parentMenuItem, r);
332 }
333 }
334 if ( m_parentMsg != 0 && wParam == 0 )
335 {
336 ::PostMessage(m_hParentWnd, m_parentMsg, 0, 0);
337 }
338 }
339#endif // _WIN32_WCE
340 };
341 CInner m_dlg;
342};
343
344
345
346}; // MFC
347}; // TNB
MFCコントロール共通のヘッダ
ウィンドウ管理.
モードレスウィンドウ管理テンプレート.
bool IsVisible(void) const
[取得] 表示状態
void DisableWmClose(void)
[設定] WM_CLOSE 処理禁止.
void Show(void)
[設定] 表示.
void Destroy(void)
[設定] 破棄.
void SetParentMenu(HWND hWnd, UINT menuItem, UINT msg=0)
[設定] 親メニュー設定.
DLG * operator->(void)
[取得] ダイアログクラス参照
bool IsViewing(void) const
[取得] 表示状態
CModelessDialogT(void)
コンストラクタ
~CModelessDialogT(void)
デストラクタ
const DLG * operator->(void) const
[取得] ダイアログクラス参照
void Toggle(void)
[設定] 表示/非表示.
void Hide(void)
[設定] 非表示.
TNB Library
Definition: TnbDoxyTitle.txt:2