MainFrm.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:12k
源码类别:

界面编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "HelpNotes.h"
  5. #include "MainFrm.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMainFrame
  13. IMPLEMENT_DYNAMIC( CMainFrame, CFrameWnd )
  14. BEGIN_MESSAGE_MAP( CMainFrame, CFrameWnd )
  15. //{{AFX_MSG_MAP(CMainFrame)
  16. ON_WM_CREATE()
  17. ON_WM_SETFOCUS()
  18. //}}AFX_MSG_MAP
  19. ON_COMMAND_EX(ID_VIEW_MENUBAR, OnBarCheck )
  20. ON_UPDATE_COMMAND_UI(ID_VIEW_MENUBAR, OnUpdateControlBarMenu)
  21. ON_COMMAND_EX(ID_VIEW_UI_LOOK_BAR, OnBarCheck )
  22. ON_UPDATE_COMMAND_UI(ID_VIEW_UI_LOOK_BAR, OnUpdateControlBarMenu)
  23. ON_REGISTERED_MESSAGE( CExtPopupMenuWnd::g_nMsgItemCoveringNotification, OnItemCoveringNotification )
  24. ON_REGISTERED_MESSAGE( CExtPopupMenuWnd::g_nMsgPrepareDesktopBk, OnAnyDeactivatePopup )
  25. ON_REGISTERED_MESSAGE( CExtPopupMenuWnd::g_nMsgNotifyMenuExpanded, OnAnyDeactivatePopup )
  26. ON_REGISTERED_MESSAGE( CExtPopupMenuWnd::g_nMsgNotifyMenuClosed, OnAnyDeactivatePopup )
  27. END_MESSAGE_MAP()
  28. static UINT indicators[] =
  29. {
  30. ID_SEPARATOR,           // status line indicator
  31. ID_INDICATOR_CAPS,
  32. ID_INDICATOR_NUM,
  33. ID_INDICATOR_SCRL,
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMainFrame construction/destruction
  37. CMainFrame::CMainFrame()
  38. : m_pWndView( NULL )
  39. {
  40. CWinApp * pApp = ::AfxGetApp();
  41. ASSERT( pApp != NULL );
  42. ASSERT( pApp->m_pszRegistryKey != NULL );
  43. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  44. ASSERT( pApp->m_pszProfileName != NULL );
  45. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  46. if( ! g_PaintManager.PaintManagerStateLoad(
  47. pApp->m_pszRegistryKey,
  48. pApp->m_pszProfileName,
  49. pApp->m_pszProfileName
  50. )
  51. )
  52. g_PaintManager.InstallPaintManager(
  53. RUNTIME_CLASS(CExtPaintManagerNativeXP)
  54. );
  55. CExtPopupMenuWnd::g_bMenuExpanding = false;
  56. CExtPopupMenuWnd::g_bMenuHighlightRarely = false;
  57. CExtPopupMenuWnd::g_bMenuShowCoolTips = false;
  58. // window placement persistence
  59. ::memset( &m_dataFrameWP, 0, sizeof(WINDOWPLACEMENT) );
  60. m_dataFrameWP.length = sizeof(WINDOWPLACEMENT);
  61. m_dataFrameWP.showCmd = SW_HIDE;
  62. }
  63. CMainFrame::~CMainFrame()
  64. {
  65. }
  66. void CMainFrame::RecalcLayout(BOOL bNotify)
  67. {
  68. CExtNCW < CFrameWnd > :: RecalcLayout( bNotify );
  69. }
  70. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  71. {
  72. if( CExtNCW < CFrameWnd > :: OnCreate( lpCreateStruct ) == -1 )
  73. return -1;
  74. CCreateContext _cc;
  75. _cc.m_pCurrentDoc = NULL;
  76. _cc.m_pCurrentFrame = this;
  77. _cc.m_pLastView = NULL;
  78. _cc.m_pNewDocTemplate = NULL;
  79. _cc.m_pNewViewClass = RUNTIME_CLASS( CChildView );
  80. m_pWndView = (CChildView*)CreateView( &_cc );
  81. if( m_pWndView == NULL )
  82. {
  83. TRACE0("Failed to create view windown");
  84. return -1;
  85. }
  86. ASSERT_KINDOF( CChildView, m_pWndView );
  87. CChildView * pChildView =
  88. STATIC_DOWNCAST( CChildView, m_pWndView );
  89. SetActiveView( pChildView );
  90. m_pWndView->ModifyStyleEx( WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME, 0, SWP_FRAMECHANGED );
  91. CWinApp * pApp = ::AfxGetApp();
  92. ASSERT( pApp != NULL );
  93. ASSERT( pApp->m_pszRegistryKey != NULL );
  94. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  95. ASSERT( pApp->m_pszProfileName != NULL );
  96. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  97. ASSERT( pApp->m_pszProfileName != NULL );
  98. HICON hIcon = pApp->LoadIcon( IDR_MAINFRAME );
  99. ASSERT( hIcon != NULL );
  100. SetIcon( hIcon, TRUE );
  101. SetIcon( hIcon, FALSE );
  102. g_CmdManager->ProfileSetup(
  103. pApp->m_pszProfileName,
  104. GetSafeHwnd()
  105. );
  106. VERIFY(
  107. g_CmdManager->UpdateFromMenu(
  108. pApp->m_pszProfileName,
  109. IDR_MAINFRAME
  110. )
  111. );
  112. if( ! m_wndMenuBar.Create(
  113. NULL, // _T("Menu Bar"),
  114. this,
  115. ID_VIEW_MENUBAR,
  116. WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS
  117. |CBRS_TOP|CBRS_GRIPPER|CBRS_FLYBY|CBRS_SIZE_DYNAMIC
  118. )
  119. )
  120.     {
  121.         TRACE0("Failed to create menubarn");
  122.         return -1;      // failed to create
  123.     }
  124. if( (! m_wndToolBar.Create(
  125. _T("ToolBar"),
  126. this,
  127. AFX_IDW_TOOLBAR,
  128. WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS
  129. |CBRS_TOP|CBRS_GRIPPER|CBRS_FLYBY|CBRS_SIZE_DYNAMIC
  130. ) )
  131. || (! m_wndToolBar.LoadToolBar( IDR_MAINFRAME ) )
  132. )
  133. {
  134. TRACE0("Failed to create toolbarn");
  135. return -1;      // fail to create
  136. }
  137. if( (! m_wndToolBarUiLook.Create( NULL, this, ID_VIEW_UI_LOOK_BAR ) )
  138. || (! m_wndToolBarUiLook.ThemeSwitcherInit() )
  139. )
  140. {
  141. TRACE0("Failed to create toolbar2n");
  142. return -1;      // fail to create
  143. }
  144. UINT g_arrResetTextIDs[] =
  145. {
  146. ID_FILE_NEW, ID_FILE_OPEN, ID_FILE_SAVE,
  147. ID_FILE_SEND_MAIL,
  148. ID_EDIT_UNDO, ID_EDIT_COPY, ID_EDIT_CUT,
  149. ID_EDIT_PASTE
  150. };
  151. for( int i = 0; i < sizeof(g_arrResetTextIDs)/sizeof(g_arrResetTextIDs[0]); i++ )
  152. {
  153. CExtCmdItem * pCmdItem =
  154. g_CmdManager->CmdGetPtr(
  155. pApp->m_pszProfileName,
  156. g_arrResetTextIDs[i]
  157. );
  158. ASSERT( pCmdItem != NULL );
  159. pCmdItem->m_sToolbarText = pCmdItem->m_sMenuText;
  160. }
  161. m_wndStatusBar.m_bDrawPaneSeparatorsInsteadOfBorders = true;
  162. if( (! m_wndStatusBar.Create(this) )
  163. || (! m_wndStatusBar.SetIndicators(
  164. indicators,
  165. sizeof(indicators)/sizeof(UINT)) )
  166. )
  167. {
  168. TRACE0("Failed to create status barn");
  169. return -1;      // fail to create
  170. }
  171.     m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
  172. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  173. m_wndToolBarUiLook.EnableDocking(CBRS_ALIGN_ANY);
  174. if( ! CExtControlBar::FrameEnableDocking(this) )
  175. {
  176. ASSERT( FALSE );
  177. return -1;
  178. }
  179. g_CmdManager->SerializeState(
  180. pApp->m_pszProfileName,
  181. pApp->m_pszRegistryKey,
  182. pApp->m_pszProfileName,
  183. false
  184. );
  185. if( ! CExtControlBar::ProfileBarStateLoad(
  186. this,
  187. pApp->m_pszRegistryKey,
  188. pApp->m_pszProfileName,
  189. pApp->m_pszProfileName,
  190. &m_dataFrameWP
  191. )
  192. )
  193. {
  194. DockControlBar( &m_wndMenuBar );
  195. DockControlBar( &m_wndToolBar );
  196. DockControlBar( &m_wndToolBarUiLook, AFX_IDW_DOCKBAR_RIGHT );
  197. RecalcLayout();
  198. }
  199. return 0;
  200. }
  201. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  202. {
  203. if( ! CExtNCW < CFrameWnd > :: PreCreateWindow( cs ) )
  204. return FALSE;
  205. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  206. cs.lpszClass = AfxRegisterWndClass(0);
  207. return TRUE;
  208. }
  209. /////////////////////////////////////////////////////////////////////////////
  210. // CMainFrame diagnostics
  211. #ifdef _DEBUG
  212. void CMainFrame::AssertValid() const
  213. {
  214. CExtNCW < CFrameWnd > :: AssertValid();
  215. }
  216. void CMainFrame::Dump(CDumpContext& dc) const
  217. {
  218. CExtNCW < CFrameWnd > :: Dump( dc );
  219. }
  220. #endif //_DEBUG
  221. /////////////////////////////////////////////////////////////////////////////
  222. // CMainFrame message handlers
  223. void CMainFrame::OnSetFocus(CWnd* pOldWnd)
  224. {
  225. pOldWnd;
  226. if( m_pWndView->GetSafeHwnd() != NULL )
  227. m_pWndView->SetFocus();
  228. }
  229. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  230. {
  231. if( nCode == CN_COMMAND && pExtra == NULL )
  232. m_wndPopupRichEditView.Deactivate();
  233. if( m_pWndView->GetSafeHwnd() != NULL
  234. && m_pWndView->OnCmdMsg( nID, nCode, pExtra, pHandlerInfo )
  235. )
  236. return TRUE;
  237. return CExtNCW < CFrameWnd > :: OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
  238. }
  239. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
  240. {
  241. if( m_wndToolBarUiLook.PreTranslateMessage( pMsg ) )
  242. return TRUE;
  243. if( m_wndMenuBar.TranslateMainFrameMessage( pMsg ) )
  244. return TRUE;
  245. return CExtNCW < CFrameWnd > ::PreTranslateMessage( pMsg );
  246. }
  247. BOOL CMainFrame::DestroyWindow() 
  248. {
  249. CWinApp * pApp = ::AfxGetApp();
  250. ASSERT( pApp != NULL );
  251. ASSERT( pApp->m_pszRegistryKey != NULL );
  252. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  253. ASSERT( pApp->m_pszProfileName != NULL );
  254. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  255. VERIFY(
  256. CExtControlBar::ProfileBarStateSave(
  257. this,
  258. pApp->m_pszRegistryKey,
  259. pApp->m_pszProfileName,
  260. pApp->m_pszProfileName
  261. )
  262. );
  263. VERIFY(
  264. g_CmdManager->SerializeState(
  265. pApp->m_pszProfileName,
  266. pApp->m_pszRegistryKey,
  267. pApp->m_pszProfileName,
  268. true
  269. )
  270. );
  271. VERIFY(
  272. g_PaintManager.PaintManagerStateSave(
  273. pApp->m_pszRegistryKey,
  274. pApp->m_pszProfileName,
  275. pApp->m_pszProfileName
  276. )
  277. );
  278. g_CmdManager->ProfileWndRemove( GetSafeHwnd() );
  279. return CExtNCW < CFrameWnd > ::DestroyWindow();
  280. }
  281. void CMainFrame::ActivateFrame(int nCmdShow) 
  282. {
  283. // window placement persistence
  284. if( m_dataFrameWP.showCmd != SW_HIDE )
  285. {
  286. SetWindowPlacement( &m_dataFrameWP );
  287. CExtNCW < CFrameWnd > ::ActivateFrame( m_dataFrameWP.showCmd );
  288. m_dataFrameWP.showCmd = SW_HIDE;
  289. return;
  290. }
  291. CExtNCW < CFrameWnd > :: ActivateFrame( nCmdShow );
  292. }
  293. LRESULT CMainFrame::OnItemCoveringNotification( WPARAM wParam, LPARAM lParam )
  294. {
  295. lParam;
  296. CExtPopupMenuWnd::ITEMCOVERINGNOTIFICATON * pICN =
  297. CExtPopupMenuWnd::ITEMCOVERINGNOTIFICATON::
  298. FromWPARAM( wParam );
  299. ASSERT( pICN != NULL );
  300. pICN->m_bSuspendTips = false;
  301. if( pICN->m_eICN == CExtPopupMenuWnd::ITEMCOVERINGNOTIFICATON::__EICN_DELAY
  302. || pICN->m_eICN == CExtPopupMenuWnd::ITEMCOVERINGNOTIFICATON::__EICN_CANCEL
  303. )
  304. {
  305. m_wndPopupRichEditView.Deactivate();
  306. return 0;
  307. }
  308. pICN->m_bSuspendTips = true;
  309. ASSERT( pICN->m_eICN == CExtPopupMenuWnd::ITEMCOVERINGNOTIFICATON::__EICN_SET );
  310. CRect rcItem( 0, 0, 0, 0 );
  311. UINT nAlignType = AFX_IDW_DOCKBAR_RIGHT;
  312. UINT nCmdID = 0;
  313. if( pICN->m_pPopup != NULL )
  314. {
  315. ASSERT( pICN->m_pTBB == NULL );
  316. ASSERT_VALID( pICN->m_pPopup );
  317. CExtPopupMenuWnd::MENUITEMDATA & _mii =
  318. pICN->m_pPopup->ItemGetInfo(
  319. pICN->m_nPopupItemIndex
  320. );
  321. if( _mii.IsSeparator()
  322. || _mii.IsPopup()
  323. || CExtCmdManager::IsSystemCommand( _mii.GetCmdID() )
  324. )
  325. {
  326. m_wndPopupRichEditView.Deactivate();
  327. return 0;
  328. }
  329. pICN->m_pPopup->_GetItemRect(
  330. pICN->m_nPopupItemIndex,
  331. rcItem
  332. );
  333. pICN->m_pPopup->ClientToScreen( &rcItem );
  334. if( _mii.IsToolButton() )
  335. {
  336. CRect rcPopup;
  337. pICN->m_pPopup->GetWindowRect( &rcPopup );
  338. rcItem.left = rcPopup.left;
  339. rcItem.right = rcPopup.right;
  340. }
  341. nCmdID = _mii.GetCmdID();
  342. } // if( pICN->m_pPopup != NULL )
  343. else
  344. {
  345. ASSERT_VALID( pICN->m_pTBB );
  346. ASSERT_VALID( pICN->m_pTBB->GetBar() );
  347. if( pICN->m_pTBB->IsAbleToTrackMenu()
  348. || pICN->m_pTBB->IsSeparator()
  349. )
  350. {
  351. m_wndPopupRichEditView.Deactivate();
  352. return 0;
  353. }
  354. rcItem = pICN->m_pTBB->Rect();
  355. pICN->m_pTBB->GetBar()->ClientToScreen( &rcItem );
  356. nCmdID = pICN->m_pTBB->GetCmdID( false );
  357. if( pICN->m_pTBB->GetBar()->IsFloating() )
  358. nAlignType = AFX_IDW_DOCKBAR_BOTTOM;
  359. else
  360. {
  361. nAlignType = (UINT)
  362. pICN->m_pTBB->GetBar()->GetParent()->GetDlgCtrlID();
  363. switch( nAlignType )
  364. {
  365. case AFX_IDW_DOCKBAR_TOP:
  366. nAlignType = AFX_IDW_DOCKBAR_BOTTOM;
  367. break;
  368. case AFX_IDW_DOCKBAR_BOTTOM:
  369. nAlignType = AFX_IDW_DOCKBAR_TOP;
  370. break;
  371. case AFX_IDW_DOCKBAR_LEFT:
  372. nAlignType = AFX_IDW_DOCKBAR_RIGHT;
  373. break;
  374. case AFX_IDW_DOCKBAR_RIGHT:
  375. nAlignType = AFX_IDW_DOCKBAR_LEFT;
  376. break;
  377. #ifdef _DEBUG
  378. default:
  379. {
  380. ASSERT( FALSE );
  381. }
  382. break;
  383. #endif // _DEBUG
  384. } // switch( nAlignType )
  385. }
  386. } // else from if( pICN->m_pPopup != NULL )
  387. ScreenToClient( &rcItem );
  388. CExtResourceManager::CExtResourceMemoryBuffer buffer;
  389. if( ! g_ResourceManager->LoadResourceBuffer(
  390. buffer,
  391. _T("RTF"),
  392. nCmdID
  393. )
  394. )
  395. {
  396. return 0;
  397. }
  398. ASSERT_VALID( m_pWndView );
  399. m_wndPopupRichEditView.m_clrBackground =
  400. ( m_pWndView->m_checkCustomBkColor.GetCheck() != 0 )
  401. ? m_pWndView->m_buttonCustomBkColor.m_clrSelected
  402. : COLORREF(-1L)
  403. ;
  404. m_wndPopupRichEditView.m_clrBorderLT =
  405. ( m_pWndView->m_checkCustomBorderLtColor.GetCheck() != 0 )
  406. ? m_pWndView->m_buttonCustomBorderLtColor.m_clrSelected
  407. : COLORREF(-1L)
  408. ;
  409. m_wndPopupRichEditView.m_clrBorderRB =
  410. ( m_pWndView->m_checkCustomBorderRbColor.GetCheck() != 0 )
  411. ? m_pWndView->m_buttonCustomBorderRbColor.m_clrSelected
  412. : COLORREF(-1L)
  413. ;
  414. if( m_pWndView->m_radioShadow2.GetCheck() != 0 )
  415. m_wndPopupRichEditView.m_eST = CExtPopupRichEditView::__EST_POPUP;
  416. else if( m_pWndView->m_radioShadow3.GetCheck() != 0 )
  417. m_wndPopupRichEditView.m_eST = CExtPopupRichEditView::__EST_WINHELP;
  418. else
  419. m_wndPopupRichEditView.m_eST = CExtPopupRichEditView::__EST_NONE;
  420. m_wndPopupRichEditView.Activate(
  421. buffer,
  422. rcItem,
  423. m_hWnd,
  424. nAlignType,
  425. 8
  426. );
  427. return 0;
  428. }
  429. LRESULT CMainFrame::OnAnyDeactivatePopup( WPARAM wParam, LPARAM lParam )
  430. {
  431. wParam;
  432. lParam;
  433. m_wndPopupRichEditView.Deactivate();
  434. return 0;
  435. }