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

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "CommandBarControls.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, CXTPMDIFrameWnd)
  14. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  15. //{{AFX_MSG_MAP(CMainFrame)
  16. ON_WM_CREATE()
  17. //}}AFX_MSG_MAP
  18. ON_COMMAND_RANGE(ID_VIEW_THEME_OFFICE2000, ID_VIEW_THEME_RIBBON, OnViewTheme)
  19. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  20. ON_XTP_CREATECONTROL()
  21. END_MESSAGE_MAP()
  22. static UINT indicators[] =
  23. {
  24. ID_SEPARATOR,           // status line indicator
  25. ID_INDICATOR_CAPS,
  26. ID_INDICATOR_NUM,
  27. ID_INDICATOR_SCRL,
  28. };
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame construction/destruction
  31. CMainFrame::CMainFrame()
  32. {
  33. // TODO: add member initialization code here
  34. }
  35. CMainFrame::~CMainFrame()
  36. {
  37. }
  38. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  39. {
  40. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  41. return -1;
  42. if (!m_wndStatusBar.Create(this) ||
  43. !m_wndStatusBar.SetIndicators(indicators,
  44. sizeof(indicators)/sizeof(UINT)))
  45. {
  46. TRACE0("Failed to create status barn");
  47. return -1;      // fail to create
  48. }
  49. // Initialize the command bars
  50. if (!InitCommandBars())
  51. return -1;
  52. // Get a pointer to the command bars object.
  53. CXTPCommandBars* pCommandBars = GetCommandBars();
  54. if(pCommandBars == NULL)
  55. {
  56. TRACE0("Failed to create command bars object.n");
  57. return -1;      // fail to create
  58. }
  59. pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME);
  60. pCommandBars->GetImageManager()->SetIcons(IDR_TOOLBAR_COLOR);
  61. // Set Office 2003 Theme
  62. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  63. // Add the menu bar
  64. CXTPMenuBar* pMenuBar = pCommandBars->SetMenu(
  65. _T("Menu Bar"), IDR_MAINFRAME);
  66. if(pMenuBar == NULL)
  67. {
  68. TRACE0("Failed to create menu bar.n");
  69. return -1;      // fail to create
  70. }
  71. CXTPToolBar* pToolBarButtons = (CXTPToolBar*) pCommandBars->Add(_T("Buttons"), xtpBarTop);
  72. pToolBarButtons->SetBarID(IDR_MAINFRAME);
  73. pToolBarButtons->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlButton:"));
  74. pToolBarButtons->GetControls()->Add(xtpControlButton, ID_FILE_OPEN);
  75. pToolBarButtons->GetControls()->Add(xtpControlButton, ID_FILE_SAVE)->SetStyle(xtpButtonCaption);
  76. pToolBarButtons->GetControls()->Add(xtpControlButton, ID_FILE_PRINT)->SetStyle(xtpButtonIconAndCaption);
  77. CXTPToolBar* pToolBarPopups = pCommandBars->Add(_T("Popups"), xtpBarTop);
  78. pToolBarPopups->SetBarID(IDR_MAINFRAME + 2);
  79. pToolBarPopups->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlPopup:"));
  80. pToolBarPopups->GetControls()->Add(xtpControlPopup, ID_EDIT_PASTE);
  81. pToolBarPopups->GetControls()->Add(xtpControlPopup, ID_EDIT_COPY)->SetStyle(xtpButtonIcon);
  82. pToolBarPopups->GetControls()->Add(xtpControlButtonPopup, ID_EDIT_CUT)->SetStyle(xtpButtonIconAndCaption);
  83. pToolBarPopups->GetControls()->Add(xtpControlSplitButtonPopup, ID_EDIT_SELECT_ALL)->SetStyle(xtpButtonIconAndCaption);
  84. DockRightOf(pToolBarPopups, pToolBarButtons);
  85. CXTPToolBar* pToolBarCombo = pCommandBars->Add(_T("Combo"), xtpBarTop);
  86. pToolBarCombo->SetBarID(IDR_MAINFRAME + 3);
  87. pToolBarCombo->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlComboBox:"));
  88. pToolBarCombo->GetControls()->Add(xtpControlComboBox, ID_FILE_NEW);
  89. CXTPControlComboBox* pControlCombo = (CXTPControlComboBox*)pToolBarCombo->GetControls()->Add(xtpControlComboBox, ID_FILE_NEW);
  90. pControlCombo->SetDropDownListStyle();
  91. DockRightOf(pToolBarCombo, pToolBarPopups);
  92. CXTPToolBar* pToolBarEdit = pCommandBars->Add(_T("Edit"), xtpBarTop);
  93. pToolBarEdit->SetBarID(IDR_MAINFRAME + 4);
  94. pToolBarEdit->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlEdit:"));
  95. CXTPControlEdit* pControlEdit = (CXTPControlEdit*)pToolBarEdit->GetControls()->Add(xtpControlEdit, ID_FILE_NEW);
  96. pControlEdit->ShowSpinButtons(TRUE);
  97. CXTPToolBar* pToolBarRadio = pCommandBars->Add(_T("Radio"), xtpBarTop);
  98. pToolBarRadio->SetBarID(IDR_MAINFRAME + 5);
  99. pToolBarRadio->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlRadioButton:"));
  100. pToolBarRadio->GetControls()->Add(xtpControlRadioButton, 0);
  101. DockRightOf(pToolBarRadio, pToolBarEdit);
  102. CXTPToolBar* pToolBarCheckBox = pCommandBars->Add(_T("CheckBox"), xtpBarTop);
  103. pToolBarCheckBox->SetBarID(IDR_MAINFRAME + 7);
  104. pToolBarCheckBox->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlCheckBox:"));
  105. pToolBarCheckBox->GetControls()->Add(xtpControlCheckBox, 0);
  106. DockRightOf(pToolBarCheckBox, pToolBarRadio);
  107. CXTPToolBar* pToolBarListBox = pCommandBars->Add(_T("ListBox"), xtpBarTop);
  108. pToolBarListBox->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlListBox:"));
  109. CXTPControlPopup* pPopup = (CXTPControlPopup*)pToolBarListBox->GetControls()->Add(xtpControlPopup, 0);
  110. pPopup->SetCaption(_T("ListBox"));
  111. CXTPControlListBox* pListBox = (CXTPControlListBox*)pPopup->GetCommandBar()->GetControls()->Add(new CXTPControlListBox, 0);
  112. pListBox->GetListCtrl()->AddString(_T("Item 1"));
  113. pListBox->GetListCtrl()->AddString(_T("Item 2"));
  114. CXTPToolBar* pToolBarGallery = pCommandBars->Add(_T("Gallery"), xtpBarTop);
  115. pToolBarGallery->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlGallery:"));
  116. CXTPControlGalleryItems* pGalleryItems = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_CONTROL_GALLERY);
  117. CXTPControlGallery* pControlGallery = (CXTPControlGallery*)pToolBarGallery->GetControls()->Add(new CXTPControlGallery(), ID_CONTROL_GALLERY);
  118. pGalleryItems->AddItem(_T("Item 1"));
  119. pGalleryItems->AddItem(_T("Item 2"));
  120. pGalleryItems->AddItem(_T("Item 3"));
  121. pGalleryItems->AddItem(_T("Item 4"));
  122. pGalleryItems->AddItem(_T("Item 5"));
  123. pGalleryItems->SetItemSize(CSize(40, 22));
  124. pControlGallery->SetHeight(22);
  125. pControlGallery->SetWidth(140);
  126. pControlGallery->SetItems(pGalleryItems);
  127. pControlGallery->SetFlags(xtpFlagManualUpdate);
  128. DockRightOf(pToolBarGallery, pToolBarListBox);
  129. CXTPToolBar* pToolBarColor = pCommandBars->Add(_T("ColorButton"), xtpBarTop);
  130. pToolBarColor->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlColorSelector:"));
  131. CXTPControlPopupColor* pControlButtonColor = (CXTPControlPopupColor*)
  132. pToolBarColor->GetControls()->Add(new CXTPControlPopupColor(), ID_COLOR_FORE);
  133. pControlButtonColor->SetColor(0xFF);
  134. CXTPPopupToolBar* pPopupToolBar = CXTPPopupToolBar::CreatePopupToolBar(pCommandBars);
  135. pControlButtonColor->SetCommandBar(pPopupToolBar);
  136. pPopupToolBar->GetControls()->Add(new CXTPControlColorSelector());
  137. pPopupToolBar->InternalRelease();
  138. pControlButtonColor->SetFlags(xtpFlagManualUpdate);
  139. DockRightOf(pToolBarColor, pToolBarGallery);
  140. CXTPToolBar* pToolBarSlider = pCommandBars->Add(_T("Slider"), xtpBarTop);
  141. pToolBarSlider->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlSlider:"));
  142. pToolBarSlider->GetControls()->Add(new CXTPControlSlider());
  143. CXTPToolBar* pToolBarScrollBar = pCommandBars->Add(_T("ScrollBar"), xtpBarTop);
  144. pToolBarScrollBar->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlScrollBar:"));
  145. pToolBarScrollBar->GetControls()->Add(new CXTPControlScrollBar());
  146. DockRightOf(pToolBarScrollBar, pToolBarSlider);
  147. CXTPToolBar* pToolBarProgress = pCommandBars->Add(_T("Progress"), xtpBarTop);
  148. pToolBarProgress->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlProgress:"));
  149. CXTPControlProgress* pProgressControl = new CXTPControlProgress();
  150. pToolBarProgress->GetControls()->Add(pProgressControl);
  151. pProgressControl->SetPos(30);
  152. DockRightOf(pToolBarProgress, pToolBarScrollBar);
  153. CXTPToolBar* pWorkspaceBar = (CXTPToolBar*)
  154. pCommandBars->Add(_T("WorkspaceBar"), xtpBarTop);
  155. if (!pWorkspaceBar)
  156. {
  157. TRACE0("Failed to create toolbarn");
  158. return -1;
  159. }
  160. pWorkspaceBar->EnableCustomization(FALSE);
  161. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
  162. pWorkspaceBar->GetControls()->Add(xtpControlLabel, 0)->SetCaption(_T("CXTPControlTabWorkspace:"));
  163. CXTPControlTabWorkspace* pControl = (CXTPControlTabWorkspace*)pWorkspaceBar->GetControls()->Add(new CXTPControlTabWorkspace());
  164. m_wndClient.Attach(this);
  165. m_wndClient.SetTabWorkspace(pControl);
  166. pControl->GetPaintManager()->m_bFillBackground = FALSE;
  167. //pControl->GetPaintManager()->GetAppearanceSet()->m_rcHeaderMargin.top = 1;
  168. pControl->GetPaintManager()->SetLayout(xtpTabLayoutSizeToFit);
  169. pControl->SetWidth(400);
  170. pControl->SetFlags(pControl->GetFlags() | xtpFlagControlStretched);
  171. pWorkspaceBar->EnableDocking(xtpFlagAlignAny | xtpFlagFloating | xtpFlagStretched);
  172. m_wndClient.SetFlags(xtpWorkspaceHideAll);
  173. pWorkspaceBar->SetBarID(IDR_MAINFRAME + 1);
  174. pWorkspaceBar->GetControls()->CreateOriginalControls();
  175. return 0;
  176. }
  177. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  178. {
  179. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  180. return FALSE;
  181. cs.lpszClass = _T("XTPMainFrame");
  182. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  183. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  184. return TRUE;
  185. }
  186. /////////////////////////////////////////////////////////////////////////////
  187. // CMainFrame diagnostics
  188. #ifdef _DEBUG
  189. void CMainFrame::AssertValid() const
  190. {
  191. CMDIFrameWnd::AssertValid();
  192. }
  193. void CMainFrame::Dump(CDumpContext& dc) const
  194. {
  195. CMDIFrameWnd::Dump(dc);
  196. }
  197. #endif //_DEBUG
  198. /////////////////////////////////////////////////////////////////////////////
  199. // CMainFrame message handlers
  200. void CMainFrame::OnCustomize()
  201. {
  202. CXTPCustomizeSheet cs(GetCommandBars());
  203. CXTPCustomizeKeyboardPage pageKeyboard(&cs);
  204. cs.AddPage(&pageKeyboard);
  205. pageKeyboard.AddCategories(IDR_COMMANTYPE);
  206. CXTPCustomizeMenusPage pageMenus(&cs);
  207. cs.AddPage(&pageMenus);
  208. CXTPCustomizeOptionsPage pageOptions(&cs);
  209. cs.AddPage(&pageOptions);
  210. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  211. pCommands->AddCategories(IDR_COMMANTYPE);
  212. pCommands->InsertAllCommandsCategory();
  213. pCommands->InsertBuiltInMenus(IDR_COMMANTYPE);
  214. pCommands->InsertNewMenuCategory();
  215. cs.DoModal();
  216. }
  217. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  218. {
  219. UNREFERENCED_PARAMETER(lpCreateControl);
  220. return FALSE;
  221. }
  222. void CMainFrame::OnViewTheme(UINT nID) 
  223. {
  224. XTPPaintManager()->SetTheme(XTPPaintTheme(nID - ID_VIEW_THEME_OFFICE2000));
  225. GetCommandBars()->RedrawCommandBars();
  226. }