MainFrm.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:5k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "ActionsSample.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. #define ID_MENUPOPUP_FILE 2000
  12. #define ID_MENUPOPUP_ABOUT 2003
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMainFrame
  15. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  16. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  18. // NOTE - the ClassWizard will add and remove mapping macros here.
  19. //    DO NOT EDIT what you see in these blocks of generated code !
  20. ON_WM_CREATE()
  21. ON_WM_CLOSE()
  22. //}}AFX_MSG_MAP
  23. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  24. ON_UPDATE_COMMAND_UI_RANGE(ID_MENUPOPUP_FILE, ID_MENUPOPUP_ABOUT, OnUpdatePopupMenu)
  25. END_MESSAGE_MAP()
  26. static UINT indicators[] =
  27. {
  28. ID_SEPARATOR,           // status line indicator
  29. ID_INDICATOR_CAPS,
  30. ID_INDICATOR_NUM,
  31. ID_INDICATOR_SCRL,
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMainFrame construction/destruction
  35. CMainFrame::CMainFrame()
  36. {
  37. // TODO: add member initialization code here
  38. }
  39. CMainFrame::~CMainFrame()
  40. {
  41. }
  42. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  43. {
  44. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  45. return -1;
  46. if (!m_wndStatusBar.Create(this) ||
  47. !m_wndStatusBar.SetIndicators(indicators,
  48.   sizeof(indicators)/sizeof(UINT)))
  49. {
  50. TRACE0("Failed to create status barn");
  51. return -1;      // fail to create
  52. }
  53. // Initialize the command bars
  54. if (!InitCommandBars())
  55. return -1;
  56. // Get a pointer to the command bars object.
  57. CXTPCommandBars* pCommandBars = GetCommandBars();
  58. if(pCommandBars == NULL)
  59. {
  60. TRACE0("Failed to create command bars object.n");
  61. return -1;      // fail to create
  62. }
  63. EnableActions();
  64. // Add the menu bar
  65. CXTPToolBar* pMenuBar = pCommandBars->SetMenu(
  66. _T("Menu Bar"), IDR_MAINFRAME);
  67. if(pMenuBar == NULL)
  68. {
  69. TRACE0("Failed to create menu bar.n");
  70. return -1;      // fail to create
  71. }
  72. // Create ToolBar
  73. CXTPToolBar* pToolBar = (CXTPToolBar*)
  74. pCommandBars->Add(_T("Standard"), xtpBarTop);
  75. if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
  76. {
  77. TRACE0("Failed to create toolbarn");
  78. return -1;
  79. }
  80. pToolBar->EnableAnimation();
  81. CXTPDialogBar* pBar = (CXTPDialogBar*)pCommandBars->Add(_T("Actions"), xtpBarRight, RUNTIME_CLASS(CXTPDialogBar));
  82. pBar->SetBarID(200);
  83. pBar->EnableDocking(xtpFlagAlignAny|xtpFlagFloating|xtpFlagStretched);
  84. pBar->ModifyStyle(0, WS_CLIPCHILDREN|WS_CLIPSIBLINGS);
  85. m_wndActions.Create(CDialogActions::IDD, pBar);
  86. m_wndActions.ShowWindow(SW_SHOW);
  87. pBar->SetChild(&m_wndActions);
  88. pCommandBars->SetTheme(xtpThemeWhidbey);
  89. LoadCommandBars(_T("CommandBars"));
  90. return 0;
  91. }
  92. void CMainFrame::EnableActions()
  93. {
  94. CXTPCommandBars* pCommandBars = GetCommandBars();
  95. pCommandBars->EnableActions();
  96. // Optional:
  97. // Add standard actions, if you going to localize them.
  98. pCommandBars->GetActions()->Add(XTP_ID_CUSTOMIZE);
  99. pCommandBars->GetActions()->Add(XTP_ID_CUSTOMIZE_RESET);
  100. pCommandBars->GetActions()->Add(XTP_ID_CUSTOMIZE_ADDORREMOVE);
  101. pCommandBars->GetActions()->Add(XTP_ID_TOOLBAR_EXPAND);
  102. pCommandBars->GetActions()->Add(XTP_ID_TOOLBAR_HIDE);
  103. }
  104. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  105. {
  106. if( !CFrameWnd::PreCreateWindow(cs) )
  107. return FALSE;
  108. cs.lpszClass = _T("XTPMainFrame");
  109. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  110. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  111. return TRUE;
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CMainFrame diagnostics
  115. #ifdef _DEBUG
  116. void CMainFrame::AssertValid() const
  117. {
  118. CFrameWnd::AssertValid();
  119. }
  120. void CMainFrame::Dump(CDumpContext& dc) const
  121. {
  122. CFrameWnd::Dump(dc);
  123. }
  124. #endif //_DEBUG
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CMainFrame message handlers
  127. void CMainFrame::OnCustomize()
  128. {
  129. // Get a pointer to the command bars object.
  130. CXTPCommandBars* pCommandBars = GetCommandBars();
  131. if (pCommandBars == NULL)
  132. return;
  133. // Instantiate the customize dialog.
  134. CXTPCustomizeSheet dlg(pCommandBars);
  135. // Add the options page to the customize dialog.
  136. CXTPCustomizeOptionsPage pageOptions(&dlg);
  137. dlg.AddPage(&pageOptions);
  138. // Add the commands page to the customize dialog.
  139. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  140. pPageCommands->AddCategories(IDR_MAINFRAME, TRUE);
  141. // Initialize the commands page page.
  142. pPageCommands->InsertAllCommandsCategory();
  143. pPageCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  144. pPageCommands->InsertNewMenuCategory();
  145. // Display the customize dialog.
  146. dlg.DoModal();
  147. }
  148. void CMainFrame::OnClose()
  149. {
  150. SaveCommandBars(_T("CommandBars"));
  151. CXTPFrameWnd::OnClose();
  152. }
  153. void CMainFrame::OnUpdatePopupMenu(CCmdUI* pCmdUI)
  154. {
  155. pCmdUI->Enable(1);
  156. }