added some development tools
[windows-sources.git] / developer / VC / WTL80 / AppWiz / Files / Templates / 1033 / MainDlg.cpp
blob5e162793b3d87799106fc7be9aa2fb4bcf19523e
1 // [!output WTL_MAINDLG_FILE].cpp : implementation of the [!output WTL_MAINDLG_CLASS] class
2 //
3 /////////////////////////////////////////////////////////////////////////////
5 #include "stdafx.h"
6 #include "resource.h"
8 [!if WTL_APPTYPE_DLG && !WTL_APPTYPE_DLG_MODAL]
9 #include "aboutdlg.h"
10 [!endif]
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)
16 [!if WTL_HOST_AX]
17 if((pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST) &&
18 (pMsg->message < WM_MOUSEFIRST || pMsg->message > WM_MOUSELAST))
19 return FALSE;
21 HWND hWndCtl = ::GetFocus();
22 if(IsChild(hWndCtl))
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)
30 return TRUE;
33 [!endif]
34 return CWindow::IsDialogMessage(pMsg);
37 BOOL [!output WTL_MAINDLG_CLASS]::OnIdle()
39 return FALSE;
42 LRESULT [!output WTL_MAINDLG_CLASS]::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
44 // center the dialog on the screen
45 CenterWindow();
47 // set icons
48 HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
49 IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
50 SetIcon(hIcon, TRUE);
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);
63 return TRUE;
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);
73 [!if WTL_COM_SERVER]
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;
81 _Module.Unlock();
82 [!endif]
84 return 0;
87 LRESULT [!output WTL_MAINDLG_CLASS]::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
89 CAboutDlg dlg;
90 dlg.DoModal();
91 return 0;
94 LRESULT [!output WTL_MAINDLG_CLASS]::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
96 // TODO: Add validation code
97 CloseDialog(wID);
98 return 0;
101 LRESULT [!output WTL_MAINDLG_CLASS]::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
103 CloseDialog(wID);
104 return 0;
107 void [!output WTL_MAINDLG_CLASS]::CloseDialog(int nVal)
109 DestroyWindow();
110 ::PostQuitMessage(nVal);
112 [!endif]
113 [!if WTL_APPTYPE_DLG && WTL_APPTYPE_DLG_MODAL]
114 LRESULT [!output WTL_MAINDLG_CLASS]::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
116 [!if WTL_COM_SERVER]
117 _Module.Lock();
119 [!endif]
120 // center the dialog on the screen
121 CenterWindow();
123 // set icons
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);
131 return TRUE;
134 [!if WTL_COM_SERVER]
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;
143 _Module.Unlock();
144 return 0;
147 [!endif]
148 LRESULT [!output WTL_MAINDLG_CLASS]::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
150 CSimpleDialog<IDD_ABOUTBOX, FALSE> dlg;
151 dlg.DoModal();
152 return 0;
155 LRESULT [!output WTL_MAINDLG_CLASS]::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
157 // TODO: Add validation code
158 EndDialog(wID);
159 return 0;
162 LRESULT [!output WTL_MAINDLG_CLASS]::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
164 EndDialog(wID);
165 return 0;
167 [!endif]