[!if RIBBON_TOOLBAR] // This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface // (the "Fluent UI") and is provided only as referential material to supplement the // Microsoft Foundation Classes Reference and related electronic documentation // included with the MFC C++ library software. // License terms to copy, use or distribute the Fluent UI are available separately. // To learn more about our Fluent UI licensing program, please visit // https://go.microsoft.com/fwlink/?LinkId=238214. // // Copyright (C) Microsoft Corporation // All rights reserved. [!endif] // $childframeimpl$ : implementation of the $childframeclass$ class // #include "pch.h" #include "framework.h" #include "$appheader$" #include "$childframeheader$" [!if PROJECT_STYLE_EXPLORER] #include "$treeviewheader$" #include "$viewheader$" [!endif] #ifdef _DEBUG #define new DEBUG_NEW #endif // $childframeclass$ IMPLEMENT_DYNCREATE($childframeclass$, $childframebaseclass$) BEGIN_MESSAGE_MAP($childframeclass$, $childframebaseclass$) [!if !DOCVIEW] ON_COMMAND(ID_FILE_CLOSE, &$childframeclass$::OnFileClose) ON_WM_SETFOCUS() ON_WM_CREATE() [!endif] [!if PROJECT_STYLE_EXPLORER] [!if LIST_VIEW] ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, &$childframeclass$::OnUpdateViewStyles) ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, &$childframeclass$::OnViewStyle) [!endif] [!endif] [!if PRINTING] [!if RIBBON_TOOLBAR] ON_COMMAND(ID_FILE_PRINT, &$childframeclass$::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, &$childframeclass$::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &$childframeclass$::OnFilePrintPreview) ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, &$childframeclass$::OnUpdateFilePrintPreview) [!endif] [!endif] END_MESSAGE_MAP() // $childframeclass$ construction/destruction $childframeclass$::$childframeclass$() noexcept { [!if ACCESSIBILITY] EnableActiveAccessibility(); [!endif] // TODO: add member initialization code here } $childframeclass$::~$childframeclass$() { } [!if APP_TYPE_MDI && SPLITTER] BOOL $childframeclass$::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($treeviewclass$), CSize(100, 100), pContext) || !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS($viewclass$), 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] } [!else] [!if PROJECT_STYLE_EXPLORER] BOOL $childframeclass$::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext) { // create splitter window if (!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE; if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS($treeviewclass$), CSize(100, 100), pContext) || !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS($viewclass$), CSize(100, 100), pContext)) { m_wndSplitter.DestroyWindow(); return FALSE; } return TRUE; } [!endif] [!endif] BOOL $childframeclass$::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs if( !$childframebaseclass$::PreCreateWindow(cs) ) return FALSE; [!if !CHILD_FRAME_DEFAULT_STYLES] cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | FWS_ADDTOTITLE$childframestyleflags$; [!endif] [!if !DOCVIEW] cs.dwExStyle &= ~WS_EX_CLIENTEDGE; cs.lpszClass = AfxRegisterWndClass(0); [!endif] return TRUE; } // $childframeclass$ diagnostics #ifdef _DEBUG void $childframeclass$::AssertValid() const { $childframebaseclass$::AssertValid(); } void $childframeclass$::Dump(CDumpContext& dc) const { $childframebaseclass$::Dump(dc); } #endif //_DEBUG // $childframeclass$ message handlers [!if PROJECT_STYLE_EXPLORER] [!if LIST_VIEW] $viewclass$* $childframeclass$::GetRightPane() { CWnd* pWnd = m_wndSplitter.GetPane(0, 1); $viewclass$* pView = DYNAMIC_DOWNCAST($viewclass$, pWnd); return pView; } void $childframeclass$::OnUpdateViewStyles(CCmdUI* pCmdUI) { if (!pCmdUI) return; // TODO: customize or extend this code to handle choices on the View menu. $viewclass$* pView = GetRightPane(); // if the right-hand pane hasn't been created or isn't a view, disable commands in our range if (pView == nullptr) 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 $childframeclass$::OnViewStyle(UINT nCommandID) { // TODO: customize or extend this code to handle choices on the View menu. $viewclass$* pView = GetRightPane(); // if the right-hand pane has been created and is a $viewclass$, process the menu commands... if (pView != nullptr) { int nStyle = -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: nStyle = LVS_REPORT; break; case ID_VIEW_SMALLICON: nStyle = LVS_SMALLICON; break; case ID_VIEW_LARGEICON: nStyle = LVS_ICON; break; case ID_VIEW_LIST: nStyle = LVS_LIST; break; } // change the style; window will repaint automatically if (nStyle != -1) pView->ModifyStyle(LVS_TYPEMASK, nStyle); } } [!endif] [!endif] [!if !DOCVIEW] void $childframeclass$::OnFileClose() { // To close the frame, just send a WM_CLOSE, which is the equivalent // choosing close from the system menu. SendMessage(WM_CLOSE); } int $childframeclass$::OnCreate(LPCREATESTRUCT lpCreateStruct) { if ($childframebaseclass$::OnCreate(lpCreateStruct) == -1) return -1; // create a view to occupy the client area of the frame if (!m_wndView.Create(nullptr, nullptr, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, nullptr)) { TRACE0("Failed to create view window\n"); return -1; } return 0; } void $childframeclass$::OnSetFocus(CWnd* pOldWnd) { $childframebaseclass$::OnSetFocus(pOldWnd); m_wndView.SetFocus(); } BOOL $childframeclass$::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 $childframebaseclass$::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); } [!endif] [!if PRINTING] [!if RIBBON_TOOLBAR] void $childframeclass$::OnFilePrint() { if (m_dockManager.IsPrintPreviewValid()) { PostMessage(WM_COMMAND, AFX_ID_PREVIEW_PRINT); } } void $childframeclass$::OnFilePrintPreview() { if (m_dockManager.IsPrintPreviewValid()) { PostMessage(WM_COMMAND, AFX_ID_PREVIEW_CLOSE); // force Print Preview mode closed } } void $childframeclass$::OnUpdateFilePrintPreview(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_dockManager.IsPrintPreviewValid()); } [!endif] [!endif]