1 // [!output WTL_MAINDLG_FILE].cpp : implementation of the [!output WTL_MAINDLG_CLASS] class
3 /////////////////////////////////////////////////////////////////////////////
8 [!if WTL_APPTYPE_DLG
&& !WTL_APPTYPE_DLG_MODAL
]
11 #include "[!output WTL_MAINDLG_FILE].h"
13 [!if WTL_APPTYPE_DLG
&& !WTL_APPTYPE_DLG_MODAL
]
14 BOOL
[!output WTL_MAINDLG_CLASS
]::PreTranslateMessage(MSG
* pMsg
)
17 if((pMsg
->message
< WM_KEYFIRST
|| pMsg
->message
> WM_KEYLAST
) &&
18 (pMsg
->message
< WM_MOUSEFIRST
|| pMsg
->message
> WM_MOUSELAST
))
21 HWND hWndCtl
= ::GetFocus();
24 // find a direct child of the dialog from the window that has focus
25 while(::GetParent(hWndCtl
) != m_hWnd
)
26 hWndCtl
= ::GetParent(hWndCtl
);
28 // give control a chance to translate this message
29 if(::SendMessage(hWndCtl
, WM_FORWARDMSG
, 0, (LPARAM
)pMsg
) != 0)
34 return CWindow::IsDialogMessage(pMsg
);
37 BOOL
[!output WTL_MAINDLG_CLASS
]::OnIdle()
42 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnInitDialog(UINT
/*uMsg*/, WPARAM
/*wParam*/, LPARAM
/*lParam*/, BOOL
& /*bHandled*/)
44 // center the dialog on the screen
48 HICON hIcon
= (HICON
)::LoadImage(_Module
.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME
),
49 IMAGE_ICON
, ::GetSystemMetrics(SM_CXICON
), ::GetSystemMetrics(SM_CYICON
), LR_DEFAULTCOLOR
);
51 HICON hIconSmall
= (HICON
)::LoadImage(_Module
.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME
),
52 IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), LR_DEFAULTCOLOR
);
53 SetIcon(hIconSmall
, FALSE
);
55 // register object for message filtering and idle updates
56 CMessageLoop
* pLoop
= _Module
.GetMessageLoop();
57 ATLASSERT(pLoop
!= NULL
);
58 pLoop
->AddMessageFilter(this);
59 pLoop
->AddIdleHandler(this);
61 UIAddChildWindowContainer(m_hWnd
);
66 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnDestroy(UINT
/*uMsg*/, WPARAM
/*wParam*/, LPARAM
/*lParam*/, BOOL
& /*bHandled*/)
68 // unregister message filtering and idle updates
69 CMessageLoop
* pLoop
= _Module
.GetMessageLoop();
70 ATLASSERT(pLoop
!= NULL
);
71 pLoop
->RemoveMessageFilter(this);
72 pLoop
->RemoveIdleHandler(this);
75 // if UI is the last thread, no need to wait
76 if(_Module
.GetLockCount() == 1)
78 _Module
.m_dwTimeOut
= 0L;
79 _Module
.m_dwPause
= 0L;
87 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnAppAbout(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
94 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnOK(WORD
/*wNotifyCode*/, WORD wID
, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
96 // TODO: Add validation code
101 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnCancel(WORD
/*wNotifyCode*/, WORD wID
, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
107 void [!output WTL_MAINDLG_CLASS
]::CloseDialog(int nVal
)
110 ::PostQuitMessage(nVal
);
113 [!if WTL_APPTYPE_DLG
&& WTL_APPTYPE_DLG_MODAL
]
114 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnInitDialog(UINT
/*uMsg*/, WPARAM
/*wParam*/, LPARAM
/*lParam*/, BOOL
& /*bHandled*/)
120 // center the dialog on the screen
124 HICON hIcon
= (HICON
)::LoadImage(_Module
.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME
),
125 IMAGE_ICON
, ::GetSystemMetrics(SM_CXICON
), ::GetSystemMetrics(SM_CYICON
), LR_DEFAULTCOLOR
);
126 SetIcon(hIcon
, TRUE
);
127 HICON hIconSmall
= (HICON
)::LoadImage(_Module
.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME
),
128 IMAGE_ICON
, ::GetSystemMetrics(SM_CXSMICON
), ::GetSystemMetrics(SM_CYSMICON
), LR_DEFAULTCOLOR
);
129 SetIcon(hIconSmall
, FALSE
);
135 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnDestroy(UINT
/*uMsg*/, WPARAM
/*wParam*/, LPARAM
/*lParam*/, BOOL
& /*bHandled*/)
137 // if UI is the last thread, no need to wait
138 if(_Module
.GetLockCount() == 1)
140 _Module
.m_dwTimeOut
= 0L;
141 _Module
.m_dwPause
= 0L;
148 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnAppAbout(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
150 CSimpleDialog
<IDD_ABOUTBOX
, FALSE
> dlg
;
155 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnOK(WORD
/*wNotifyCode*/, WORD wID
, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
157 // TODO: Add validation code
162 LRESULT
[!output WTL_MAINDLG_CLASS
]::OnCancel(WORD
/*wNotifyCode*/, WORD wID
, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)