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

对话框与窗口

开发平台:

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 "Advanced.h"
  22. #include "MainFrm.h"
  23. #include "PopoutFrame.h"
  24. #include "HeroesView.h"
  25. #include "DockingFrame.h"
  26. #include "AdvancedDialog.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMainFrame
  34. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  35. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  36. //{{AFX_MSG_MAP(CMainFrame)
  37. ON_WM_CREATE()
  38. ON_COMMAND(ID_WINDOW_NEWPOPOUT, OnWindowNewpopout)
  39. ON_UPDATE_COMMAND_UI(ID_WINDOW_NEWPOPOUT, OnUpdateWindowNewpopout)
  40. ON_WM_CLOSE()
  41. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  42. ON_COMMAND(ID_WINDOW_DIALOG, OnWindowDialog)
  43. //}}AFX_MSG_MAP
  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. m_pHeroesView = 0;
  58. m_pNewFrameWnd = 0;
  59. m_pDockingFrame = 0;
  60. }
  61. CMainFrame::~CMainFrame()
  62. {
  63. if (m_pHeroesView)
  64. delete m_pHeroesView;
  65. }
  66. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  67. {
  68. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  69. return -1;
  70. if (!m_wndStatusBar.Create(this) ||
  71. !m_wndStatusBar.SetIndicators(indicators,
  72. sizeof(indicators)/sizeof(UINT)))
  73. {
  74. TRACE0("Failed to create status barn");
  75. return -1;      // fail to create
  76. }
  77. if (!InitCommandBars())
  78. return -1;
  79. XTPImageManager()->SetMaskColor(CXTPImageManager::GetBitmapMaskColor(IDR_MAINFRAME));
  80. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  81. CXTPCommandBars* pCommandBars = GetCommandBars();
  82. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_ADVANCTYPE);
  83. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  84. CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  85. if (!pCommandBar ||
  86. !pCommandBar->LoadToolBar(IDR_MAINFRAME))
  87. {
  88. TRACE0("Failed to create toolbarn");
  89. return -1;
  90. }
  91. ((CXTPControlButton*)(pCommandBar->GetControls()->FindControl(ID_WINDOW_DIALOG)))->SetStyle(xtpButtonCaption);
  92. ((CXTPControlButton*)(pCommandBar->GetControls()->FindControl(ID_WINDOW_NEWPOPOUT)))->SetStyle(xtpButtonCaption);
  93. GetDockingPaneManager()->InstallDockingPanes(this);
  94. GetDockingPaneManager()->SetTheme(xtpPaneThemeOffice);
  95. CXTPDockingPane* pwndPaneFrame = GetDockingPaneManager()->CreatePane(
  96. 2, CRect(0, 0,200, 120), xtpPaneDockRight);
  97. pwndPaneFrame->SetTitle(_T("Docking FramenFrame"));
  98. CXTPDockingPane* pwndPaneEdit = GetDockingPaneManager()->CreatePane(
  99. 3, CRect(0, 0,200, 120), xtpPaneDockBottom);
  100. pwndPaneEdit->SetTitle(_T("Edit ControlnEdit"));
  101. CXTPDockingPane* pwndPaneHeroes = GetDockingPaneManager()->CreatePane(
  102. 1, CRect(0, 0,200, 120), xtpPaneDockLeft);
  103. pwndPaneHeroes->SetTitle(_T("Super HeroesnHeroes"));
  104. const int nIDTabs[] = {1, 2, 3};
  105. GetDockingPaneManager()->SetIcons(IDB_BITMAP_ICONS, nIDTabs, 3);
  106. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  107. // Load the previous state for command bars.
  108. LoadCommandBars(_T("CommandBars"));
  109. return 0;
  110. }
  111. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  112. {
  113. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  114. return FALSE;
  115. cs.lpszClass = _T("XTPMainFrame");
  116. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  117. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  118. return TRUE;
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CMainFrame diagnostics
  122. #ifdef _DEBUG
  123. void CMainFrame::AssertValid() const
  124. {
  125. CMDIFrameWnd::AssertValid();
  126. }
  127. void CMainFrame::Dump(CDumpContext& dc) const
  128. {
  129. CMDIFrameWnd::Dump(dc);
  130. }
  131. #endif //_DEBUG
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CMainFrame message handlers
  134. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  135. {
  136. if (wParam == XTP_DPN_SHOWWINDOW)
  137. {
  138. // get a pointer to the docking pane being shown.
  139. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  140. if (!pPane->IsValid())
  141. {
  142. if (pPane->GetID() == 1)
  143. {
  144. if (m_pHeroesView == 0)
  145. {
  146. m_pHeroesView = new  CHeroesView();
  147. m_pHeroesView->Create(_T("STATIC"), NULL, WS_CHILD, CRect(0, 0, 0, 0), this, 0);
  148. ((CHeroesView*)m_pHeroesView)->OnInitialUpdate();
  149. }
  150. pPane->Attach(m_pHeroesView);
  151. }
  152. if (pPane->GetID() == 2)
  153. {
  154. if (m_pDockingFrame == 0)
  155. {
  156. m_pDockingFrame = (CDockingFrame*)CDockingFrame::CreateObject();
  157. m_pDockingFrame->Create(NULL, NULL, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  158. m_pDockingFrame->ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
  159. }
  160. pPane->Attach(m_pDockingFrame);
  161. }
  162. if (pPane->GetID() == 3)
  163. {
  164. if (!m_wndEdit.GetSafeHwnd())
  165. {
  166. VERIFY(m_wndEdit.CreateEx(WS_EX_STATICEDGE, _T("EDIT"), _T(""),
  167. WS_CHILD|ES_AUTOVSCROLL|ES_MULTILINE, CRect(0, 0,200, 120), this, 0));
  168. m_wndEdit.SetFont(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
  169. }
  170. pPane->Attach(&m_wndEdit);
  171. }
  172. }
  173. return TRUE; // handled
  174. }
  175. return FALSE;
  176. }
  177. void CMainFrame::OnWindowNewpopout()
  178. {
  179. if (m_pNewFrameWnd)
  180. {
  181. m_pNewFrameWnd->BringWindowToTop();
  182. return;
  183. }
  184. m_pNewFrameWnd = new CPopoutFrame;
  185. m_pNewFrameWnd->LoadFrame(IDR_MAINFRAME,
  186. WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
  187. // The one and only window has been initialized, so show and update it.
  188. m_pNewFrameWnd->ShowWindow(SW_SHOW);
  189. m_pNewFrameWnd->UpdateWindow();
  190. }
  191. void CMainFrame::OnUpdateWindowNewpopout(CCmdUI* pCmdUI)
  192. {
  193. pCmdUI->SetCheck(m_pNewFrameWnd && ::IsWindow(m_pNewFrameWnd->m_hWnd));
  194. }
  195. void CMainFrame::OnClose()
  196. {
  197. // Save the current state for command bars.
  198. SaveCommandBars(_T("CommandBars"));
  199. if (m_pNewFrameWnd)
  200. m_pNewFrameWnd->SendMessage(WM_CLOSE);
  201. CMDIFrameWnd::OnClose();
  202. }
  203. void CMainFrame::OnWindowDialog()
  204. {
  205. CAdvancedDialog ad;
  206. ad.DoModal();
  207. }
  208. void CMainFrame::OnCustomize()
  209. {
  210. // get a pointer to the command bars object.
  211. CXTPCommandBars* pCommandBars = GetCommandBars();
  212. if (pCommandBars == NULL)
  213. return;
  214. // instanciate the customize dialog
  215. CXTPCustomizeSheet dlg(pCommandBars);
  216. // add the options page to the customize dialog.
  217. CXTPCustomizeOptionsPage pageOptions(&dlg);
  218. dlg.AddPage(&pageOptions);
  219. // add the commands page to the customize dialog.
  220. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  221. pPageCommands->AddCategories(IDR_ADVANCTYPE);
  222. // initialize the commands page page.
  223. pPageCommands->InsertAllCommandsCategory();
  224. pPageCommands->InsertBuiltInMenus(IDR_ADVANCTYPE);
  225. pPageCommands->InsertNewMenuCategory();
  226. // display the customize dialog.
  227. dlg.DoModal();
  228. }
  229. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  230. {
  231. // Toggle CommandBars
  232. GetCommandBars()->OnSetPreviewMode(bPreview);
  233. // Toggle Docking Panes.
  234. m_paneManager.OnSetPreviewMode(bPreview);
  235. CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
  236. }