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

对话框与窗口

开发平台:

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 "MDIMenus.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_DYNAMIC(CMainFrame, CMDIFrameWnd)
  31. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  32. //{{AFX_MSG_MAP(CMainFrame)
  33. // NOTE - the ClassWizard will add and remove mapping macros here.
  34. //    DO NOT EDIT what you see in these blocks of generated code !
  35. ON_WM_CREATE()
  36. ON_WM_CLOSE()
  37. //}}AFX_MSG_MAP
  38. ON_XTP_CREATECONTROL()
  39. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  40. END_MESSAGE_MAP()
  41. static UINT indicators[] =
  42. {
  43. ID_SEPARATOR,           // status line indicator
  44. ID_INDICATOR_CAPS,
  45. ID_INDICATOR_NUM,
  46. ID_INDICATOR_SCRL,
  47. };
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CMainFrame construction/destruction
  50. CMainFrame::CMainFrame()
  51. {
  52. // TODO: add member initialization code here
  53. }
  54. CMainFrame::~CMainFrame()
  55. {
  56. }
  57. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  58. {
  59. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  60. return -1;
  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. if (!InitCommandBars())
  69. return -1;
  70. CXTPCommandBars* pCommandBars = GetCommandBars();
  71. CXTPMenuBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  72. pMenuBar->SetFlags(xtpFlagAddMDISysPopup);
  73. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  74. if (!pStandardBar ||
  75. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  76. {
  77. TRACE0("Failed to create toolbarn");
  78. return -1;
  79. }
  80. XTPColorManager()->DisableLunaColors(TRUE);
  81. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  82. LoadCommandBars(_T("CommandBars2"));
  83. return 0;
  84. }
  85. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  86. {
  87. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  88. return FALSE;
  89. cs.lpszClass = _T("XTPMainFrame");
  90. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  91. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  92. return TRUE;
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CMainFrame diagnostics
  96. #ifdef _DEBUG
  97. void CMainFrame::AssertValid() const
  98. {
  99. CMDIFrameWnd::AssertValid();
  100. }
  101. void CMainFrame::Dump(CDumpContext& dc) const
  102. {
  103. CMDIFrameWnd::Dump(dc);
  104. }
  105. #endif //_DEBUG
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CMainFrame message handlers
  108. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  109. {
  110. CXTPMenuBar* pMenuBar = DYNAMIC_DOWNCAST(CXTPMenuBar, lpCreateControl->pCommandBar);
  111. if (pMenuBar)
  112. {
  113. ASSERT(lpCreateControl->pMenu);
  114. CMenu* pPopupMenu = lpCreateControl->pMenu->GetSubMenu(lpCreateControl->nIndex);
  115. if (lpCreateControl->strCaption == _T("&Window"))
  116. {
  117. CXTPControlPopup* pControlPopup = CXTPControlPopup::CreateControlPopup(xtpControlPopup);
  118. // Exclude only IDR_MAINFRAME template
  119. pControlPopup->ExcludeDocTemplate(IDR_MAINFRAME);
  120. pControlPopup->SetCommandBar(pPopupMenu);
  121. lpCreateControl->pControl = pControlPopup;
  122. return TRUE;
  123. }
  124. if (lpCreateControl->strCaption == _T("&Edit"))
  125. {
  126. CXTPControlPopup* pControlPopup = CXTPControlPopup::CreateControlPopup(xtpControlPopup);
  127. // Present only in IDR_MDIMENUTYPEEDIT and IDR_MDIMENUTYPEHTML template
  128. pControlPopup->AssignDocTemplate(IDR_MDIMENUTYPEEDIT);
  129. pControlPopup->AssignDocTemplate(IDR_MDIMENUTYPEHTML);
  130. pControlPopup->SetCommandBar(pPopupMenu);
  131. lpCreateControl->pControl = pControlPopup;
  132. return TRUE;
  133. }
  134. if (lpCreateControl->strCaption == _T("&Color"))
  135. {
  136. CXTPControlPopup* pControlPopup = CXTPControlPopup::CreateControlPopup(xtpControlPopup);
  137. // Present only in IDR_MDIMENUTYPECOLOR template
  138. pControlPopup->AssignDocTemplate(IDR_MDIMENUTYPECOLOR);
  139. pControlPopup->SetCommandBar(pPopupMenu);
  140. lpCreateControl->pControl = pControlPopup;
  141. return TRUE;
  142. }
  143. }
  144. if (lpCreateControl->nID == ID_GOTO_URL)
  145. {
  146. CXTPControlComboBox* pComboUrl = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  147. pComboUrl->AssignDocTemplate(IDR_MDIMENUTYPEHTML);
  148. pComboUrl->AddString(_T("http://www.codejock.com"));
  149. pComboUrl->AddString(_T("ms-help://MS.VSCC/vsccCommon/html/vsccCommon_Start_Page.htm"));
  150. pComboUrl->SetWidth(200);
  151. pComboUrl->SetDropDownWidth(300);
  152. pComboUrl->SetDropDownListStyle();
  153. pComboUrl->SetFlags(xtpFlagManualUpdate);
  154. pComboUrl->SetEditText(_T("http://www.codejock.com"));
  155. lpCreateControl->pControl = pComboUrl;
  156. return TRUE;
  157. }
  158. return FALSE;
  159. }
  160. void CMainFrame::OnCustomize()
  161. {
  162. CXTPCustomizeSheet cs(GetCommandBars());
  163. CXTPCustomizeOptionsPage pageOptions(&cs);
  164. cs.AddPage(&pageOptions);
  165. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  166. pCommands->AddCategories(IDR_MAINFRAME);
  167. pCommands->InsertAllCommandsCategory();
  168. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  169. pCommands->InsertNewMenuCategory();
  170. cs.DoModal();
  171. }
  172. void CMainFrame::OnClose()
  173. {
  174. SaveCommandBars(_T("CommandBars2"));
  175. CFrameWnd::OnClose();
  176. }