// [!output MAIN_FRAME_IMPL] : implementation of the [!output MAIN_FRAME_CLASS] class // #include "stdafx.h" #include "[!output APP_HEADER]" #include "[!output MAIN_FRAME_HEADER]" [!if PROJECT_STYLE_EXPLORER] [!if APP_TYPE_SDI || APP_TYPE_MTLD] #include "[!output TREE_VIEW_HEADER]" #include "[!output VIEW_HEADER]" [!endif] [!endif] #ifdef _DEBUG #define new DEBUG_NEW #endif // [!output MAIN_FRAME_CLASS] [!if APP_TYPE_MDI || !DOCVIEW] IMPLEMENT_DYNAMIC([!output MAIN_FRAME_CLASS], [!output MAIN_FRAME_BASE_CLASS]) [!else] IMPLEMENT_DYNCREATE([!output MAIN_FRAME_CLASS], [!output MAIN_FRAME_BASE_CLASS]) [!endif] BEGIN_MESSAGE_MAP([!output MAIN_FRAME_CLASS], [!output MAIN_FRAME_BASE_CLASS]) [!if DOCKING_TOOLBAR || STATUS_BAR] ON_WM_CREATE() [!else] [!if APP_TYPE_SDI && !DOCVIEW] ON_WM_CREATE() [!endif] [!endif] [!if APP_TYPE_SDI] [!if !DOCVIEW] ON_WM_SETFOCUS() [!endif] [!endif] [!if APP_TYPE_MTLD] ON_COMMAND(ID_FILE_CLOSE, &[!output MAIN_FRAME_CLASS]::OnFileClose) [!if !DOCVIEW] ON_WM_CLOSE() [!endif] [!endif] [!if CONTEXT_HELP] // Global help commands ON_COMMAND(ID_HELP_FINDER, &[!output MAIN_FRAME_BASE_CLASS]::OnHelpFinder) ON_COMMAND(ID_HELP, &[!output MAIN_FRAME_BASE_CLASS]::OnHelp) ON_COMMAND(ID_CONTEXT_HELP, &[!output MAIN_FRAME_BASE_CLASS]::OnContextHelp) ON_COMMAND(ID_DEFAULT_HELP, &[!output MAIN_FRAME_BASE_CLASS]::OnHelpFinder) [!endif] [!if PROJECT_STYLE_EXPLORER] [!if APP_TYPE_SDI || APP_TYPE_MTLD] [!if LIST_VIEW] ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, &[!output MAIN_FRAME_CLASS]::OnUpdateViewStyles) ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, &[!output MAIN_FRAME_CLASS]::OnViewStyle) [!endif] [!endif] [!endif] END_MESSAGE_MAP() [!if STATUS_BAR] static UINT indicators[] = { ID_SEPARATOR, // status line indicator [!if DO_KANA] ID_INDICATOR_KANA, [!endif] ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; [!endif] // [!output MAIN_FRAME_CLASS] construction/destruction [!output MAIN_FRAME_CLASS]::[!output MAIN_FRAME_CLASS]() { [!if ACCESSIBILITY] EnableActiveAccessibility(); [!endif] // TODO: add member initialization code here } [!output MAIN_FRAME_CLASS]::~[!output MAIN_FRAME_CLASS]() { } [!if DOCKING_TOOLBAR || STATUS_BAR] int [!output MAIN_FRAME_CLASS]::OnCreate(LPCREATESTRUCT lpCreateStruct) { if ([!output MAIN_FRAME_BASE_CLASS]::OnCreate(lpCreateStruct) == -1) return -1; [!if APP_TYPE_SDI] [!if !DOCVIEW] // create a view to occupy the client area of the frame if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL)) { TRACE0("Failed to create view window\n"); return -1; } [!endif] [!endif] [!if DOCKING_TOOLBAR] [!if TOOLBAR_STYLE_REBAR] if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT) || [!else] if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || [!endif] !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } [!if TOOLBAR_STYLE_REBAR] [!if CONTAINER || CONTAINER_SERVER] m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() & ~CBRS_HIDE_INPLACE); [!endif] if (!m_wndDlgBar.Create(this, IDR_MAINFRAME, CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR)) { TRACE0("Failed to create dialogbar\n"); return -1; // fail to create } if (!m_wndReBar.Create(this) || !m_wndReBar.AddBar(&m_wndToolBar) || !m_wndReBar.AddBar(&m_wndDlgBar)) { TRACE0("Failed to create rebar\n"); return -1; // fail to create } [!if CONTAINER || CONTAINER_SERVER] m_wndReBar.SetBarStyle(m_wndReBar.GetBarStyle() & ~CBRS_HIDE_INPLACE); [!endif] [!endif] [!endif] [!if STATUS_BAR] if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } [!endif] [!if DOCKING_TOOLBAR] [!if TOOLBAR_STYLE_REBAR] // TODO: Remove this if you don't want tool tips m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY); [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] m_wndDlgBar.SetBarStyle(m_wndDlgBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY); [!endif] [!else] // TODO: Delete these three lines if you don't want the toolbar to be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); [!endif] [!endif] return 0; } [!else] [!if APP_TYPE_SDI && !DOCVIEW] int [!output MAIN_FRAME_CLASS]::OnCreate(LPCREATESTRUCT lpCreateStruct) { if ([!output MAIN_FRAME_BASE_CLASS]::OnCreate(lpCreateStruct) == -1) return -1; // create a view to occupy the client area of the frame if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL)) { TRACE0("Failed to create view window\n"); return -1; } return 0; } [!endif] [!endif] [!if SPLITTER || PROJECT_STYLE_EXPLORER] [!if APP_TYPE_SDI || APP_TYPE_MTLD] BOOL [!output MAIN_FRAME_CLASS]::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext) { [!if PROJECT_STYLE_EXPLORER] // create splitter window if (!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE; if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS([!output TREE_VIEW_CLASS]), CSize(100, 100), pContext) || !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS([!output VIEW_CLASS]), CSize(100, 100), pContext)) { m_wndSplitter.DestroyWindow(); return FALSE; } return TRUE; [!else] [!if HTML_VIEW || HTML_EDITVIEW] return m_wndSplitter.Create(this, 2, 2, // TODO: adjust the number of rows, columns CSize(10, 10), // TODO: adjust the minimum pane size pContext, WS_CHILD | WS_VISIBLE | SPLS_DYNAMIC_SPLIT); [!else] return m_wndSplitter.Create(this, 2, 2, // TODO: adjust the number of rows, columns CSize(10, 10), // TODO: adjust the minimum pane size pContext); [!endif] [!endif] } [!endif] [!endif] BOOL [!output MAIN_FRAME_CLASS]::PreCreateWindow(CREATESTRUCT& cs) { if( ![!output MAIN_FRAME_BASE_CLASS]::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs [!if !MAIN_FRAME_DEFAULT_STYLES] cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE [!output MAIN_FRAME_STYLE_FLAGS]; [!endif] [!if APP_TYPE_SDI] [!if !DOCVIEW] cs.dwExStyle &= ~WS_EX_CLIENTEDGE; cs.lpszClass = AfxRegisterWndClass(0); [!endif] [!endif] return TRUE; } // [!output MAIN_FRAME_CLASS] diagnostics #ifdef _DEBUG void [!output MAIN_FRAME_CLASS]::AssertValid() const { [!output MAIN_FRAME_BASE_CLASS]::AssertValid(); } void [!output MAIN_FRAME_CLASS]::Dump(CDumpContext& dc) const { [!output MAIN_FRAME_BASE_CLASS]::Dump(dc); } #endif //_DEBUG // [!output MAIN_FRAME_CLASS] message handlers [!if APP_TYPE_SDI] [!if !DOCVIEW] void [!output MAIN_FRAME_CLASS]::OnSetFocus(CWnd* /*pOldWnd*/) { // forward focus to the view window m_wndView.SetFocus(); } BOOL [!output MAIN_FRAME_CLASS]::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { // let the view have first crack at the command if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // otherwise, do default handling return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); } [!endif] [!endif] [!if APP_TYPE_SDI || APP_TYPE_MTLD] [!if PROJECT_STYLE_EXPLORER] [!if LIST_VIEW] [!output VIEW_CLASS]* [!output MAIN_FRAME_CLASS]::GetRightPane() { CWnd* pWnd = m_wndSplitter.GetPane(0, 1); [!output VIEW_CLASS]* pView = DYNAMIC_DOWNCAST([!output VIEW_CLASS], pWnd); return pView; } void [!output MAIN_FRAME_CLASS]::OnUpdateViewStyles(CCmdUI* pCmdUI) { if (!pCmdUI) return; // TODO: customize or extend this code to handle choices on the View menu [!output VIEW_CLASS]* pView = GetRightPane(); // if the right-hand pane hasn't been created or isn't a view, // disable commands in our range if (pView == NULL) pCmdUI->Enable(FALSE); else { DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK; // if the command is ID_VIEW_LINEUP, only enable command // when we're in LVS_ICON or LVS_SMALLICON mode if (pCmdUI->m_nID == ID_VIEW_LINEUP) { if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON) pCmdUI->Enable(); else pCmdUI->Enable(FALSE); } else { // otherwise, use dots to reflect the style of the view pCmdUI->Enable(); BOOL bChecked = FALSE; switch (pCmdUI->m_nID) { case ID_VIEW_DETAILS: bChecked = (dwStyle == LVS_REPORT); break; case ID_VIEW_SMALLICON: bChecked = (dwStyle == LVS_SMALLICON); break; case ID_VIEW_LARGEICON: bChecked = (dwStyle == LVS_ICON); break; case ID_VIEW_LIST: bChecked = (dwStyle == LVS_LIST); break; default: bChecked = FALSE; break; } pCmdUI->SetRadio(bChecked ? 1 : 0); } } } void [!output MAIN_FRAME_CLASS]::OnViewStyle(UINT nCommandID) { // TODO: customize or extend this code to handle choices on the View menu [!output VIEW_CLASS]* pView = GetRightPane(); // if the right-hand pane has been created and is a [!output VIEW_CLASS], // process the menu commands... if (pView != NULL) { DWORD dwStyle = -1; switch (nCommandID) { case ID_VIEW_LINEUP: { // ask the list control to snap to grid CListCtrl& refListCtrl = pView->GetListCtrl(); refListCtrl.Arrange(LVA_SNAPTOGRID); } break; // other commands change the style on the list control case ID_VIEW_DETAILS: dwStyle = LVS_REPORT; break; case ID_VIEW_SMALLICON: dwStyle = LVS_SMALLICON; break; case ID_VIEW_LARGEICON: dwStyle = LVS_ICON; break; case ID_VIEW_LIST: dwStyle = LVS_LIST; break; } // change the style; window will repaint automatically if (dwStyle != -1) pView->ModifyStyle(LVS_TYPEMASK, dwStyle); } } [!endif] [!endif] [!endif] [!if APP_TYPE_MTLD] BOOL [!output MAIN_FRAME_CLASS]::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) { // base class does the real work if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext)) { return FALSE; } CWinApp* pApp = AfxGetApp(); if (pApp->m_pMainWnd == NULL) pApp->m_pMainWnd = this; // replace Exit option on File menu with Close for secondary windows if (AfxGetApp()->m_pMainWnd != this) { CMenu *pMenu = GetMenu(); ASSERT(pMenu); pMenu->ModifyMenu(ID_APP_EXIT, MF_BYCOMMAND | MF_STRING, ID_FILE_CLOSE, _T("&Close")); } return TRUE; } void [!output MAIN_FRAME_CLASS]::OnFileClose() { DestroyWindow(); } [!if !DOCVIEW] void [!output MAIN_FRAME_CLASS]::OnClose() { [!output APP_CLASS] *pApp = reinterpret_cast<[!output APP_CLASS]*>(AfxGetApp()); // main window is being closed so cleanup if (pApp->m_pMainWnd == this) { for (int iCntr=0; iCntr < pApp->m_aryFrames.GetSize(); iCntr++) { HWND hFrame = pApp->m_aryFrames.GetAt(iCntr); if (::IsWindow(hFrame)) ::SendMessage(hFrame, WM_CLOSE, 0, 0); } } CFrameWnd::OnClose(); } [!endif] [!endif]