[!if RIBBON_TOOLBAR] // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面 // (“Fluent UI”)。该示例仅供参考, // 用以补充《Microsoft 基础类参考》和 // MFC C++ 库软件随附的相关电子文档。 // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。 // 若要了解有关 Fluent UI 许可计划的详细信息,请访问 // https://go.microsoft.com/fwlink/?LinkId=238214. // // 版权所有(C) Microsoft Corporation // 保留所有权利。 [!endif] // $inplaceframeimpl$: $inplaceframeclass$ 类的实现 // #include "pch.h" #include "framework.h" #include "$appheader$" #include "$inplaceframeheader$" #ifdef _DEBUG #define new DEBUG_NEW #endif // $inplaceframeclass$ IMPLEMENT_DYNCREATE($inplaceframeclass$, $inplaceframebaseclass$) BEGIN_MESSAGE_MAP($inplaceframeclass$, $inplaceframebaseclass$) ON_WM_CREATE() END_MESSAGE_MAP() // $inplaceframeclass$ 构造/析构 $inplaceframeclass$::$inplaceframeclass$() { [!if ACCESSIBILITY] EnableActiveAccessibility(); [!endif] } $inplaceframeclass$::~$inplaceframeclass$() { } int $inplaceframeclass$::OnCreate(LPCREATESTRUCT lpCreateStruct) { if ($inplaceframebaseclass$::OnCreate(lpCreateStruct) == -1) return -1; // CResizeBar 实现就地调整大小。 if (!m_wndResizeBar.Create(this)) { TRACE0("Failed to create resize bar\n"); return -1; // 未能创建 } // 默认情况下,最好注册一个与框架窗口 // 无关的放置目标。 这将防止 // 拖放对象“错过”支持拖放的容器中。 m_dropTarget.Register(this); return 0; } [!if DOCKING_TOOLBAR || TOOLBAR_STYLE_REBAR || MENUBAR_TOOLBAR || RIBBON_TOOLBAR] // 框架将调用 OnCreateControlBars 以便在 // 容器应用程序的窗口上创建控件条。 pWndFrame 是容器的顶级框架窗口, // 为容器并且始终不为 null。pWndDoc 是文档级框架窗口 // 并且在容器是 SDI 应用程序时将为 null。服务器 // 服务器应用程序可以将 MFC 控件条放在这两个窗口中的任何一个上。 BOOL $inplaceframeclass$::OnCreateControlBars(CFrameWnd* pWndFrame, CFrameWnd* pWndDoc) { // 如果使用 pWndDoc,则将此移除 UNREFERENCED_PARAMETER(pWndDoc); // 设置此窗口的所有者,以便将消息发送到正确的应用程序 m_wndToolBar.SetOwner(this); [!if MENUBAR_TOOLBAR || RIBBON_TOOLBAR] if (!$inplaceframebaseclass$::OnCreateControlBars(pWndFrame, pWndDoc)) { return FALSE; } COleCntrFrameWndEx* pNewFrame = DYNAMIC_DOWNCAST(COleCntrFrameWndEx, m_pMainFrame); ASSERT_VALID(pNewFrame); [!endif] // 在客户端的框架窗口上创建工具栏 [!if TOOLBAR_STYLE_REBAR] if (!m_wndToolBar.CreateEx(pWndFrame, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT) || [!else] [!if MENUBAR_TOOLBAR || RIBBON_TOOLBAR] if (!m_wndToolBar.CreateEx(pNewFrame, TBSTYLE_FLAT,WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || [!else] if (!m_wndToolBar.CreateEx(pWndFrame, TBSTYLE_FLAT,WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || [!endif] [!endif] [!if APP_TYPE_MDI] [!if MENUBAR_TOOLBAR] !m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_$safedoctypename$TYPE_SRVR_IP_256 : IDR_$safedoctypename$TYPE_SRVR_IP)) [!else] !m_wndToolBar.LoadToolBar(IDR_$safedoctypename$TYPE_SRVR_IP)) [!endif] [!else] [!if MENUBAR_TOOLBAR] !m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_SRVR_INPLACE_256 : IDR_SRVR_INPLACE)) [!else] !m_wndToolBar.LoadToolBar(IDR_SRVR_INPLACE)) [!endif] [!endif] { TRACE0("Failed to create toolbar\n"); return FALSE; } [!if TOOLBAR_STYLE_REBAR] // 设置此窗口的所有者,以便将消息发送到正确的应用程序 m_wndDlgBar.SetOwner(this); // 在客户端的框架窗口上创建对话栏 [!if APP_TYPE_MDI] if (!m_wndDlgBar.Create(pWndFrame, IDR_$safedoctypename$TYPE_SRVR_IP, [!else] if (!m_wndDlgBar.Create(pWndFrame, IDR_SRVR_INPLACE, [!endif] CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR)) { TRACE0("Failed to create dialogbar\n"); return FALSE; } // 设置此窗口的所有者,以便将消息发送到正确的应用程序 m_wndReBar.SetOwner(this); // 在客户端的框架窗口上创建 Rebar if (!m_wndReBar.Create(pWndFrame) || !m_wndReBar.AddBar(&m_wndToolBar) || !m_wndReBar.AddBar(&m_wndDlgBar)) { TRACE0("Failed to create rebar\n"); return FALSE; } [!else] // TODO: 如果不需要可停靠工具栏,则删除这三行 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); [!if MENUBAR_TOOLBAR || RIBBON_TOOLBAR] pNewFrame->EnableDocking(CBRS_ALIGN_ANY); pNewFrame->DockPane(&m_wndToolBar); // TODO: 如果不需要工具使用技巧,则将此移除 m_wndToolBar.SetControlBarStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY); [!else] pWndFrame->EnableDocking(CBRS_ALIGN_ANY); pWndFrame->DockControlBar(&m_wndToolBar); [!endif] [!endif] return TRUE; } [!endif] BOOL $inplaceframeclass$::PreCreateWindow(CREATESTRUCT& cs) { // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式 return $inplaceframebaseclass$::PreCreateWindow(cs); } // $inplaceframeclass$ 诊断 #ifdef _DEBUG void $inplaceframeclass$::AssertValid() const { $inplaceframebaseclass$::AssertValid(); } void $inplaceframeclass$::Dump(CDumpContext& dc) const { $inplaceframebaseclass$::Dump(dc); } #endif //_DEBUG // $inplaceframeclass$ 命令