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

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "ReBarSample.h"
  22. #include "MainFrm.h"
  23. #include "ExplorerTheme.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame
  31. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  32. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  33. //{{AFX_MSG_MAP(CMainFrame)
  34. ON_WM_CREATE()
  35. ON_WM_CLOSE()
  36. ON_COMMAND(ID_THEME_OFFICE, OnThemeOffice)
  37. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE, OnUpdateThemeOffice)
  38. ON_COMMAND(ID_THEME_STANDARD, OnThemeStandard)
  39. ON_UPDATE_COMMAND_UI(ID_THEME_STANDARD, OnUpdateThemeStandard)
  40. ON_WM_DESTROY()
  41. //}}AFX_MSG_MAP
  42. ON_COMMAND_RANGE(ID_WEBBROWSER_STOP, ID_WEBBROWSER_NEXT, OnEmptyCommandRange)
  43. ON_XTP_CREATECONTROL()
  44. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  45. END_MESSAGE_MAP()
  46. static UINT indicators[] =
  47. {
  48. ID_SEPARATOR,           // status line indicator
  49. ID_INDICATOR_CAPS,
  50. ID_INDICATOR_NUM,
  51. ID_INDICATOR_SCRL,
  52. };
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CMainFrame construction/destruction
  55. CMainFrame::CMainFrame()
  56. {
  57. }
  58. CMainFrame::~CMainFrame()
  59. {
  60. }
  61. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  62. {
  63. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  64. return -1;
  65. if (!InitCommandBars(/*RUNTIME_CLASS(CReBarCommandBars)*/))
  66. return -1;
  67. CXTPCommandBars* pCommandBars = GetCommandBars();
  68. CXTPToolBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME); ;
  69. if (!pMenuBar)
  70. {
  71. TRACE0("Failed to create toolbarn");
  72. return -1;      // fail to create
  73. }
  74. CXTPToolBar* pToolBar = pCommandBars->Add(_T("Standard"), xtpBarTop);
  75. if (!pToolBar ||
  76. !pToolBar->LoadToolBar(IDR_MAINFRAME))
  77. {
  78. TRACE0("Failed to create toolbarn");
  79. return -1;      // fail to create
  80. }
  81. CXTPToolBar* pWebBar = pCommandBars->Add(_T("Web"), xtpBarTop);
  82. if (!pWebBar ||
  83. !pWebBar->LoadToolBar(IDR_TOOLBAR_WEB))
  84. {
  85. TRACE0("Failed to create toolbarn");
  86. return -1;      // fail to create
  87. }
  88. CXTPToolBar* pThemeBar = pCommandBars->Add(_T("Theme"), xtpBarTop);
  89. if (!pThemeBar ||
  90. !pThemeBar->LoadToolBar(IDR_TOOLBAR_THEME))
  91. {
  92. TRACE0("Failed to create toolbarn");
  93. return -1;      // fail to create
  94. }
  95. ///
  96. if (!m_wndReBar.Create(this) ||
  97. !m_wndReBar.AddToolBar(pMenuBar) ||
  98. !m_wndReBar.AddToolBar(pToolBar, RBBS_GRIPPERALWAYS|RBBS_BREAK) ||
  99. !m_wndReBar.AddToolBar(pThemeBar) ||
  100. !m_wndReBar.AddToolBar(pWebBar)
  101. )
  102. {
  103. TRACE0("Failed to create rebarn");
  104. return -1;      // fail to create
  105. }
  106. pMenuBar->SetFlags(xtpFlagAddMDISysPopup);
  107. if (!m_wndStatusBar.Create(this) ||
  108. !m_wndStatusBar.SetIndicators(indicators,
  109. sizeof(indicators)/sizeof(UINT)))
  110. {
  111. TRACE0("Failed to create status barn");
  112. return -1;      // fail to create
  113. }
  114. CXTPToolBar* pWorkspaceBar = (CXTPToolBar*)
  115. pCommandBars->Add(_T("WorkspaceBar"), xtpBarTop);
  116. if (!pWorkspaceBar)
  117. {
  118. TRACE0("Failed to create toolbarn");
  119. return -1;
  120. }
  121. pWorkspaceBar->ShowExpandButton(FALSE);
  122. pWorkspaceBar->EnableDocking(xtpFlagStretched);
  123. pWorkspaceBar->EnableCustomization(FALSE);
  124. m_wndReBar.AddToolBar(pWorkspaceBar, RBBS_BREAK);
  125. m_wndClient.Attach(this);
  126. m_wndClient.SetAutoTheme(FALSE);
  127. m_wndClient.SetPaintManager(new CExplorerTabPaintManager());
  128. m_wndClient.SetFlags(xtpWorkspaceShowCloseSelectedTab | xtpWorkspaceHideClose | xtpWorkspaceHideArrows);
  129. CXTPControlTabWorkspace* pControl = (CXTPControlTabWorkspace*)pWorkspaceBar->GetControls()->Add(new CXTPControlTabWorkspace());
  130. pControl->SetFlags(xtpFlagControlStretched);
  131. m_wndClient.SetTabWorkspace(pControl);
  132. LoadCommandBars(_T("CommandBars3"));
  133. m_wndReBar.LoadState( _T("RebarState3") );
  134. OnThemeStandard();
  135. return 0;
  136. }
  137. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  138. {
  139. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  140. return FALSE;
  141. cs.lpszClass = _T("XTPMainFrame");
  142. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  143. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  144. return TRUE;
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CMainFrame diagnostics
  148. #ifdef _DEBUG
  149. void CMainFrame::AssertValid() const
  150. {
  151. CMDIFrameWnd::AssertValid();
  152. }
  153. void CMainFrame::Dump(CDumpContext& dc) const
  154. {
  155. CMDIFrameWnd::Dump(dc);
  156. }
  157. #endif //_DEBUG
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CMainFrame message handlers
  160. void CMainFrame::OnEmptyCommandRange(UINT)
  161. {
  162. }
  163. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  164. {
  165. if (lpCreateControl->bToolBar)
  166. {
  167. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  168. if (!pToolBar)
  169. return FALSE;
  170. if (lpCreateControl->nID == ID_GOTO_URL && pToolBar->GetBarID() == IDR_TOOLBAR_WEB)
  171. {
  172. CXTPControlComboBox* pComboUrl = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  173. pComboUrl->AddString(_T("http://www.codejock.com"));
  174. pComboUrl->AddString(_T("ms-help://MS.VSCC/vsccCommon/html/vsccCommon_Start_Page.htm"));
  175. pComboUrl->SetWidth(200);
  176. pComboUrl->SetDropDownWidth(300);
  177. pComboUrl->SetDropDownListStyle();
  178. pComboUrl->SetFlags(xtpFlagManualUpdate);
  179. pComboUrl->SetEditText(_T("http://www.codejock.com"));
  180. lpCreateControl->pControl = pComboUrl;
  181. return TRUE;
  182. }
  183. }
  184. return FALSE;
  185. }
  186. void CMainFrame::OnClose()
  187. {
  188. SaveCommandBars(_T("CommandBars3"));
  189. m_wndReBar.SaveState( _T("RebarState3") );
  190. CMDIFrameWnd::OnClose();
  191. }
  192. void CMainFrame::OnCustomize()
  193. {
  194. CXTPCustomizeSheet cs(GetCommandBars());
  195. CXTPCustomizeOptionsPage pageOptions(&cs);
  196. cs.AddPage(&pageOptions);
  197. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  198. pCommands->AddCategories(IDR_REBARSTYPE, TRUE);
  199. pCommands->InsertAllCommandsCategory();
  200. pCommands->InsertBuiltInMenus(IDR_REBARSTYPE);
  201. pCommands->InsertNewMenuCategory();
  202. cs.DoModal();
  203. }
  204. void CMainFrame::OnThemeOffice()
  205. {
  206. m_bOfficeXP = TRUE;
  207. CXTPPaintManager::SetCustomTheme(new CXTPReBarPaintManager<CXTPOfficeTheme>());
  208. GetCommandBars()->RedrawCommandBars();
  209. }
  210. void CMainFrame::OnUpdateThemeOffice(CCmdUI* pCmdUI)
  211. {
  212. pCmdUI->SetCheck(m_bOfficeXP);
  213. }
  214. void CMainFrame::OnThemeStandard()
  215. {
  216. m_bOfficeXP = FALSE;
  217. CXTPPaintManager::SetCustomTheme(new CXTPReBarPaintManager<CXTPNativeXPTheme>());
  218. XTPPaintManager()->m_bSelectImageInPopupBar = TRUE;
  219. XTPPaintManager()->m_bThickCheckMark = TRUE;
  220. GetCommandBars()->RedrawCommandBars();
  221. }
  222. void CMainFrame::OnUpdateThemeStandard(CCmdUI* pCmdUI)
  223. {
  224. pCmdUI->SetCheck(!m_bOfficeXP);
  225. }
  226. void CMainFrame::OnDestroy()
  227. {
  228. CMDIFrameWnd::OnDestroy();
  229. }