added some development tools
[windows-sources.git] / developer / VC / WTL80 / AppWiz / Files / Templates / 1033 / Frame.cpp
bloba2efa645ce7fc1c828993fe51026401d456c9e51
1 // [!output WTL_FRAME_FILE].cpp : implmentation of the [!output WTL_FRAME_CLASS] class
2 //
3 /////////////////////////////////////////////////////////////////////////////
5 #include "stdafx.h"
6 #include "resource.h"
8 #include "aboutdlg.h"
9 [!if WTL_USE_VIEW]
10 #include "[!output WTL_VIEW_FILE].h"
11 [!endif]
12 [!if WTL_APPTYPE_MDI]
13 #include "[!output WTL_CHILD_FRAME_FILE].h"
14 [!endif]
15 #include "[!output WTL_FRAME_FILE].h"
17 BOOL [!output WTL_FRAME_CLASS]::PreTranslateMessage(MSG* pMsg)
19 [!if WTL_APPTYPE_MDI]
20 if([!output WTL_FRAME_BASE_CLASS]<[!output WTL_FRAME_CLASS]>::PreTranslateMessage(pMsg))
21 return TRUE;
23 HWND hWnd = MDIGetActive();
24 if(hWnd != NULL)
25 return (BOOL)::SendMessage(hWnd, WM_FORWARDMSG, 0, (LPARAM)pMsg);
27 return FALSE;
28 [!else]
29 [!if WTL_USE_VIEW]
30 if([!output WTL_FRAME_BASE_CLASS]<[!output WTL_FRAME_CLASS]>::PreTranslateMessage(pMsg))
31 return TRUE;
33 return m_view.PreTranslateMessage(pMsg);
34 [!else]
35 return [!output WTL_FRAME_BASE_CLASS]<[!output WTL_FRAME_CLASS]>::PreTranslateMessage(pMsg);
36 [!endif]
37 [!endif]
40 BOOL [!output WTL_FRAME_CLASS]::OnIdle()
42 [!if WTL_USE_TOOLBAR]
43 UIUpdateToolBar();
44 [!endif]
45 return FALSE;
48 LRESULT [!output WTL_FRAME_CLASS]::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
50 [!if WTL_USE_TOOLBAR]
51 [!if WTL_USE_REBAR]
52 [!if WTL_USE_CMDBAR]
53 // create command bar window
54 HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
55 // attach menu
56 m_CmdBar.AttachMenu(GetMenu());
57 // load command bar images
58 m_CmdBar.LoadImages(IDR_MAINFRAME);
59 // remove old menu
60 SetMenu(NULL);
62 [!endif]
63 HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
65 CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
66 [!if WTL_USE_CMDBAR]
67 AddSimpleReBarBand(hWndCmdBar);
68 AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
69 [!else]
70 AddSimpleReBarBand(hWndToolBar);
71 [!endif]
72 [!else]
73 CreateSimpleToolBar();
74 [!endif]
75 [!endif]
76 [!if WTL_USE_STATUSBAR]
78 CreateSimpleStatusBar();
79 [!endif]
80 [!if WTL_APPTYPE_MDI]
82 CreateMDIClient();
83 [!if WTL_USE_CMDBAR]
84 m_CmdBar.SetMDIClient(m_hWndMDIClient);
85 [!endif]
86 [!endif]
87 [!if WTL_APPTYPE_SDI || WTL_APPTYPE_MTSDI]
88 [!if WTL_USE_VIEW]
89 [!if WTL_VIEWTYPE_FORM]
91 m_hWndClient = m_view.Create(m_hWnd);
92 [!else]
93 [!if WTL_VIEWTYPE_HTML]
95 //TODO: Replace with a URL of your choice
96 m_hWndClient = m_view.Create(m_hWnd, rcDefault, _T("http://www.microsoft.com"), [!output WTL_VIEW_STYLES], [!output WTL_VIEW_EX_STYLES]);
97 [!else]
99 m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, [!output WTL_VIEW_STYLES], [!output WTL_VIEW_EX_STYLES]);
100 [!endif]
101 [!if WTL_VIEWTYPE_LISTBOX || WTL_VIEWTYPE_EDIT || WTL_VIEWTYPE_LISTVIEW || WTL_VIEWTYPE_TREEVIEW || WTL_VIEWTYPE_RICHEDIT]
102 m_view.SetFont(AtlGetDefaultGuiFont());
103 [!endif]
104 [!if WTL_VIEWTYPE_SCROLL]
105 // replace with appropriate values for the app
106 m_view.SetScrollSize(2000, 1000);
107 [!endif]
108 [!endif]
109 [!endif]
110 [!endif]
111 [!if WTL_APPTYPE_TABVIEW]
113 m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
114 [!endif]
115 [!if WTL_APPTYPE_EXPLORER]
117 m_hWndClient = m_splitter.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
119 m_pane.SetPaneContainerExtendedStyle(PANECNT_NOBORDER);
120 m_pane.Create(m_splitter, _T("Tree"), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
121 m_treeview.Create(m_pane, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS, WS_EX_CLIENTEDGE);
122 m_treeview.SetFont(AtlGetDefaultGuiFont());
123 m_pane.SetClient(m_treeview);
124 [!if WTL_VIEWTYPE_FORM]
126 m_view.Create(m_splitter);
127 [!else]
128 [!if WTL_VIEWTYPE_HTML]
130 //TODO: Replace with a URL of your choice
131 m_view.Create(m_splitter, rcDefault, _T("http://www.microsoft.com"), [!output WTL_VIEW_STYLES], [!output WTL_VIEW_EX_STYLES]);
132 [!else]
134 m_view.Create(m_splitter, rcDefault, NULL, [!output WTL_VIEW_STYLES], [!output WTL_VIEW_EX_STYLES]);
135 [!endif]
136 [!if WTL_VIEWTYPE_LISTBOX || WTL_VIEWTYPE_EDIT || WTL_VIEWTYPE_LISTVIEW || WTL_VIEWTYPE_TREEVIEW || WTL_VIEWTYPE_RICHEDIT]
137 m_view.SetFont(AtlGetDefaultGuiFont());
138 [!endif]
139 [!if WTL_VIEWTYPE_SCROLL]
140 // replace with appropriate values for the app
141 m_view.SetScrollSize(2000, 1000);
142 [!endif]
143 [!endif]
145 m_splitter.SetSplitterPanes(m_pane, m_view);
146 UpdateLayout();
147 m_splitter.SetSplitterPosPct(25);
148 [!endif]
149 [!if WTL_USE_TOOLBAR]
150 [!if WTL_USE_REBAR]
152 UIAddToolBar(hWndToolBar);
153 [!else]
155 UIAddToolBar(m_hWndToolBar);
156 [!endif]
157 UISetCheck(ID_VIEW_TOOLBAR, 1);
158 [!endif]
159 [!if WTL_USE_STATUSBAR]
160 UISetCheck(ID_VIEW_STATUS_BAR, 1);
161 [!endif]
162 [!if WTL_APPTYPE_EXPLORER]
163 UISetCheck(ID_VIEW_TREEPANE, 1);
164 [!endif]
166 // register object for message filtering and idle updates
167 CMessageLoop* pLoop = _Module.GetMessageLoop();
168 ATLASSERT(pLoop != NULL);
169 pLoop->AddMessageFilter(this);
170 pLoop->AddIdleHandler(this);
172 [!if WTL_APPTYPE_TABVIEW]
173 [!if WTL_USE_CMDBAR]
174 CMenuHandle menuMain = m_CmdBar.GetMenu();
175 [!else]
176 CMenuHandle menuMain = GetMenu();
177 [!endif]
178 m_view.SetWindowMenu(menuMain.GetSubMenu(WINDOW_MENU_POSITION));
180 [!endif]
181 return 0;
184 [!if WTL_COM_SERVER]
185 LRESULT [!output WTL_FRAME_CLASS]::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
187 [!if WTL_APPTYPE_MDI]
188 [!if WTL_USE_CMDBAR]
189 m_CmdBar.AttachMenu(NULL);
191 [!endif]
192 [!endif]
193 // unregister message filtering and idle updates
194 CMessageLoop* pLoop = _Module.GetMessageLoop();
195 ATLASSERT(pLoop != NULL);
196 pLoop->RemoveMessageFilter(this);
197 pLoop->RemoveIdleHandler(this);
199 // if UI is the last thread, no need to wait
200 if(_Module.GetLockCount() == 1)
202 _Module.m_dwTimeOut = 0L;
203 _Module.m_dwPause = 0L;
205 _Module.Unlock();
207 [!if WTL_APPTYPE_MTSDI]
208 ::PostQuitMessage(1);
210 [!endif]
211 return 0;
214 [!else]
215 LRESULT [!output WTL_FRAME_CLASS]::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
217 [!if WTL_APPTYPE_MDI]
218 [!if WTL_USE_CMDBAR]
219 m_CmdBar.AttachMenu(NULL);
221 [!endif]
222 [!endif]
223 // unregister message filtering and idle updates
224 CMessageLoop* pLoop = _Module.GetMessageLoop();
225 ATLASSERT(pLoop != NULL);
226 pLoop->RemoveMessageFilter(this);
227 pLoop->RemoveIdleHandler(this);
229 bHandled = FALSE;
230 return 1;
233 [!endif]
234 LRESULT [!output WTL_FRAME_CLASS]::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
236 PostMessage(WM_CLOSE);
237 return 0;
240 LRESULT [!output WTL_FRAME_CLASS]::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
242 [!if WTL_APPTYPE_TABVIEW]
243 [!output WTL_VIEW_CLASS]* pView = new [!output WTL_VIEW_CLASS];
244 [!if WTL_VIEWTYPE_FORM]
245 pView->Create(m_view);
246 [!else]
247 [!if WTL_VIEWTYPE_HTML]
248 //TODO: Replace with a URL of your choice
249 pView->Create(m_view, rcDefault, _T("http://www.microsoft.com"), [!output WTL_VIEW_STYLES], [!output WTL_VIEW_EX_STYLES]);
250 [!else]
251 pView->Create(m_view, rcDefault, NULL, [!output WTL_VIEW_STYLES], [!output WTL_VIEW_EX_STYLES]);
252 [!endif]
253 [!if WTL_VIEWTYPE_LISTBOX || WTL_VIEWTYPE_EDIT || WTL_VIEWTYPE_LISTVIEW || WTL_VIEWTYPE_TREEVIEW || WTL_VIEWTYPE_RICHEDIT]
254 pView->SetFont(AtlGetDefaultGuiFont());
255 [!endif]
256 [!if WTL_VIEWTYPE_SCROLL]
257 // replace with appropriate values for the app
258 pView->SetScrollSize(2000, 1000);
259 [!endif]
260 [!endif]
261 m_view.AddPage(pView->m_hWnd, _T("Document"));
263 [!endif]
264 [!if WTL_APPTYPE_MDI]
265 [!output WTL_CHILD_FRAME_CLASS]* pChild = new [!output WTL_CHILD_FRAME_CLASS];
266 pChild->CreateEx(m_hWndClient);
268 [!endif]
269 // TODO: add code to initialize document
271 return 0;
274 [!if WTL_APPTYPE_MTSDI]
275 LRESULT [!output WTL_FRAME_CLASS]::OnFileNewWindow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
277 ::PostThreadMessage(_Module.m_dwMainThreadID, WM_USER, 0, 0L);
278 return 0;
281 [!endif]
282 [!if WTL_USE_TOOLBAR]
283 LRESULT [!output WTL_FRAME_CLASS]::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
285 [!if WTL_USE_REBAR]
286 static BOOL bVisible = TRUE; // initially visible
287 bVisible = !bVisible;
288 CReBarCtrl rebar = m_hWndToolBar;
289 [!if WTL_USE_CMDBAR]
290 int nBandIndex = rebar.IdToIndex(ATL_IDW_BAND_FIRST + 1); // toolbar is 2nd added band
291 [!else]
292 int nBandIndex = rebar.IdToIndex(ATL_IDW_BAND_FIRST); // toolbar is first 1st band
293 [!endif]
294 rebar.ShowBand(nBandIndex, bVisible);
295 [!else]
296 BOOL bVisible = !::IsWindowVisible(m_hWndToolBar);
297 ::ShowWindow(m_hWndToolBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
298 [!endif]
299 UISetCheck(ID_VIEW_TOOLBAR, bVisible);
300 UpdateLayout();
301 return 0;
304 [!endif]
305 [!if WTL_USE_STATUSBAR]
306 LRESULT [!output WTL_FRAME_CLASS]::OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
308 BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar);
309 ::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
310 UISetCheck(ID_VIEW_STATUS_BAR, bVisible);
311 UpdateLayout();
312 return 0;
315 [!endif]
316 LRESULT [!output WTL_FRAME_CLASS]::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
318 CAboutDlg dlg;
319 dlg.DoModal();
320 return 0;
322 [!if WTL_APPTYPE_MDI]
324 LRESULT [!output WTL_FRAME_CLASS]::OnWindowCascade(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
326 MDICascade();
327 return 0;
330 LRESULT [!output WTL_FRAME_CLASS]::OnWindowTile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
332 MDITile();
333 return 0;
336 LRESULT [!output WTL_FRAME_CLASS]::OnWindowArrangeIcons(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
338 MDIIconArrange();
339 return 0;
341 [!endif]
342 [!if WTL_APPTYPE_TABVIEW]
344 LRESULT [!output WTL_FRAME_CLASS]::OnWindowClose(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
346 int nActivePage = m_view.GetActivePage();
347 if(nActivePage != -1)
348 m_view.RemovePage(nActivePage);
349 else
350 ::MessageBeep((UINT)-1);
352 return 0;
355 LRESULT [!output WTL_FRAME_CLASS]::OnWindowCloseAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
357 m_view.RemoveAllPages();
359 return 0;
362 LRESULT [!output WTL_FRAME_CLASS]::OnWindowActivate(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
364 int nPage = wID - ID_WINDOW_TABFIRST;
365 m_view.SetActivePage(nPage);
367 return 0;
369 [!endif]
370 [!if WTL_APPTYPE_EXPLORER]
372 LRESULT [!output WTL_FRAME_CLASS]::OnViewTreePane(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
374 bool bShow = (m_splitter.GetSinglePaneMode() != SPLIT_PANE_NONE);
375 m_splitter.SetSinglePaneMode(bShow ? SPLIT_PANE_NONE : SPLIT_PANE_RIGHT);
376 UISetCheck(ID_VIEW_TREEPANE, bShow);
378 return 0;
381 LRESULT [!output WTL_FRAME_CLASS]::OnTreePaneClose(WORD /*wNotifyCode*/, WORD /*wID*/, HWND hWndCtl, BOOL& /*bHandled*/)
383 if(hWndCtl == m_pane.m_hWnd)
385 m_splitter.SetSinglePaneMode(SPLIT_PANE_RIGHT);
386 UISetCheck(ID_VIEW_TREEPANE, 0);
389 return 0;
391 [!endif]