OutputWnd.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. #include "stdafx.h"
  12. #include "OutputWnd.h"
  13. #include "Resource.h"
  14. #include "MainFrm.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // COutputBar
  22. COutputWnd::COutputWnd() noexcept
  23. {
  24. }
  25. COutputWnd::~COutputWnd()
  26. {
  27. }
  28. BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)
  29. ON_WM_CREATE()
  30. ON_WM_SIZE()
  31. END_MESSAGE_MAP()
  32. int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  33. {
  34. if (CDockablePane::OnCreate(lpCreateStruct) == -1)
  35. return -1;
  36. CRect rectDummy;
  37. rectDummy.SetRectEmpty();
  38. // 创建选项卡窗口:
  39. if (!m_wndTabs.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, 1))
  40. {
  41. TRACE0("未能创建输出选项卡窗口\n");
  42. return -1; // 未能创建
  43. }
  44. // 创建输出窗格:
  45. const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
  46. if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_wndTabs, 2) ||
  47. !m_wndOutputDebug.Create(dwStyle, rectDummy, &m_wndTabs, 3) ||
  48. !m_wndOutputFind.Create(dwStyle, rectDummy, &m_wndTabs, 4))
  49. {
  50. TRACE0("未能创建输出窗口\n");
  51. return -1; // 未能创建
  52. }
  53. UpdateFonts();
  54. CString strTabName;
  55. BOOL bNameValid;
  56. // 将列表窗口附加到选项卡:
  57. bNameValid = strTabName.LoadString(IDS_BUILD_TAB);
  58. ASSERT(bNameValid);
  59. m_wndTabs.AddTab(&m_wndOutputBuild, strTabName, (UINT)0);
  60. bNameValid = strTabName.LoadString(IDS_DEBUG_TAB);
  61. ASSERT(bNameValid);
  62. m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);
  63. bNameValid = strTabName.LoadString(IDS_FIND_TAB);
  64. ASSERT(bNameValid);
  65. m_wndTabs.AddTab(&m_wndOutputFind, strTabName, (UINT)2);
  66. // 使用一些虚拟文本填写输出选项卡(无需复杂数据)
  67. FillBuildWindow();
  68. FillDebugWindow();
  69. FillFindWindow();
  70. return 0;
  71. }
  72. void COutputWnd::OnSize(UINT nType, int cx, int cy)
  73. {
  74. CDockablePane::OnSize(nType, cx, cy);
  75. // 选项卡控件应覆盖整个工作区:
  76. m_wndTabs.SetWindowPos (nullptr, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
  77. }
  78. void COutputWnd::AdjustHorzScroll(CListBox& wndListBox)
  79. {
  80. CClientDC dc(this);
  81. CFont* pOldFont = dc.SelectObject(&afxGlobalData.fontRegular);
  82. int cxExtentMax = 0;
  83. for (int i = 0; i < wndListBox.GetCount(); i ++)
  84. {
  85. CString strItem;
  86. wndListBox.GetText(i, strItem);
  87. cxExtentMax = max(cxExtentMax, (int)dc.GetTextExtent(strItem).cx);
  88. }
  89. wndListBox.SetHorizontalExtent(cxExtentMax);
  90. dc.SelectObject(pOldFont);
  91. }
  92. void COutputWnd::FillBuildWindow()
  93. {
  94. m_wndOutputBuild.AddString(_T("生成输出正显示在此处。"));
  95. m_wndOutputBuild.AddString(_T("输出正显示在列表视图的行中"));
  96. m_wndOutputBuild.AddString(_T("但您可以根据需要更改其显示方式..."));
  97. }
  98. void COutputWnd::FillDebugWindow()
  99. {
  100. m_wndOutputDebug.AddString(_T("调试输出正显示在此处。"));
  101. m_wndOutputDebug.AddString(_T("输出正显示在列表视图的行中"));
  102. m_wndOutputDebug.AddString(_T("但您可以根据需要更改其显示方式..."));
  103. }
  104. void COutputWnd::FillFindWindow()
  105. {
  106. m_wndOutputFind.AddString(_T("查找输出正显示在此处。"));
  107. m_wndOutputFind.AddString(_T("输出正显示在列表视图的行中"));
  108. m_wndOutputFind.AddString(_T("但您可以根据需要更改其显示方式..."));
  109. }
  110. void COutputWnd::UpdateFonts()
  111. {
  112. m_wndOutputBuild.SetFont(&afxGlobalData.fontRegular);
  113. m_wndOutputDebug.SetFont(&afxGlobalData.fontRegular);
  114. m_wndOutputFind.SetFont(&afxGlobalData.fontRegular);
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. // COutputList1
  118. COutputList::COutputList() noexcept
  119. {
  120. }
  121. COutputList::~COutputList()
  122. {
  123. }
  124. BEGIN_MESSAGE_MAP(COutputList, CListBox)
  125. ON_WM_CONTEXTMENU()
  126. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  127. ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  128. ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
  129. ON_WM_WINDOWPOSCHANGING()
  130. END_MESSAGE_MAP()
  131. /////////////////////////////////////////////////////////////////////////////
  132. // COutputList 消息处理程序
  133. void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
  134. {
  135. CMenu menu;
  136. menu.LoadMenu(IDR_OUTPUT_POPUP);
  137. CMenu* pSumMenu = menu.GetSubMenu(0);
  138. if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
  139. {
  140. CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
  141. if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
  142. return;
  143. ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
  144. UpdateDialogControls(this, FALSE);
  145. }
  146. SetFocus();
  147. }
  148. void COutputList::OnEditCopy()
  149. {
  150. MessageBox(_T("复制输出"));
  151. }
  152. void COutputList::OnEditClear()
  153. {
  154. MessageBox(_T("清除输出"));
  155. }
  156. void COutputList::OnViewOutput()
  157. {
  158. CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
  159. CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
  160. if (pMainFrame != nullptr && pParentBar != nullptr)
  161. {
  162. pMainFrame->SetFocus();
  163. pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
  164. pMainFrame->RecalcLayout();
  165. }
  166. }