Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
6.2 KiB

  1. // MainFrm.h : interface of the CMainFrame class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_MAINFRM_H__B6365AB2_8C89_4148_B58F_CBC7DB386F31__INCLUDED_)
  5. #define AFX_MAINFRM_H__B6365AB2_8C89_4148_B58F_CBC7DB386F31__INCLUDED_
  6. #if _MSC_VER >= 1000
  7. #pragma once
  8. #endif // _MSC_VER >= 1000
  9. class CMainFrame : public CFrameWindowImpl<CMainFrame>, public CUpdateUI<CMainFrame>,
  10. public CMessageFilter, public CIdleHandler
  11. {
  12. public:
  13. DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)
  14. CThreadCtlPerfView m_view;
  15. CCommandBarCtrl m_CmdBar;
  16. virtual BOOL PreTranslateMessage(MSG* pMsg)
  17. {
  18. if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
  19. return TRUE;
  20. return m_view.PreTranslateMessage(pMsg);
  21. }
  22. virtual BOOL OnIdle()
  23. {
  24. UIUpdateToolBar();
  25. return FALSE;
  26. }
  27. BEGIN_MSG_MAP(CMainFrame)
  28. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  29. MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
  30. MESSAGE_HANDLER(WM_MENUSELECT, OnMenuSelect)
  31. COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
  32. COMMAND_ID_HANDLER(ID_FILE_NEW, OnFileNew)
  33. COMMAND_ID_HANDLER(ID_FILE_NEW_WINDOW, OnFileNewWindow)
  34. COMMAND_ID_HANDLER(ID_VIEW_TOOLBAR, OnViewToolBar)
  35. COMMAND_ID_HANDLER(ID_VIEW_STATUS_BAR, OnViewStatusBar)
  36. COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
  37. CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
  38. CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
  39. END_MSG_MAP()
  40. BEGIN_UPDATE_UI_MAP(CMainFrame)
  41. UPDATE_ELEMENT(ID_VIEW_TOOLBAR, UPDUI_MENUPOPUP)
  42. UPDATE_ELEMENT(ID_VIEW_STATUS_BAR, UPDUI_MENUPOPUP)
  43. END_UPDATE_UI_MAP()
  44. LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  45. {
  46. // create command bar window
  47. HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
  48. // attach menu
  49. m_CmdBar.AttachMenu(GetMenu());
  50. // load command bar images
  51. m_CmdBar.LoadImages(IDR_MAINFRAME);
  52. // remove old menu
  53. SetMenu(NULL);
  54. HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
  55. CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
  56. AddSimpleReBarBand(hWndCmdBar);
  57. AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
  58. CreateSimpleStatusBar();
  59. m_hWndClient = m_view.Create(m_hWnd);
  60. UIAddToolBar(hWndToolBar);
  61. UISetCheck(ID_VIEW_TOOLBAR, 1);
  62. UISetCheck(ID_VIEW_STATUS_BAR, 1);
  63. CMessageLoop* pLoop = _Module.GetMessageLoop();
  64. pLoop->AddMessageFilter(this);
  65. pLoop->AddIdleHandler(this);
  66. WCHAR wzStatusText[256];
  67. __int64 liLast;
  68. ::QueryPerformanceCounter( (LARGE_INTEGER*) &liLast);
  69. (g_lpfnGetProcessMemoryInfo)(GetCurrentProcess(), &g_ProcessMem, sizeof(g_ProcessMem));
  70. wsprintf(wzStatusText, _T("Load time: %d ms. Workingset: %d bytes; peak %d bytes"),
  71. UINT(1000 * (liLast - g_liLast) / g_liFreq),
  72. g_ProcessMem.WorkingSetSize,
  73. g_ProcessMem.PeakWorkingSetSize);
  74. ::SendMessage(m_hWndStatusBar, SB_SIMPLE, TRUE, 0L);
  75. ::SendMessage(m_hWndStatusBar, SB_SETTEXT, (255 | SBT_NOBORDERS), (LPARAM)wzStatusText);
  76. if(OpenClipboard())
  77. {
  78. wsprintf(wzStatusText, _T("%d %d %d"),
  79. UINT(1000 * (liLast - g_liLast) / g_liFreq),
  80. g_ProcessMem.WorkingSetSize,
  81. g_ProcessMem.PeakWorkingSetSize);
  82. int nTextLen = (lstrlen(wzStatusText) + 1) * sizeof(TCHAR);
  83. HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nTextLen);
  84. if(hGlobal != NULL)
  85. {
  86. LPVOID lpText = GlobalLock(hGlobal);
  87. memcpy(lpText, wzStatusText, nTextLen);
  88. EmptyClipboard();
  89. GlobalUnlock(hGlobal);
  90. SetClipboardData(CF_UNICODETEXT, hGlobal);
  91. }
  92. CloseClipboard();
  93. }
  94. return 0;
  95. }
  96. LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  97. {
  98. bHandled = FALSE;
  99. ::PostQuitMessage(0);
  100. ::PostThreadMessage(_Module.m_dwMainThreadID, WM_USER + 1, 0, 0L);
  101. return 0;
  102. }
  103. LRESULT OnMenuSelect(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  104. {
  105. return 0;
  106. }
  107. LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  108. {
  109. PostMessage(WM_CLOSE);
  110. return 0;
  111. }
  112. LRESULT OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  113. {
  114. // TODO: add code to initialize document
  115. return 0;
  116. }
  117. LRESULT OnFileNewWindow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  118. {
  119. ::PostThreadMessage(_Module.m_dwMainThreadID, WM_USER, 0, 0L);
  120. return 0;
  121. }
  122. LRESULT OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  123. {
  124. static BOOL bVisible = TRUE; // initially visible
  125. bVisible = !bVisible;
  126. CReBarCtrl rebar = m_hWndToolBar;
  127. int nBandIndex = rebar.IdToIndex(ATL_IDW_BAND_FIRST + 1); // toolbar is 2nd added band
  128. rebar.ShowBand(nBandIndex, bVisible);
  129. UISetCheck(ID_VIEW_TOOLBAR, bVisible);
  130. UpdateLayout();
  131. return 0;
  132. }
  133. LRESULT OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  134. {
  135. BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar);
  136. ::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
  137. UISetCheck(ID_VIEW_STATUS_BAR, bVisible);
  138. UpdateLayout();
  139. return 0;
  140. }
  141. LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  142. {
  143. CAboutDlg dlg;
  144. dlg.DoModal();
  145. return 0;
  146. }
  147. };
  148. /////////////////////////////////////////////////////////////////////////////
  149. //{{AFX_INSERT_LOCATION}}
  150. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  151. #endif // !defined(AFX_MAINFRM_H__B6365AB2_8C89_4148_B58F_CBC7DB386F31__INCLUDED_)