MainFrm.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
  2. // (“Fluent UI”)。该示例仅供参考,
  3. // 用以补充《Microsoft 基础类参考》和
  4. // MFC C++ 库软件随附的相关电子文档。
  5. // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
  6. // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
  7. // https://go.microsoft.com/fwlink/?LinkId=238214.
  8. //
  9. // 版权所有(C) Microsoft Corporation
  10. // 保留所有权利。
  11. // MainFrm.cpp: CMainFrame 类的实现
  12. //
  13. #include "stdafx.h"
  14. #include "IDE.h"
  15. #include "MainFrm.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #endif
  19. // CMainFrame
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
  21. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
  22. ON_WM_CREATE()
  23. ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnApplicationLook)
  24. ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnUpdateApplicationLook)
  25. ON_COMMAND(ID_VIEW_CLASS_BAR, &CMainFrame::OnClassViewCaptionBar)
  26. ON_UPDATE_COMMAND_UI(ID_VIEW_CLASS_BAR, &CMainFrame::OnUpdateClassViewCaptionBar)
  27. ON_COMMAND(ID_TOOLS_OPTIONS, &CMainFrame::OnOptions)
  28. ON_COMMAND(ID_VIEW_FILEVIEW, &CMainFrame::OnViewFileView)
  29. ON_UPDATE_COMMAND_UI(ID_VIEW_FILEVIEW, &CMainFrame::OnUpdateViewFileView)
  30. ON_COMMAND(ID_VIEW_CLASSVIEW, &CMainFrame::OnViewClassView)
  31. ON_UPDATE_COMMAND_UI(ID_VIEW_CLASSVIEW, &CMainFrame::OnUpdateViewClassView)
  32. ON_COMMAND(ID_VIEW_OUTPUTWND, &CMainFrame::OnViewOutputWindow)
  33. ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUTWND, &CMainFrame::OnUpdateViewOutputWindow)
  34. ON_COMMAND(ID_VIEW_PROPERTIESWND, &CMainFrame::OnViewPropertiesWindow)
  35. ON_UPDATE_COMMAND_UI(ID_VIEW_PROPERTIESWND, &CMainFrame::OnUpdateViewPropertiesWindow)
  36. ON_COMMAND(ID_FILE_PRINT, &CMainFrame::OnFilePrint)
  37. ON_COMMAND(ID_FILE_PRINT_DIRECT, &CMainFrame::OnFilePrint)
  38. ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMainFrame::OnFilePrintPreview)
  39. ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, &CMainFrame::OnUpdateFilePrintPreview)
  40. ON_WM_SETTINGCHANGE()
  41. ON_WM_GETMINMAXINFO()
  42. ON_COMMAND(ID_VIEW_FILE_BAR, &CMainFrame::OnViewFileBar)
  43. ON_UPDATE_COMMAND_UI(ID_VIEW_FILE_BAR, &CMainFrame::OnUpdateViewFileBar)
  44. ON_COMMAND(ID_VIEW_PROPERTY_BAR, &CMainFrame::OnViewPropertyBar)
  45. ON_UPDATE_COMMAND_UI(ID_VIEW_PROPERTY_BAR, &CMainFrame::OnUpdateViewPropertyBar)
  46. ON_COMMAND(ID_VIEW_OUTPUT_BAR, &CMainFrame::OnViewOutputBar)
  47. ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT_BAR, &CMainFrame::OnUpdateViewOutputBar)
  48. END_MESSAGE_MAP()
  49. // CMainFrame 构造/析构
  50. CMainFrame::CMainFrame() noexcept
  51. {
  52. // TODO: 在此添加成员初始化代码
  53. theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2008);
  54. }
  55. CMainFrame::~CMainFrame()
  56. {
  57. }
  58. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  59. {
  60. if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
  61. return -1;
  62. BOOL bNameValid;
  63. m_wndRibbonBar.Create(this);
  64. m_wndRibbonBar.LoadFromResource(IDR_RIBBON);
  65. #if !__QUICKACCESS_COMMAND__
  66. CMFCRibbonQuickAccessToolBar* pQAToolbar = m_wndRibbonBar.GetQuickAccessToolbar();
  67. pQAToolbar->RemoveAll();
  68. #endif
  69. if (!m_wndStatusBar.Create(this))
  70. {
  71. TRACE0("未能创建状态栏\n");
  72. return -1; // 未能创建
  73. }
  74. CString strTitlePane1;
  75. CString strTitlePane2;
  76. bNameValid = strTitlePane1.LoadString(IDS_STATUS_PANE1);
  77. ASSERT(bNameValid);
  78. bNameValid = strTitlePane2.LoadString(IDS_STATUS_PANE2);
  79. ASSERT(bNameValid);
  80. m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE1, strTitlePane1, TRUE), strTitlePane1);
  81. m_wndStatusBar.AddExtendedElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE2, strTitlePane2, TRUE), strTitlePane2);
  82. // 启用 Visual Studio 2005 样式停靠窗口行为
  83. CDockingManager::SetDockingMode(DT_SMART);
  84. // 启用 Visual Studio 2005 样式停靠窗口自动隐藏行为
  85. EnableAutoHidePanes(CBRS_ALIGN_ANY);
  86. #if __OUTLOOKBAR__
  87. // 导航窗格将创建在左侧,因此将暂时禁用左侧的停靠:
  88. EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM | CBRS_ALIGN_RIGHT);
  89. // 创建并设置“Outlook”导航栏:
  90. if (!CreateOutlookBar(m_wndNavigationBar, ID_VIEW_NAVIGATION, m_wndTree, m_wndCalendar, 250))
  91. {
  92. TRACE0("未能创建导航窗格\n");
  93. return -1; // 未能创建
  94. }
  95. #endif
  96. #if __CAPTIONBAR__
  97. // 创建标题栏:
  98. if (!CreateCaptionBar())
  99. {
  100. TRACE0("未能创建标题栏\n");
  101. return -1; // 未能创建
  102. }
  103. #endif
  104. #if __OUTLOOKBAR__
  105. // 已创建 Outlook 栏,应允许在左侧停靠。
  106. EnableDocking(CBRS_ALIGN_LEFT);
  107. EnableAutoHidePanes(CBRS_ALIGN_RIGHT);
  108. #endif
  109. // 加载菜单项图像(不在任何标准工具栏上):
  110. CMFCToolBar::AddToolBarForImageCollection(IDR_MENU_IMAGES, theApp.m_bHiColorIcons ? IDB_MENU_IMAGES_24 : 0);
  111. // 创建停靠窗口
  112. if (!CreateDockingWindows())
  113. {
  114. TRACE0("未能创建停靠窗口\n");
  115. return -1;
  116. }
  117. m_wndFileView.EnableDocking(CBRS_ALIGN_ANY);
  118. m_wndClassView.EnableDocking(CBRS_ALIGN_ANY);
  119. DockPane(&m_wndFileView);
  120. CDockablePane* pTabbedBar = nullptr;
  121. m_wndClassView.AttachToTabWnd(&m_wndFileView, DM_SHOW, TRUE, &pTabbedBar);
  122. m_wndOutput.EnableDocking(CBRS_ALIGN_ANY);
  123. DockPane(&m_wndOutput);
  124. m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
  125. DockPane(&m_wndProperties);
  126. // 基于持久值设置视觉管理器和样式
  127. OnApplicationLook(theApp.m_nAppLook);
  128. return 0;
  129. }
  130. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  131. {
  132. if( !CFrameWndEx::PreCreateWindow(cs) )
  133. return FALSE;
  134. // TODO: 在此处通过修改
  135. // CREATESTRUCT cs 来修改窗口类或样式
  136. return TRUE;
  137. }
  138. BOOL CMainFrame::CreateDockingWindows()
  139. {
  140. BOOL bNameValid;
  141. // 创建类视图
  142. CString strClassView;
  143. bNameValid = strClassView.LoadString(IDS_CLASS_VIEW);
  144. ASSERT(bNameValid);
  145. if (!m_wndClassView.Create(strClassView, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_CLASSVIEW, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
  146. {
  147. TRACE0("未能创建“类视图”窗口\n");
  148. return FALSE; // 未能创建
  149. }
  150. // 创建文件视图
  151. CString strFileView;
  152. bNameValid = strFileView.LoadString(IDS_FILE_VIEW);
  153. ASSERT(bNameValid);
  154. if (!m_wndFileView.Create(strFileView, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_FILEVIEW, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT| CBRS_FLOAT_MULTI))
  155. {
  156. TRACE0("未能创建“文件视图”窗口\n");
  157. return FALSE; // 未能创建
  158. }
  159. // 创建输出窗口
  160. CString strOutputWnd;
  161. bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);
  162. ASSERT(bNameValid);
  163. if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 100, 100), TRUE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
  164. {
  165. TRACE0("未能创建输出窗口\n");
  166. return FALSE; // 未能创建
  167. }
  168. // 创建属性窗口
  169. CString strPropertiesWnd;
  170. bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
  171. ASSERT(bNameValid);
  172. if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
  173. {
  174. TRACE0("未能创建“属性”窗口\n");
  175. return FALSE; // 未能创建
  176. }
  177. SetDockingWindowIcons(theApp.m_bHiColorIcons);
  178. return TRUE;
  179. }
  180. void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)
  181. {
  182. HICON hFileViewIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_FILE_VIEW_HC : IDI_FILE_VIEW), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
  183. m_wndFileView.SetIcon(hFileViewIcon, FALSE);
  184. HICON hClassViewIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_CLASS_VIEW_HC : IDI_CLASS_VIEW), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
  185. m_wndClassView.SetIcon(hClassViewIcon, FALSE);
  186. HICON hOutputBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_OUTPUT_WND_HC : IDI_OUTPUT_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
  187. m_wndOutput.SetIcon(hOutputBarIcon, FALSE);
  188. HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
  189. m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);
  190. }
  191. #if __OUTLOOKBAR__
  192. BOOL CMainFrame::CreateOutlookBar(CMFCOutlookBar& bar, UINT uiID, CMFCShellTreeCtrl& tree, CCalendarBar& calendar, int nInitialWidth)
  193. {
  194. bar.SetMode2003();
  195. BOOL bNameValid;
  196. CString strTemp;
  197. bNameValid = strTemp.LoadString(IDS_SHORTCUTS);
  198. ASSERT(bNameValid);
  199. if (!bar.Create(strTemp, this, CRect(0, 0, nInitialWidth, 32000), uiID, WS_CHILD | WS_VISIBLE | CBRS_LEFT))
  200. {
  201. return FALSE; // 未能创建
  202. }
  203. CMFCOutlookBarTabCtrl* pOutlookBar = (CMFCOutlookBarTabCtrl*)bar.GetUnderlyingWindow();
  204. if (pOutlookBar == nullptr)
  205. {
  206. ASSERT(FALSE);
  207. return FALSE;
  208. }
  209. pOutlookBar->EnableInPlaceEdit(TRUE);
  210. static UINT uiPageID = 1;
  211. // 可浮动,可自动隐藏,可调整大小,但不能关闭
  212. DWORD dwStyle = AFX_CBRS_FLOAT | AFX_CBRS_AUTOHIDE | AFX_CBRS_RESIZE;
  213. CRect rectDummy(0, 0, 0, 0);
  214. const DWORD dwTreeStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
  215. tree.Create(dwTreeStyle, rectDummy, &bar, 1200);
  216. bNameValid = strTemp.LoadString(IDS_FOLDERS);
  217. ASSERT(bNameValid);
  218. pOutlookBar->AddControl(&tree, strTemp, 2, TRUE, dwStyle);
  219. calendar.Create(rectDummy, &bar, 1201);
  220. bNameValid = strTemp.LoadString(IDS_CALENDAR);
  221. ASSERT(bNameValid);
  222. pOutlookBar->AddControl(&calendar, strTemp, 3, TRUE, dwStyle);
  223. bar.SetPaneStyle(bar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  224. pOutlookBar->SetImageList(theApp.m_bHiColorIcons ? IDB_PAGES_HC : IDB_PAGES, 24);
  225. pOutlookBar->SetToolbarImageList(theApp.m_bHiColorIcons ? IDB_PAGES_SMALL_HC : IDB_PAGES_SMALL, 16);
  226. pOutlookBar->RecalcLayout();
  227. BOOL bAnimation = theApp.GetInt(_T("OutlookAnimation"), TRUE);
  228. CMFCOutlookBarTabCtrl::EnableAnimation(bAnimation);
  229. bar.SetButtonsFont(&afxGlobalData.fontBold);
  230. return TRUE;
  231. }
  232. #endif
  233. #if __CAPTIONBAR__
  234. BOOL CMainFrame::CreateCaptionBar()
  235. {
  236. if (!m_wndCaptionBar.Create(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, this, ID_VIEW_CAPTION_BAR, -1, TRUE))
  237. {
  238. TRACE0("未能创建标题栏\n");
  239. return FALSE;
  240. }
  241. BOOL bNameValid;
  242. CString strTemp, strTemp2;
  243. bNameValid = strTemp.LoadString(IDS_CAPTION_BUTTON);
  244. ASSERT(bNameValid);
  245. m_wndCaptionBar.SetButton(strTemp, ID_TOOLS_OPTIONS, CMFCCaptionBar::ALIGN_LEFT, FALSE);
  246. bNameValid = strTemp.LoadString(IDS_CAPTION_BUTTON_TIP);
  247. ASSERT(bNameValid);
  248. m_wndCaptionBar.SetButtonToolTip(strTemp);
  249. bNameValid = strTemp.LoadString(IDS_CAPTION_TEXT);
  250. ASSERT(bNameValid);
  251. m_wndCaptionBar.SetText(strTemp, CMFCCaptionBar::ALIGN_LEFT);
  252. m_wndCaptionBar.SetBitmap(IDB_INFO, RGB(255, 255, 255), FALSE, CMFCCaptionBar::ALIGN_LEFT);
  253. bNameValid = strTemp.LoadString(IDS_CAPTION_IMAGE_TIP);
  254. ASSERT(bNameValid);
  255. bNameValid = strTemp2.LoadString(IDS_CAPTION_IMAGE_TEXT);
  256. ASSERT(bNameValid);
  257. m_wndCaptionBar.SetImageToolTip(strTemp, strTemp2);
  258. return TRUE;
  259. }
  260. #endif
  261. // CMainFrame 诊断
  262. #ifdef _DEBUG
  263. void CMainFrame::AssertValid() const
  264. {
  265. CFrameWndEx::AssertValid();
  266. }
  267. void CMainFrame::Dump(CDumpContext& dc) const
  268. {
  269. CFrameWndEx::Dump(dc);
  270. }
  271. #endif //_DEBUG
  272. // CMainFrame 消息处理程序
  273. void CMainFrame::OnApplicationLook(UINT id)
  274. {
  275. CWaitCursor wait;
  276. theApp.m_nAppLook = id;
  277. switch (theApp.m_nAppLook)
  278. {
  279. case ID_VIEW_APPLOOK_WIN_2000:
  280. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));
  281. m_wndRibbonBar.SetWindows7Look(FALSE);
  282. break;
  283. case ID_VIEW_APPLOOK_OFF_XP:
  284. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
  285. m_wndRibbonBar.SetWindows7Look(FALSE);
  286. break;
  287. case ID_VIEW_APPLOOK_WIN_XP:
  288. CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
  289. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
  290. m_wndRibbonBar.SetWindows7Look(FALSE);
  291. break;
  292. case ID_VIEW_APPLOOK_OFF_2003:
  293. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
  294. CDockingManager::SetDockingMode(DT_SMART);
  295. m_wndRibbonBar.SetWindows7Look(FALSE);
  296. break;
  297. case ID_VIEW_APPLOOK_VS_2005:
  298. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
  299. CDockingManager::SetDockingMode(DT_SMART);
  300. m_wndRibbonBar.SetWindows7Look(FALSE);
  301. break;
  302. case ID_VIEW_APPLOOK_VS_2008:
  303. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008));
  304. CDockingManager::SetDockingMode(DT_SMART);
  305. m_wndRibbonBar.SetWindows7Look(FALSE);
  306. break;
  307. case ID_VIEW_APPLOOK_WINDOWS_7:
  308. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
  309. CDockingManager::SetDockingMode(DT_SMART);
  310. m_wndRibbonBar.SetWindows7Look(TRUE);
  311. break;
  312. default:
  313. switch (theApp.m_nAppLook)
  314. {
  315. case ID_VIEW_APPLOOK_OFF_2007_BLUE:
  316. CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
  317. break;
  318. case ID_VIEW_APPLOOK_OFF_2007_BLACK:
  319. CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
  320. break;
  321. case ID_VIEW_APPLOOK_OFF_2007_SILVER:
  322. CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
  323. break;
  324. case ID_VIEW_APPLOOK_OFF_2007_AQUA:
  325. CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
  326. break;
  327. }
  328. CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
  329. CDockingManager::SetDockingMode(DT_SMART);
  330. m_wndRibbonBar.SetWindows7Look(FALSE);
  331. }
  332. m_wndOutput.UpdateFonts();
  333. RedrawWindow(nullptr, nullptr, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
  334. theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
  335. }
  336. void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
  337. {
  338. pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
  339. }
  340. void CMainFrame::OnClassViewCaptionBar()
  341. {
  342. #if __CAPTIONBAR__
  343. m_wndCaptionBar.ShowWindow(m_wndCaptionBar.IsVisible() ? SW_HIDE : SW_SHOW);
  344. #endif
  345. #if 1
  346. // 类视图;
  347. BOOL bVisible = m_wndClassView.IsVisible();
  348. m_wndClassView.ShowPane(!bVisible, FALSE, !bVisible);
  349. #endif
  350. RecalcLayout(FALSE);
  351. }
  352. void CMainFrame::OnUpdateClassViewCaptionBar(CCmdUI* pCmdUI)
  353. {
  354. #if __CAPTIONBAR__
  355. pCmdUI->SetCheck(m_wndCaptionBar.IsVisible());
  356. #endif
  357. #if 1
  358. pCmdUI->SetCheck(m_wndClassView.IsVisible());
  359. #endif
  360. }
  361. void CMainFrame::OnOptions()
  362. {
  363. CMFCRibbonCustomizeDialog *pOptionsDlg = new CMFCRibbonCustomizeDialog(this, &m_wndRibbonBar);
  364. ASSERT(pOptionsDlg != nullptr);
  365. pOptionsDlg->DoModal();
  366. delete pOptionsDlg;
  367. }
  368. void CMainFrame::OnViewFileView()
  369. {
  370. // 显示或激活窗格,具体取决于当前状态。
  371. // 只能通过窗格帧上的 [x] 按钮关闭窗格。
  372. m_wndFileView.ShowPane(TRUE, FALSE, TRUE);
  373. m_wndFileView.SetFocus();
  374. }
  375. void CMainFrame::OnUpdateViewFileView(CCmdUI* pCmdUI)
  376. {
  377. pCmdUI->Enable(TRUE);
  378. }
  379. void CMainFrame::OnViewClassView()
  380. {
  381. // 显示或激活窗格,具体取决于当前状态。
  382. // 只能通过窗格帧上的 [x] 按钮关闭窗格。
  383. m_wndClassView.ShowPane(TRUE, FALSE, TRUE);
  384. m_wndClassView.SetFocus();
  385. }
  386. void CMainFrame::OnUpdateViewClassView(CCmdUI* pCmdUI)
  387. {
  388. pCmdUI->Enable(TRUE);
  389. }
  390. void CMainFrame::OnViewOutputWindow()
  391. {
  392. // 显示或激活窗格,具体取决于当前状态。
  393. // 只能通过窗格帧上的 [x] 按钮关闭窗格。
  394. m_wndOutput.ShowPane(TRUE, FALSE, TRUE);
  395. m_wndOutput.SetFocus();
  396. }
  397. void CMainFrame::OnUpdateViewOutputWindow(CCmdUI* pCmdUI)
  398. {
  399. pCmdUI->Enable(TRUE);
  400. }
  401. void CMainFrame::OnViewPropertiesWindow()
  402. {
  403. // 显示或激活窗格,具体取决于当前状态。
  404. // 只能通过窗格帧上的 [x] 按钮关闭窗格。
  405. m_wndProperties.ShowPane(TRUE, FALSE, TRUE);
  406. m_wndProperties.SetFocus();
  407. }
  408. void CMainFrame::OnUpdateViewPropertiesWindow(CCmdUI* pCmdUI)
  409. {
  410. pCmdUI->Enable(TRUE);
  411. }
  412. void CMainFrame::OnFilePrint()
  413. {
  414. if (IsPrintPreview())
  415. {
  416. PostMessage(WM_COMMAND, AFX_ID_PREVIEW_PRINT);
  417. }
  418. }
  419. void CMainFrame::OnFilePrintPreview()
  420. {
  421. if (IsPrintPreview())
  422. {
  423. PostMessage(WM_COMMAND, AFX_ID_PREVIEW_CLOSE); // 强制关闭“打印预览”模式
  424. }
  425. }
  426. void CMainFrame::OnUpdateFilePrintPreview(CCmdUI* pCmdUI)
  427. {
  428. pCmdUI->SetCheck(IsPrintPreview());
  429. }
  430. void CMainFrame::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
  431. {
  432. CFrameWndEx::OnSettingChange(uFlags, lpszSection);
  433. m_wndOutput.UpdateFonts();
  434. }
  435. void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
  436. {
  437. // TODO: 在此添加消息处理程序代码和/或调用默认值
  438. // 640*480//800*600
  439. // 设置窗口最小范围;
  440. lpMMI->ptMinTrackSize.x = 800;
  441. lpMMI->ptMinTrackSize.y = 600;
  442. CFrameWndEx::OnGetMinMaxInfo(lpMMI);
  443. }
  444. void CMainFrame::OnViewFileBar()
  445. {
  446. // TODO: 在此添加命令处理程序代码
  447. // 类视图;
  448. BOOL bVisible = m_wndFileView.IsVisible();
  449. m_wndFileView.ShowPane(!bVisible, FALSE, !bVisible);
  450. RecalcLayout(FALSE);
  451. }
  452. void CMainFrame::OnUpdateViewFileBar(CCmdUI *pCmdUI)
  453. {
  454. // TODO: 在此添加命令更新用户界面处理程序代码
  455. pCmdUI->SetCheck(m_wndFileView.IsVisible());
  456. }
  457. void CMainFrame::OnViewPropertyBar()
  458. {
  459. // TODO: 在此添加命令处理程序代码
  460. BOOL bVisible = m_wndProperties.IsVisible();
  461. m_wndProperties.ShowPane(!bVisible, FALSE, !bVisible);
  462. RecalcLayout(FALSE);
  463. }
  464. void CMainFrame::OnUpdateViewPropertyBar(CCmdUI *pCmdUI)
  465. {
  466. // TODO: 在此添加命令更新用户界面处理程序代码
  467. pCmdUI->SetCheck(m_wndProperties.IsVisible());
  468. }
  469. void CMainFrame::OnViewOutputBar()
  470. {
  471. // TODO: 在此添加命令处理程序代码
  472. BOOL bVisible = m_wndOutput.IsVisible();
  473. m_wndOutput.ShowPane(!bVisible, FALSE, !bVisible);
  474. RecalcLayout(FALSE);
  475. }
  476. void CMainFrame::OnUpdateViewOutputBar(CCmdUI *pCmdUI)
  477. {
  478. // TODO: 在此添加命令更新用户界面处理程序代码
  479. pCmdUI->SetCheck(m_wndOutput.IsVisible());
  480. }