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

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "SkinMDISample.h"
  5. #include "SkinPropertySheet.h"
  6. #include "MainFrm.h"
  7. #include "DialogsView.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_DYNAMIC(CMainFrame, CMDIFrameWnd)
  16. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  18. ON_WM_CREATE()
  19. ON_WM_CLOSE()
  20. ON_COMMAND(ID_VIEW_THEME_DIALOG, OnViewThemeDialog)
  21. ON_COMMAND(ID_VIEW_THEME, OnViewTheme)
  22. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME, OnUpdateViewTheme)
  23. //}}AFX_MSG_MAP
  24. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  25. ON_XTP_CREATECONTROL()
  26. ON_COMMAND_RANGE(ID_THEME_OFFICE2000, ID_THEME_WINXP, OnViewThemePopup)
  27. ON_UPDATE_COMMAND_UI_RANGE(ID_THEME_OFFICE2000, ID_THEME_WINXP, OnUpdateViewTheme)
  28. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify) 
  29. END_MESSAGE_MAP()
  30. static UINT indicators[] =
  31. {
  32. ID_SEPARATOR,           // status line indicator
  33. ID_INDICATOR_CAPS,
  34. ID_INDICATOR_NUM,
  35. ID_INDICATOR_SCRL,
  36. };
  37. CString CMainFrame::GetStylesPath()
  38. {
  39. TCHAR szStylesPath[_MAX_PATH];
  40. VERIFY(::GetModuleFileName(
  41. AfxGetApp()->m_hInstance, szStylesPath, _MAX_PATH));
  42. CString csStylesPath(szStylesPath);
  43. int nIndex  = csStylesPath.ReverseFind(_T('\'));
  44. if (nIndex > 0) {
  45. csStylesPath = csStylesPath.Left(nIndex);
  46. }
  47. else {
  48. csStylesPath.Empty();
  49. }
  50. return csStylesPath + _T("\Styles\");
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMainFrame construction/destruction
  54. CMainFrame::CMainFrame()
  55. {
  56. OnShemaChanged(3);
  57. }
  58. CMainFrame::~CMainFrame()
  59. {
  60. }
  61. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  62. {
  63. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  64. return -1;
  65. if (!m_wndStatusBar.Create(this) ||
  66. !m_wndStatusBar.SetIndicators(indicators,
  67. sizeof(indicators)/sizeof(UINT)))
  68. {
  69. TRACE0("Failed to create status barn");
  70. return -1;      // fail to create
  71. }
  72. if (!InitCommandBars())
  73. return -1;
  74. CXTPCommandBars* pCommandBars = GetCommandBars();
  75. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  76. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  77. if (!pStandardBar ||
  78. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  79. {
  80. TRACE0("Failed to create toolbarn");
  81. }
  82. pCommandBars->GetToolTipContext()->SetStyle(xtpToolTipOffice);
  83. // Load the previous state for command bars.
  84. //LoadCommandBars(_T("CommandBars"));
  85. m_paneManager.InstallDockingPanes(this);
  86. // Create docking panes.
  87. m_paneManager.CreatePane(
  88. IDD_PANE_DIALOGS, CRect(0, 0,120, 120), xtpPaneDockRight);
  89. SetTheme(xtpThemeNativeWinXP);
  90. ShowThemesDialog();
  91. m_MTIClientWnd.Attach(this);
  92. return 0;
  93. }
  94. void CMainFrame::ShowThemesDialog()
  95. {
  96. if (!::IsWindow(m_dlgThemes.GetSafeHwnd()))
  97. {
  98. m_dlgThemes.Create(this);
  99. m_dlgThemes.CenterWindow(this);
  100. }
  101. else
  102. {
  103. m_dlgThemes.SetFocus();
  104. }
  105. m_dlgThemes.ShowWindow(SW_SHOW);
  106. }
  107. void CMainFrame::OnClose() 
  108. {
  109.     // Save the current state for toolbars and menus.
  110.     SaveCommandBars(_T("CommandBars"));
  111.     CMDIFrameWnd::OnClose();
  112. }
  113. void CMainFrame::OnCustomize()
  114. {
  115.     // Get a pointer to the command bars object.
  116.     CXTPCommandBars* pCommandBars = GetCommandBars();
  117.     if(pCommandBars != NULL)
  118.     {
  119.         // Instantiate the customize dialog object.
  120.         CXTPCustomizeSheet dlg(pCommandBars);
  121.         // Add the options page to the customize dialog.
  122.         CXTPCustomizeOptionsPage pageOptions(&dlg);
  123.         dlg.AddPage(&pageOptions);
  124.         // Add the commands page to the customize dialog.
  125.         CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();
  126.         pCommands->AddCategories(IDR_SKINMDTYPE);
  127.         // Use the command bar manager to initialize the 
  128.         // customize dialog.
  129.         pCommands->InsertAllCommandsCategory();
  130.         pCommands->InsertBuiltInMenus(IDR_SKINMDTYPE);
  131.         pCommands->InsertNewMenuCategory();
  132.         // Display the dialog.
  133.         dlg.DoModal();
  134.     }
  135. }
  136. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  137. {
  138. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  139. return FALSE;
  140. cs.lpszClass = _T("XTPMainFrame");
  141. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  142. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  143. return TRUE;
  144. }
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CMainFrame diagnostics
  147. #ifdef _DEBUG
  148. void CMainFrame::AssertValid() const
  149. {
  150. CMDIFrameWnd::AssertValid();
  151. }
  152. void CMainFrame::Dump(CDumpContext& dc) const
  153. {
  154. CMDIFrameWnd::Dump(dc);
  155. }
  156. #endif //_DEBUG
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CMainFrame message handlers
  159. void CMainFrame::RedrawFrame(CWnd* pWnd)
  160. {
  161. pWnd->RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  162. }
  163. void CMainFrame::OnSkinChanged()
  164. {
  165. if (m_nTheme == xtpThemeOffice2003)
  166. {
  167. if (XTPSkinManager()->GetResourceFile() &&
  168. XTPSkinManager()->GetResourceFile()->GetResourcePath().Find(_T("Office2007")) > 0)
  169. {
  170. XTPPaintManager()->SetTheme(xtpThemeOffice2007);
  171. }
  172. else
  173. {
  174. XTPPaintManager()->SetTheme(xtpThemeOffice2003);
  175. }
  176. }
  177. XTPPaintManager()->RefreshMetrics();
  178. RedrawFrame(this);
  179. if (::IsWindow(m_dlgThemes.m_hWnd))
  180. RedrawFrame(&m_dlgThemes);
  181. m_wndStatusBar.Invalidate();
  182. CWnd* pWnd = CWnd::FromHandle(m_hWndMDIClient)->GetWindow(GW_CHILD);
  183. while(pWnd)
  184. {
  185. RedrawFrame(pWnd);
  186. pWnd = pWnd->GetWindow(GW_HWNDNEXT);
  187. }
  188. GetCommandBars()->GetPaintManager()->RefreshMetrics();
  189. GetCommandBars()->RedrawCommandBars();
  190. }
  191. void CMainFrame::OnShemaChanged(int nSchema)
  192. {
  193. switch (nSchema)
  194. {
  195. case 0:
  196. XTPSkinManager()->LoadSkin(GetStylesPath() + _T("Office2007.cjstyles"));
  197. break;
  198. case 1:
  199. XTPSkinManager()->LoadSkin(GetStylesPath() + _T("WinXP.Luna.cjstyles"), _T("NormalBlue.INI"));
  200. break;
  201. case 2:
  202. XTPSkinManager()->LoadSkin(GetStylesPath() + _T("WinXP.Royale.cjstyles"), _T("NormalRoyale.INI"));
  203. break;
  204. case 3:
  205. XTPSkinManager()->LoadSkin(GetStylesPath() + _T("Vista.cjstyles"), _T("NormalBlack2.INI"));
  206. break;
  207. default:
  208. XTPSkinManager()->LoadSkin(_T(""), _T(""));
  209. }
  210. if (m_hWnd) OnSkinChanged();
  211. }
  212. void CMainFrame::OnViewThemeDialog() 
  213. {
  214. ShowThemesDialog();
  215. }
  216. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  217. {
  218. // Toggle CommandBars
  219. GetCommandBars()->OnSetPreviewMode(bPreview);
  220. // Toggle Tab Client
  221. m_MTIClientWnd.ShowWorkspace(!bPreview);
  222. CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
  223. }
  224.  
  225. void CMainFrame::OnViewTheme() 
  226. {
  227. SetTheme((m_nTheme + 1) % 4);
  228. }
  229. void CMainFrame::OnUpdateViewTheme(CCmdUI* pCmdUI) 
  230. {
  231. pCmdUI->Enable();
  232. pCmdUI->SetCheck((int)pCmdUI->m_nID == m_nTheme + ID_THEME_OFFICE2000 ? TRUE : FALSE);
  233. }
  234. void CMainFrame::OnViewThemePopup(UINT nCommand)
  235. {
  236. SetTheme(nCommand - ID_THEME_OFFICE2000);
  237. }
  238. void CMainFrame::SetTheme(int nTheme)
  239. {
  240. m_nTheme = nTheme;
  241. if (m_nTheme == xtpThemeOffice2003)
  242. {
  243. if (XTPSkinManager()->GetResourceFile() &&
  244. XTPSkinManager()->GetResourceFile()->GetResourcePath().Find(_T("Office2007")) > 0)
  245. {
  246. nTheme = xtpThemeOffice2007;
  247. }
  248. }
  249. CXTPPaintManager::SetTheme((XTPPaintTheme)nTheme);
  250. XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
  251. XTPPaintManager()->GetIconsInfo()->bIconsWithShadow = FALSE;
  252. m_paneManager.SetTheme((XTPDockingPanePaintTheme)nTheme);
  253. GetCommandBars()->RedrawCommandBars();
  254. m_MTIClientWnd.GetPaintManager()->RefreshMetrics();
  255. RedrawWindow( NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
  256. }
  257. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  258. {
  259. if (lpCreateControl->nID == ID_VIEW_THEME)
  260. {
  261. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  262. lpCreateControl->buttonStyle = xtpButtonIconAndCaption;
  263. return TRUE;
  264. }
  265. return FALSE;
  266. }
  267. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  268. {
  269. if (wParam == XTP_DPN_SHOWWINDOW)
  270. {
  271. // get a pointer to the docking pane being shown.
  272. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  273. if (!pPane->IsValid())
  274. {
  275. pPane->AttachView(this, RUNTIME_CLASS(CDialogsView));
  276. }
  277. return TRUE; // handled
  278. }
  279. return FALSE;
  280. }
  281.