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

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "SkinSDISample.h"
  5. #include "MainFrm.h"
  6. #include "SkinManagerExtResourceFile.h"
  7. #include "SampleView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  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. END_MESSAGE_MAP()
  25. static UINT indicators[] =
  26. {
  27. ID_SEPARATOR,           // status line indicator
  28. ID_INDICATOR_CAPS,
  29. ID_INDICATOR_NUM,
  30. ID_INDICATOR_SCRL,
  31. };
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMainFrame construction/destruction
  34. CMainFrame::CMainFrame()
  35. {
  36. TCHAR szStylesPath[_MAX_PATH];
  37. VERIFY(::GetModuleFileName(
  38. AfxGetApp()->m_hInstance, szStylesPath, _MAX_PATH));
  39. CString csStylesPath(szStylesPath);
  40. int nIndex  = csStylesPath.ReverseFind(_T('\'));
  41. if (nIndex > 0) {
  42. csStylesPath = csStylesPath.Left(nIndex);
  43. }
  44. else {
  45. csStylesPath.Empty();
  46. }
  47. m_strStylesPath = csStylesPath + _T("\Styles\");
  48. XTPSkinManager()->SetApplyOptions(xtpSkinApplyFrame | xtpSkinApplyColors | xtpSkinApplyMetrics);
  49. LoadSkin(0);
  50. }
  51. CMainFrame::~CMainFrame()
  52. {
  53. }
  54. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  55. {
  56. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  57. return -1;
  58. // Create Status bar.
  59. // Important: All control bars including the Status Bar
  60. // must be created before CommandBars....
  61. if (!m_wndStatusBar.Create(this) ||
  62. !m_wndStatusBar.SetIndicators(indicators,
  63. sizeof(indicators)/sizeof(UINT)))
  64. {
  65. TRACE0("Failed to create status barn");
  66. return -1;      // fail to create
  67. }
  68. // Initialize the command bars
  69. if (!InitCommandBars())
  70. return -1;
  71. XTPPaintManager()->SetTheme(xtpThemeNativeWinXP);
  72. XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
  73. // Get a pointer to the command bars object.
  74. CXTPCommandBars* pCommandBars = GetCommandBars();
  75. if(pCommandBars == NULL)
  76. {
  77. TRACE0("Failed to create command bars object.n");
  78. return -1;      // fail to create
  79. }
  80. // Add the menu bar
  81. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
  82. _T("Menu Bar"), IDR_MAINFRAME);
  83. if(pMenuBar == NULL)
  84. {
  85. TRACE0("Failed to create menu bar.n");
  86. return -1;      // fail to create
  87. }
  88. // Create ToolBar
  89. CXTPToolBar* pToolBar = (CXTPToolBar*)
  90. pCommandBars->Add(_T("Standard"), xtpBarTop);
  91. if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
  92. {
  93. TRACE0("Failed to create toolbarn");
  94. return -1;
  95. }
  96. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
  97. // Load the previous state for toolbars and menus.
  98. LoadCommandBars(_T("CommandBars"));
  99. PostMessage(WM_SYSCOLORCHANGE);
  100. return 0;
  101. }
  102. void CMainFrame::OnClose()
  103. {
  104. // Save the current state for toolbars and menus.
  105. SaveCommandBars(_T("CommandBars"));
  106. CFrameWnd::OnClose();
  107. }
  108. void CMainFrame::OnCustomize()
  109. {
  110. // Get a pointer to the command bars object.
  111. CXTPCommandBars* pCommandBars = GetCommandBars();
  112. if(pCommandBars != NULL)
  113. {
  114. // Instanciate the customize dialog object.
  115. CXTPCustomizeSheet dlg(pCommandBars);
  116. // Add the keyboard page to the customize dialog.
  117. CXTPCustomizeKeyboardPage pageKeyboard(&dlg);
  118. dlg.AddPage(&pageKeyboard);
  119. pageKeyboard.AddCategories(IDR_MAINFRAME);
  120. // Add the options page to the customize dialog.
  121. CXTPCustomizeOptionsPage pageOptions(&dlg);
  122. dlg.AddPage(&pageOptions);
  123. // Add the commands page to the customize dialog.
  124. CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();
  125. pCommands->AddCategories(IDR_MAINFRAME);
  126. // Use the command bar manager to initialize the
  127. // customize dialog.
  128. pCommands->InsertAllCommandsCategory();
  129. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  130. pCommands->InsertNewMenuCategory();
  131. // Dispaly the dialog.
  132. dlg.DoModal();
  133. }
  134. }
  135. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  136. {
  137. if( !CFrameWnd::PreCreateWindow(cs) )
  138. return FALSE;
  139. cs.lpszClass = _T("XTPMainFrame");
  140. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  141. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  142. return TRUE;
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CMainFrame diagnostics
  146. #ifdef _DEBUG
  147. void CMainFrame::AssertValid() const
  148. {
  149. CFrameWnd::AssertValid();
  150. }
  151. void CMainFrame::Dump(CDumpContext& dc) const
  152. {
  153. CFrameWnd::Dump(dc);
  154. }
  155. #endif //_DEBUG
  156. /////////////////////////////////////////////////////////////////////////////
  157. // CMainFrame message handlers
  158. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext) 
  159. {
  160. m_wndSplitter.CreateStatic(this, 1, 2);
  161. m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSampleView), CSize(220, 200), NULL);
  162. m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, CSize(0, 0), pContext);
  163. return TRUE;
  164. }
  165. void CMainFrame::OnSkinChanged()
  166. {
  167. XTPPaintManager()->RefreshMetrics();
  168. OnSysColorChange();
  169. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  170. GetCommandBars()->GetPaintManager()->RefreshMetrics();
  171. GetCommandBars()->RedrawCommandBars();
  172. }
  173. void CMainFrame::LoadSkin(int nSkin)
  174. {
  175. switch (nSkin)
  176. {
  177. case 1:
  178. XTPSkinManager()->LoadSkin(m_strStylesPath + _T("iTunes"), _T("Normalitunes.INI"));
  179. break;
  180. case 0:
  181. XTPSkinManager()->LoadSkin(m_strStylesPath + _T("Le5"), _T("NormalBlue.INI"));
  182. break;
  183. default:
  184. XTPSkinManager()->LoadSkin(_T(""), _T(""));
  185. }
  186. if (m_hWnd) OnSkinChanged();
  187. }
  188. void CMainFrame::SetTheme(int nTheme, BOOL bFlat)
  189. {
  190. switch (nTheme)
  191. {
  192. case 0:
  193. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  194. break;
  195. case 1:
  196. CXTPPaintManager::SetTheme(xtpThemeNativeWinXP);
  197. break;
  198. }
  199. XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
  200. if (bFlat)
  201. {
  202. XTPPaintManager()->m_bFlatMenuBar = TRUE;
  203. XTPPaintManager()->m_bFlatToolBar = TRUE;
  204. }
  205. GetCommandBars()->RedrawCommandBars();
  206. RedrawWindow( NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);  
  207. }