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

对话框与窗口

开发平台:

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 "CommandBarIcons.h"
  22. #include "MainFrm.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CMainFrame
  30. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  31. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  32. //{{AFX_MSG_MAP(CMainFrame)
  33. ON_WM_CREATE()
  34. ON_WM_CLOSE()
  35. //}}AFX_MSG_MAP
  36. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  37. ON_COMMAND(ID_PROJECT_ADDFILES, OnEmptyCommand)
  38. ON_COMMAND(ID_PROJECT_IMPORTFILES, OnEmptyCommand)
  39. ON_COMMAND(ID_PROJECT_EXPORTFILES, OnEmptyCommand)
  40. ON_COMMAND(ID_PROJECT_UPDATEALL, OnEmptyCommand)
  41. ON_COMMAND(ID_PROJECT_IMPORTFILES, OnEmptyCommand)
  42. ON_COMMAND(ID_PROJECT_BUILD, OnEmptyCommand)
  43. ON_COMMAND(ID_PROJECT_BUILDALL, OnEmptyCommand)
  44. ON_COMMAND(ID_PROJECT_CHECK, OnEmptyCommand)
  45. ON_COMMAND(ID_BUTTON_ADD, OnEmptyCommand)
  46. ON_COMMAND(ID_BUTTON_DELETE, OnEmptyCommand)
  47. ON_COMMAND(ID_FILE_NEW_ARCHIVE, OnEmptyCommand)
  48. ON_COMMAND(ID_FILE_OPEN_ARCHIVE, OnEmptyCommand)
  49. ON_COMMAND(ID_FILE_FAVORITES, OnEmptyCommand)
  50. ON_COMMAND(ID_FILE_CLOSE_ARCHIVE, OnEmptyCommand)
  51. ON_COMMAND(ID_FILE_WIZARD, OnEmptyCommand)
  52. ON_COMMAND(ID_FILE_PROPERTIES, OnEmptyCommand)
  53. ON_COMMAND(ID_THEME_OFFICE2000, OnSwitchOffice2000)
  54. ON_COMMAND(ID_THEME_OFFICEXP, OnSwitchOfficeXP)
  55. ON_COMMAND(ID_THEME_OFFICE2003, OnSwitchOffice2003)
  56. ON_COMMAND(ID_THEME_NATIVEXP, OnSwitchNativeXP)
  57. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2000, OnUpdateSwitchOffice2000)
  58. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICEXP, OnUpdateSwitchOfficeXP)
  59. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2003, OnUpdateSwitchOffice2003)
  60. ON_UPDATE_COMMAND_UI(ID_THEME_NATIVEXP, OnUpdateSwitchNativeXP)
  61. ON_COMMAND(ID_PROPERTIES, OnProperties)
  62. ON_UPDATE_COMMAND_UI(ID_PROPERTIES, OnUpdateProperties)
  63. ON_XTP_CREATECONTROL()
  64. END_MESSAGE_MAP()
  65. static UINT indicators[] =
  66. {
  67. ID_SEPARATOR,           // status line indicator
  68. ID_INDICATOR_CAPS,
  69. ID_INDICATOR_NUM,
  70. ID_INDICATOR_SCRL,
  71. };
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CMainFrame construction/destruction
  74. CMainFrame::CMainFrame()
  75. {
  76. // TODO: add member initialization code here
  77. }
  78. CMainFrame::~CMainFrame()
  79. {
  80. }
  81. void CMainFrame::OnEmptyCommand()
  82. {
  83. }
  84. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  85. {
  86. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  87. return -1;
  88. if (!m_wndStatusBar.Create(this) ||
  89. !m_wndStatusBar.SetIndicators(indicators,
  90. sizeof(indicators)/sizeof(UINT)))
  91. {
  92. TRACE0("Failed to create status barn");
  93. return -1;      // fail to create
  94. }
  95. if (!InitCommandBars())
  96. return -1;
  97. CXTPPaintManager::SetTheme(xtpThemeNativeWinXP);
  98. //CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  99. XTP_COMMANDBARS_ICONSINFO* pIconsInfo = XTPPaintManager()->GetIconsInfo();
  100. pIconsInfo->bUseDisabledIcons = TRUE;
  101. pIconsInfo->bIconsWithShadow = FALSE;
  102. CXTPCommandBars* pCommandBars = GetCommandBars();
  103. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  104. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  105. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  106. if (!pStandardBar ||
  107. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  108. {
  109. TRACE0("Failed to create toolbarn");
  110. return -1;
  111. }
  112. CXTPToolBar* pThemesBar = (CXTPToolBar*)pCommandBars->Add(_T("Themes Bar"), xtpBarTop);
  113. if (!pThemesBar ||
  114. !pThemesBar->LoadToolBar(IDR_TOOLBAR_THEMES))
  115. {
  116. TRACE0("Failed to create toolbarn");
  117. return -1;
  118. }
  119. XTPImageManager()->SetIcons(IDR_MENU_ICONS);
  120. XTPImageManager()->SetIcons(IDR_MAINFRAME_LARGE);
  121. m_wndProperties.Create(IDD_DIALOG_PROPERTIES, this);
  122. m_wndProperties.CenterWindow(this);
  123. m_wndProperties.ShowWindow(SW_SHOW);
  124. // Load the previous state for command bars.
  125. LoadCommandBars(_T("CommandBars"));
  126. CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();
  127. pOptions->szLargeIcons = CSize (24, 24);
  128. pOptions->bLargeIcons = FALSE;
  129. return 0;
  130. }
  131. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  132. {
  133. if( !CFrameWnd::PreCreateWindow(cs) )
  134. return FALSE;
  135. cs.lpszClass = _T("XTPMainFrame");
  136. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  137. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  138. return TRUE;
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CMainFrame diagnostics
  142. #ifdef _DEBUG
  143. void CMainFrame::AssertValid() const
  144. {
  145. CFrameWnd::AssertValid();
  146. }
  147. void CMainFrame::Dump(CDumpContext& dc) const
  148. {
  149. CFrameWnd::Dump(dc);
  150. }
  151. #endif //_DEBUG
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CMainFrame message handlers.
  154. void CMainFrame::OnProperties()
  155. {
  156. if (m_wndProperties.GetSafeHwnd() && m_wndProperties.IsWindowVisible())
  157. {
  158. m_wndProperties.ShowWindow(SW_HIDE);
  159. else
  160. {
  161. if (!m_wndProperties.GetSafeHwnd())
  162. {
  163. m_wndProperties.Create(IDD_DIALOG_PROPERTIES, this);
  164. m_wndProperties.UpdateAll();
  165. }
  166. m_wndProperties.ShowWindow(SW_SHOW);
  167. }
  168. }
  169. void CMainFrame::OnUpdateProperties(CCmdUI* pCmdUI)
  170. {
  171. pCmdUI->SetCheck(m_wndProperties.GetSafeHwnd() && m_wndProperties.IsWindowVisible());
  172. }
  173. void CMainFrame::SwitchTheme(XTPPaintTheme paintTheme)
  174. {
  175. CXTPPaintManager::SetTheme(paintTheme);
  176. XTP_COMMANDBARS_ICONSINFO* pIconsInfo = XTPPaintManager()->GetIconsInfo();
  177. pIconsInfo->bUseDisabledIcons = TRUE;
  178. RecalcLayout(FALSE);
  179. GetCommandBars()->RedrawCommandBars();
  180. RedrawWindow();
  181. if (m_wndProperties.GetSafeHwnd() && m_wndProperties.IsWindowVisible())
  182. {
  183. m_wndProperties.UpdateAll();
  184. }
  185. }
  186. void CMainFrame::OnSwitchOffice2000()
  187. {
  188. SwitchTheme(xtpThemeOffice2000);
  189. }
  190. void CMainFrame::OnSwitchOfficeXP()
  191. {
  192. SwitchTheme(xtpThemeOfficeXP);
  193. }
  194. void CMainFrame::OnSwitchOffice2003()
  195. {
  196. SwitchTheme(xtpThemeOffice2003);
  197. }
  198. void CMainFrame::OnSwitchNativeXP()
  199. {
  200. SwitchTheme(xtpThemeNativeWinXP);
  201. }
  202. void CMainFrame::OnUpdateSwitchOffice2000(CCmdUI* pCmdUI)
  203. {
  204. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2000);
  205. }
  206. void CMainFrame::OnUpdateSwitchOfficeXP(CCmdUI* pCmdUI)
  207. {
  208. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOfficeXP);
  209. }
  210. void CMainFrame::OnUpdateSwitchOffice2003(CCmdUI* pCmdUI)
  211. {
  212. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003);
  213. }
  214. void CMainFrame::OnUpdateSwitchNativeXP(CCmdUI* pCmdUI)
  215. {
  216. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeNativeWinXP);
  217. }
  218. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  219. {
  220. if (lpCreateControl->bToolBar && lpCreateControl->nID >= ID_THEME_OFFICE2000 && lpCreateControl->nID <= ID_THEME_NATIVEXP)
  221. {
  222. CXTPControlButton* pButton = (CXTPControlButton*)CXTPControlButton::CreateObject();
  223. lpCreateControl->pControl = pButton;
  224. pButton->SetID(lpCreateControl->nID);
  225. pButton->SetStyle(xtpButtonCaption);
  226. return TRUE;
  227. }
  228. if (lpCreateControl->bToolBar &&
  229. (lpCreateControl->nID == ID_PROPERTIES || lpCreateControl->nID == ID_BUTTON_ADD || lpCreateControl->nID == ID_BUTTON_DELETE))
  230. {
  231. CXTPControlButton* pButton = (CXTPControlButton*)CXTPControlButton::CreateObject();
  232. lpCreateControl->pControl = pButton;
  233. pButton->SetID(lpCreateControl->nID);
  234. pButton->SetStyle(xtpButtonIconAndCaption);
  235. return TRUE;
  236. }
  237. return FALSE;
  238. }
  239. void CMainFrame::OnClose()
  240. {
  241. // Save the current state for command bars.
  242. SaveCommandBars(_T("CommandBars"));
  243. CFrameWnd::OnClose();
  244. }
  245. void CMainFrame::OnCustomize()
  246. {
  247. // Get a pointer to the command bars object.
  248. CXTPCommandBars* pCommandBars = GetCommandBars();
  249. if (pCommandBars == NULL)
  250. return;
  251. // Instantiate the customize dialog.
  252. CXTPCustomizeSheet dlg(pCommandBars);
  253. // Add the options page to the customize dialog.
  254. CXTPCustomizeOptionsPage pageOptions(&dlg);
  255. dlg.AddPage(&pageOptions);
  256. // Add the commands page to the customize dialog.
  257. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  258. pPageCommands->AddCategories(IDR_MAINFRAME);
  259. // Initialize the commands page page.
  260. pPageCommands->InsertAllCommandsCategory();
  261. pPageCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  262. pPageCommands->InsertNewMenuCategory();
  263. // Display the customize dialog.
  264. dlg.DoModal();
  265. }