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

界面编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "ResizableChildSheet.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, CMDIFrameWnd )
  14. BEGIN_MESSAGE_MAP( CMainFrame, CMDIFrameWnd )
  15. //{{AFX_MSG_MAP(CMainFrame)
  16. ON_WM_CREATE()
  17. //}}AFX_MSG_MAP
  18. ON_COMMAND_EX(ID_VIEW_MENUBAR, OnBarCheck )
  19. ON_UPDATE_COMMAND_UI(ID_VIEW_MENUBAR, OnUpdateControlBarMenu)
  20. ON_COMMAND_EX(ID_VIEW_UI_LOOK_BAR, OnBarCheck )
  21. ON_UPDATE_COMMAND_UI(ID_VIEW_UI_LOOK_BAR, OnUpdateControlBarMenu)
  22. ON_COMMAND_EX(ID_VIEW_RESIZABLEBAR_PS1, OnBarCheck )
  23. ON_UPDATE_COMMAND_UI(ID_VIEW_RESIZABLEBAR_PS1, OnUpdateControlBarMenu)
  24. ON_COMMAND_EX(ID_VIEW_RESIZABLEBAR_PS2, OnBarCheck )
  25. ON_UPDATE_COMMAND_UI(ID_VIEW_RESIZABLEBAR_PS2, OnUpdateControlBarMenu)
  26. ON_COMMAND_EX(ID_VIEW_RESIZABLEBAR_PS3, OnBarCheck )
  27. ON_UPDATE_COMMAND_UI(ID_VIEW_RESIZABLEBAR_PS3, OnUpdateControlBarMenu)
  28. ON_COMMAND_EX(ID_VIEW_RESIZABLEBAR_PS4, OnBarCheck )
  29. ON_UPDATE_COMMAND_UI(ID_VIEW_RESIZABLEBAR_PS4, OnUpdateControlBarMenu)
  30. ON_REGISTERED_MESSAGE(
  31. CExtPopupMenuWnd::g_nMsgPrepareMenu,
  32. OnExtMenuPrepare
  33. )
  34. END_MESSAGE_MAP()
  35. static UINT indicators[] =
  36. {
  37. ID_SEPARATOR,           // status line indicator
  38. ID_INDICATOR_CAPS,
  39. ID_INDICATOR_NUM,
  40. ID_INDICATOR_SCRL,
  41. };
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CMainFrame construction/destruction
  44. CMainFrame::CMainFrame()
  45. {
  46. CExtControlBar::g_eResizablePanelDockingType =
  47. CExtControlBar::__RESIZABLE_DOCKING_TYPE_STUDIO_2005;
  48. ::memset( &m_dataFrameWP, 0, sizeof(WINDOWPLACEMENT) );
  49. m_dataFrameWP.showCmd = SW_HIDE;
  50. CWinApp * pApp = ::AfxGetApp();
  51. ASSERT( pApp != NULL );
  52. ASSERT( pApp->m_pszRegistryKey != NULL );
  53. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  54. ASSERT( pApp->m_pszProfileName != NULL );
  55. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  56. if( ! g_PaintManager.PaintManagerStateLoad(
  57. pApp->m_pszRegistryKey,
  58. pApp->m_pszProfileName,
  59. pApp->m_pszProfileName
  60. )
  61. )
  62. g_PaintManager.InstallPaintManager(
  63. RUNTIME_CLASS(CExtPaintManagerOffice2007_R2_LunaBlue)
  64. );
  65. }
  66. CMainFrame::~CMainFrame()
  67. {
  68. }
  69. void CMainFrame::OnUpdateControlBarMenu(CCmdUI* pCmdUI)
  70. {
  71. // CFrameWnd::OnUpdateControlBarMenu( pCmdUI );
  72. CExtControlBar::DoFrameBarCheckUpdate(
  73. this,
  74. pCmdUI,
  75. false
  76. );
  77. }
  78. BOOL CMainFrame::OnBarCheck(UINT nID)
  79. {
  80. // return CFrameWnd::OnBarCheck( nID );
  81. return
  82. CExtControlBar::DoFrameBarCheckCmd(
  83. this,
  84. nID,
  85. false
  86. );
  87. }
  88. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  89. {
  90. CWinApp * pApp = ::AfxGetApp();
  91. ASSERT( pApp != NULL );
  92. ASSERT( pApp->m_pszRegistryKey != NULL );
  93. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  94. ASSERT( pApp->m_pszProfileName != NULL );
  95. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  96. pApp;
  97. if( CExtNCW < CMDIFrameWnd > :: OnCreate(lpCreateStruct) == -1 )
  98. {
  99. ASSERT( FALSE );
  100. return -1;
  101. }
  102. VERIFY(
  103. g_CmdManager->ProfileWndAdd(
  104. __PROF_UIS_PROJECT_CMD_PROFILE_NAME,
  105. GetSafeHwnd()
  106. )
  107. );
  108. VERIFY(
  109. g_CmdManager->UpdateFromMenu(
  110. __PROF_UIS_PROJECT_CMD_PROFILE_NAME,
  111. IDR_MAINFRAME
  112. )
  113. );
  114. VERIFY(
  115. g_CmdManager->UpdateFromMenu(
  116. __PROF_UIS_PROJECT_CMD_PROFILE_NAME,
  117. IDR_MAINFRAME
  118. )
  119. );
  120. VERIFY(
  121. g_CmdManager->UpdateFromMenu(
  122. __PROF_UIS_PROJECT_CMD_PROFILE_NAME,
  123. IDR_CHILDSTYPE
  124. )
  125. );
  126. m_wndMenuBar.SetMdiWindowPopupName( _T("Window") );
  127. if( !m_wndMenuBar.Create( NULL, this, ID_VIEW_MENUBAR ) )
  128.     {
  129.         TRACE0("Failed to create menubarn");
  130.         return -1;      // failed to create
  131.     }
  132. if( (! m_wndToolBarUiLook.Create( NULL, this, ID_VIEW_UI_LOOK_BAR ) )
  133. || (! m_wndToolBarUiLook.ThemeSwitcherInit() )
  134. )
  135. {
  136. TRACE0("Failed to create toolbar2n");
  137. return -1;      // fail to create
  138. }
  139. if( !m_wndToolBar.Create( NULL, this, AFX_IDW_TOOLBAR )
  140. || !m_wndToolBar.LoadToolBar( IDR_MAINFRAME )
  141. )
  142. {
  143. TRACE0("Failed to create toolbarn");
  144. return -1;      // fail to create
  145. }
  146. if( !m_wndStatusBar.Create(this)
  147. || !m_wndStatusBar.SetIndicators( indicators, sizeof(indicators)/sizeof(UINT) )
  148. )
  149. {
  150. TRACE0("Failed to create status barn");
  151. return -1;      // fail to create
  152. }
  153. m_wndResizableBarPS1.SetInitDesiredSizeVertical( CSize(150,200) );
  154. m_wndResizableBarPS1.SetInitDesiredSizeHorizontal( CSize(200,150) );
  155. if( !m_wndResizableBarPS1.Create(
  156. NULL,
  157. this,
  158. ID_VIEW_RESIZABLEBAR_PS1
  159. )
  160. )
  161. {
  162. TRACE0("Failed to create m_wndResizableBarPS1n");
  163. return -1; // fail to create
  164. }
  165. m_wndDockedPS1.AddPage( &m_wndPage1_PS1 );
  166. m_wndDockedPS1.AddPage( &m_wndPage2_PS1 );
  167. m_wndDockedPS1.AddPage( &m_wndPage3_PS1 );
  168. if( !m_wndDockedPS1.Create(&m_wndResizableBarPS1) )
  169. {
  170. TRACE0("Failed to create m_wndResizableBarPS1 windown");
  171. return -1;
  172. }
  173. m_wndResizableBarPS2.SetInitDesiredSizeVertical( CSize(150,200) );
  174. m_wndResizableBarPS2.SetInitDesiredSizeHorizontal( CSize(200,150) );
  175. if( !m_wndResizableBarPS2.Create(
  176. NULL,
  177. this,
  178. ID_VIEW_RESIZABLEBAR_PS2
  179. )
  180. )
  181. {
  182. TRACE0("Failed to create m_wndResizableBarPS2n");
  183. return -1; // fail to create
  184. }
  185. m_wndDockedPS2.m_bInitTabSingleLine = true;
  186. m_wndDockedPS2.m_bInitTabButtons = true;
  187. m_wndDockedPS2.AddPage( &m_wndPage1_PS2 );
  188. m_wndDockedPS2.AddPage( &m_wndPage2_PS2 );
  189. m_wndDockedPS2.AddPage( &m_wndPage3_PS2 );
  190. if( !m_wndDockedPS2.Create(&m_wndResizableBarPS2) )
  191. {
  192. TRACE0("Failed to create m_wndResizableBarPS2 windown");
  193. return -1;
  194. }
  195. m_wndResizableBarPS3.SetInitDesiredSizeVertical( CSize(150,200) );
  196. m_wndResizableBarPS3.SetInitDesiredSizeHorizontal( CSize(200,150) );
  197. if( !m_wndResizableBarPS3.Create(
  198. NULL,
  199. this,
  200. ID_VIEW_RESIZABLEBAR_PS3
  201. )
  202. )
  203. {
  204. TRACE0("Failed to create m_wndResizableBarPS3n");
  205. return -1; // fail to create
  206. }
  207. m_wndDockedPS3.m_bInitTabSingleLine = true;
  208. m_wndDockedPS3.m_bInitTabButtons = true;
  209. m_wndDockedPS3.m_bInitTabButtonsFlat = true;
  210. m_wndDockedPS3.AddPage( &m_wndPage1_PS3 );
  211. m_wndDockedPS3.AddPage( &m_wndPage2_PS3 );
  212. m_wndDockedPS3.AddPage( &m_wndPage3_PS3 );
  213. if( !m_wndDockedPS3.Create(&m_wndResizableBarPS3) )
  214. {
  215. TRACE0("Failed to create m_wndResizableBarPS3 windown");
  216. return -1;
  217. }
  218. m_wndResizableBarPS4.SetInitDesiredSizeVertical( CSize(150,200) );
  219. m_wndResizableBarPS4.SetInitDesiredSizeHorizontal( CSize(200,150) );
  220. if( !m_wndResizableBarPS4.Create(
  221. NULL,
  222. this,
  223. ID_VIEW_RESIZABLEBAR_PS4
  224. )
  225. )
  226. {
  227. TRACE0("Failed to create m_wndResizableBarPS4n");
  228. return -1; // fail to create
  229. }
  230. m_wndDockedPS4.m_bInitTabSingleLine = true;
  231. m_wndDockedPS4.m_bInitTabButtons = true;
  232. m_wndDockedPS4.m_bInitTabButtonsFlat = true;
  233. m_wndDockedPS4.m_bInitTabSeparatorsFlat = true;
  234. m_wndDockedPS4.AddPage( &m_wndPage1_PS4 );
  235. m_wndDockedPS4.AddPage( &m_wndPage2_PS4 );
  236. m_wndDockedPS4.AddPage( &m_wndPage3_PS4 );
  237. if( !m_wndDockedPS4.Create(&m_wndResizableBarPS4) )
  238. {
  239. TRACE0("Failed to create m_wndResizableBarPS4 windown");
  240. return -1;
  241. }
  242. m_wndMenuBar.EnableDocking( CBRS_ALIGN_ANY );
  243. m_wndToolBarUiLook.EnableDocking(CBRS_ALIGN_ANY);
  244. m_wndToolBar.EnableDocking( CBRS_ALIGN_ANY );
  245. m_wndResizableBarPS1.EnableDocking( CBRS_ALIGN_ANY );
  246. m_wndResizableBarPS2.EnableDocking( CBRS_ALIGN_ANY );
  247. m_wndResizableBarPS3.EnableDocking( CBRS_ALIGN_ANY );
  248. m_wndResizableBarPS4.EnableDocking( CBRS_ALIGN_ANY );
  249. // Enable control bars in the frame window to be redocable
  250. if( !CExtControlBar::FrameEnableDocking(this) )
  251. {
  252. ASSERT( FALSE );
  253. return -1;
  254. }
  255. if( !CExtControlBar::ProfileBarStateLoad(
  256. this,
  257. pApp->m_pszRegistryKey,
  258. pApp->m_pszProfileName,
  259. pApp->m_pszProfileName,
  260. &m_dataFrameWP
  261. )
  262. )
  263. {
  264. DockControlBar( &m_wndMenuBar );
  265. DockControlBar(&m_wndToolBarUiLook,AFX_IDW_DOCKBAR_RIGHT);
  266. DockControlBar( &m_wndToolBar );
  267. m_wndResizableBarPS1.DockControlBar( AFX_IDW_DOCKBAR_RIGHT,  1, this, false );
  268. m_wndResizableBarPS2.DockControlBar( AFX_IDW_DOCKBAR_BOTTOM, 2, this, false );
  269. m_wndResizableBarPS3.DockControlBar( AFX_IDW_DOCKBAR_RIGHT,  3, this, false );
  270. m_wndResizableBarPS4.DockControlBar( AFX_IDW_DOCKBAR_BOTTOM, 4, this, false );
  271. }
  272. RecalcLayout();
  273. return 0;
  274. }
  275. BOOL CMainFrame::DestroyWindow() 
  276. {
  277. CWinApp * pApp = ::AfxGetApp();
  278. ASSERT( pApp != NULL );
  279. ASSERT( pApp->m_pszRegistryKey != NULL );
  280. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  281. ASSERT( pApp->m_pszProfileName != NULL );
  282. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  283. VERIFY(
  284. CExtControlBar::ProfileBarStateSave(
  285. this,
  286. pApp->m_pszRegistryKey,
  287. pApp->m_pszProfileName,
  288. pApp->m_pszProfileName,
  289. &m_dataFrameWP
  290. )
  291. );
  292. VERIFY(
  293. g_PaintManager.PaintManagerStateSave(
  294. pApp->m_pszRegistryKey,
  295. pApp->m_pszProfileName,
  296. pApp->m_pszProfileName
  297. )
  298. );
  299. g_CmdManager->ProfileWndRemove( GetSafeHwnd() );
  300. return CExtNCW < CMDIFrameWnd > :: DestroyWindow();
  301. }
  302. void CMainFrame::ActivateFrame(int nCmdShow) 
  303. {
  304. if( m_dataFrameWP.showCmd != SW_HIDE )
  305. {
  306. SetWindowPlacement( &m_dataFrameWP );
  307. CExtNCW < CMDIFrameWnd > :: ActivateFrame( m_dataFrameWP.showCmd );
  308. m_dataFrameWP.showCmd = SW_HIDE;
  309. return;
  310. }
  311. CExtNCW < CMDIFrameWnd > :: ActivateFrame(nCmdShow);
  312. }
  313. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  314. {
  315. if( ! CExtNCW < CMDIFrameWnd > :: PreCreateWindow(cs) )
  316. return FALSE;
  317. return TRUE;
  318. }
  319. /////////////////////////////////////////////////////////////////////////////
  320. // CMainFrame diagnostics
  321. #ifdef _DEBUG
  322. void CMainFrame::AssertValid() const
  323. {
  324. CExtNCW < CMDIFrameWnd > :: AssertValid();
  325. }
  326. void CMainFrame::Dump(CDumpContext& dc) const
  327. {
  328. CExtNCW < CMDIFrameWnd > :: Dump(dc);
  329. }
  330. #endif //_DEBUG
  331. /////////////////////////////////////////////////////////////////////////////
  332. // CMainFrame message handlers
  333. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
  334. {
  335. if( m_wndToolBarUiLook.PreTranslateMessage( pMsg ) )
  336. return TRUE;
  337. if( m_wndMenuBar.TranslateMainFrameMessage(pMsg) )
  338. return TRUE;
  339. return CExtNCW < CMDIFrameWnd > :: PreTranslateMessage(pMsg);
  340. }
  341. LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
  342. {
  343. wParam;
  344. lParam;
  345. //////////////////////////////////////////////////////////////////////////
  346. // Add "Windows..." command
  347. //////////////////////////////////////////////////////////////////////////
  348. CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
  349. reinterpret_cast
  350. < CExtPopupMenuWnd::MsgPrepareMenuData_t * >
  351. ( wParam );
  352. ASSERT( pData != NULL );
  353. CExtPopupMenuWnd * pPopup = pData->m_pPopup;
  354. ASSERT( pPopup != NULL );
  355. INT nItemPos;
  356. INT nNewPos = -1;
  357. nItemPos = pPopup->ItemFindPosForCmdID( __ID_MDIWND_DLGWINDOWS );
  358. if( nItemPos > 0 )
  359. {
  360. // "More Windows..." command found
  361. pPopup->ItemRemove( nItemPos );
  362. nNewPos = nItemPos;
  363. }
  364. else
  365. {
  366. int nMaxCmdID = 0;
  367. for( int nCmdID = __ID_MDIWNDLIST_FIRST; nCmdID <= __ID_MDIWNDLIST_LAST; nCmdID++ ){
  368. nItemPos = pPopup->ItemFindPosForCmdID( nCmdID );
  369. if( nItemPos > 0 ){
  370. if( nCmdID > nMaxCmdID ){
  371. nMaxCmdID = nCmdID;
  372. nNewPos = nItemPos;
  373. }
  374. }
  375. }
  376. if( nNewPos > 0 ){
  377. pPopup->ItemInsert(
  378. (UINT)CExtPopupMenuWnd::TYPE_SEPARATOR,
  379. ++nNewPos
  380. );
  381. nNewPos++;
  382. }
  383. }
  384. if( nNewPos > 0 )
  385. {
  386. UINT nCmdID = ID_WINDOWS_LIST;
  387. CExtCmdItem * pCmdItem =
  388. g_CmdManager->CmdGetPtr(
  389. g_CmdManager->ProfileNameFromWnd( this->GetSafeHwnd() ),
  390. nCmdID
  391. );
  392. if( pCmdItem == NULL ){
  393. pCmdItem = 
  394. g_CmdManager->CmdAllocPtr( 
  395. g_CmdManager->ProfileNameFromWnd( this->GetSafeHwnd() ), 
  396. nCmdID 
  397. );
  398. }
  399. ASSERT( pCmdItem != NULL );
  400. if( pCmdItem != NULL )
  401. {
  402. CExtSafeString sMoreWindows(_T("Windows..."));
  403. CExtSafeString sManageWindows(_T("Manages the currently open windows"));
  404. pCmdItem->m_sMenuText = sMoreWindows;
  405. pCmdItem->m_sToolbarText = pCmdItem->m_sMenuText;
  406. pCmdItem->m_sTipTool = sManageWindows;
  407. pCmdItem->m_sTipStatus = pCmdItem->m_sTipTool;
  408. pCmdItem->StateSetBasic( true );
  409. pPopup->ItemInsert(
  410. nCmdID,
  411. nNewPos,
  412. sMoreWindows,
  413. NULL,
  414. m_hWnd
  415. );
  416. }
  417. }
  418. return 1;
  419. }
  420. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
  421. {
  422. if( nCode == CN_COMMAND )
  423. {
  424. if( nID == ID_WINDOWS_LIST )
  425. {
  426. CMyMdiWindowsListDlg dlgMdiWindowsList( this );
  427. dlgMdiWindowsList.DoModal();
  428. return TRUE;
  429. }
  430. }
  431. return CExtNCW < CMDIFrameWnd > :: OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  432. }