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

对话框与窗口

开发平台:

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 "PaneOptions.h"
  22. #include "PreviewFrame.h"
  23. #include "MainFrm.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. CArray<CXTPDockingPaneManager*, CXTPDockingPaneManager*> CMainFrame::m_arrManagers;
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMainFrame
  32. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  33. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  34. //{{AFX_MSG_MAP(CMainFrame)
  35. ON_WM_CREATE()
  36. ON_COMMAND(ID_VIEW_OFFICEXP, OnViewOfficexp)
  37. ON_UPDATE_COMMAND_UI(ID_VIEW_OFFICEXP, OnUpdateViewOfficexp)
  38. ON_COMMAND(ID_VIEW_OFFICE2003, OnViewOffice2003)
  39. ON_UPDATE_COMMAND_UI(ID_VIEW_OFFICE2003, OnUpdateViewOffice2003)
  40. //}}AFX_MSG_MAP
  41. ON_XTP_CREATECONTROL()
  42. ON_COMMAND(ID_HELP_SEARCH, OnEmptyCommand)
  43. ON_COMMAND(ID_HELP_HELP, OnEmptyCommand)
  44. ON_COMMAND(ID_HELP_USING, OnEmptyCommand)
  45. ON_COMMAND(ID_BUILD_COMPILE, OnEmptyCommand)
  46. ON_COMMAND(ID_BUILD_DEBUG, OnEmptyCommand)
  47. ON_COMMAND(ID_BUILD_RUN, OnEmptyCommand)
  48. ON_XTP_EXECUTE(ID_BUILD_CONFIGURATION, OnBuildConfiguration)
  49. ON_UPDATE_COMMAND_UI(ID_BUILD_CONFIGURATION, OnUpdateBuildConfiguration)
  50. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  51. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  52. END_MESSAGE_MAP()
  53. static UINT indicators[] =
  54. {
  55. ID_SEPARATOR,           // status line indicator
  56. ID_INDICATOR_CAPS,
  57. ID_INDICATOR_NUM,
  58. ID_INDICATOR_SCRL,
  59. };
  60. #define PANEID_NAVIGATION 10
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CMainFrame construction/destruction
  63. CMainFrame::CMainFrame()
  64. {
  65. m_nState = 0;
  66. XTAuxData().bXPMode = TRUE;
  67. }
  68. CMainFrame::~CMainFrame()
  69. {
  70. }
  71. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  72. {
  73. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  74. return -1;
  75. if (!m_wndStatusBar.Create(this) ||
  76. !m_wndStatusBar.SetIndicators(indicators,
  77.   sizeof(indicators)/sizeof(UINT)))
  78. {
  79. TRACE0("Failed to create status barn");
  80. return -1;      // fail to create
  81. }
  82. if (!InitCommandBars())
  83. return -1;
  84. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  85. CXTPCommandBars* pCommandBars = GetCommandBars();
  86. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  87. XTPImageManager()->SetMaskColor(RGB(0, 255, 0));
  88. CXTPToolBar* pStandardBar = pCommandBars->Add(_T("Standard"), xtpBarTop);
  89. if (!pStandardBar ||
  90. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  91. {
  92. TRACE0("Failed to create toolbarn");
  93. }
  94. CXTPToolBar* pBuildBar = pCommandBars->Add(_T("Build Bar"), xtpBarTop);
  95. if (!pBuildBar ||
  96. !pBuildBar->LoadToolBar(IDR_BUILD_BAR))
  97. {
  98. TRACE0("Failed to create toolbarn");
  99. }
  100. CXTPToolBar* pHelpBar = (CXTPToolBar*)pCommandBars->Add(_T("Help Bar"), xtpBarTop);
  101. if (!pHelpBar ||
  102. !pHelpBar->LoadToolBar(IDR_HELP_BAR))
  103. {
  104. TRACE0("Failed to create toolbarn");
  105. }
  106. DockRightOf(pBuildBar, pStandardBar);
  107. DockRightOf(pHelpBar, pBuildBar);
  108. m_paneManager.InstallDockingPanes(this);
  109. m_paneManager.SetTheme(xtpPaneThemeOffice);
  110. m_arrManagers.Add(&m_paneManager);
  111. // Create docking panes.
  112. CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane(
  113. PANEID_NAVIGATION, CRect(0, 0,200, 120), xtpPaneDockLeft);
  114. pwndPane1->SetTitle(_T("Project Navigation"));
  115. const int  nIDs[] = {PANEID_NAVIGATION};
  116. m_paneManager.SetIcons(IDB_PANE_ICONS, nIDs, 1);
  117. m_ilTreeIcons.Create(16, 16, ILC_MASK|ILC_COLOR8, 0, 1);
  118. CBitmap bmp;
  119. bmp.LoadBitmap(IDR_TREE_ICONS);
  120. m_ilTreeIcons.Add(&bmp, RGB(255, 0, 255));
  121. return 0;
  122. }
  123. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  124. {
  125. if( !CFrameWnd::PreCreateWindow(cs) )
  126. return FALSE;
  127. cs.lpszClass = _T("XTPMainFrame");
  128. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  129. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  130. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  131. return TRUE;
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CMainFrame diagnostics
  135. #ifdef _DEBUG
  136. void CMainFrame::AssertValid() const
  137. {
  138. CFrameWnd::AssertValid();
  139. }
  140. void CMainFrame::Dump(CDumpContext& dc) const
  141. {
  142. CFrameWnd::Dump(dc);
  143. }
  144. #endif //_DEBUG
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CMainFrame message handlers
  147. BOOL CMainFrame::InitializeCaptionBar()
  148. {
  149. if (!m_wndCaption.Create(&m_wndSplitterCaption, _T("Caption Text"), NULL,
  150. WS_VISIBLE|SS_CENTER|SS_CENTERIMAGE, CRect(0,0,0,0), m_wndSplitterCaption.IdFromRowCol(0, 0)))
  151. {
  152. TRACE0("Failed to caption window.n");
  153. return FALSE;
  154. }
  155. HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  156. // set the caption colors.
  157. m_wndCaption.SetCaptionColors (GetXtremeColor(COLOR_3DFACE),
  158. GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_WINDOW) );
  159. LOGFONT lf;
  160. XTAuxData().fontBold.GetLogFont(&lf);
  161. lf.lfHeight = 18;
  162. m_fontCaption.CreateFontIndirect(&lf);
  163. // set the font and initial icon.
  164. m_wndCaption.ModifyCaptionStyle(0,
  165. &m_fontCaption, NULL, hIcon);
  166. // Sizing for splitter
  167. m_wndSplitterCaption.SetRowInfo (0, 22, 0);
  168. return TRUE;
  169. }
  170. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* /*pContext*/)
  171. {
  172. // TODO: Add your specialized code here and/or call the base class
  173. m_wndSplitterCaption.CreateStatic(this, 2, 1);
  174. m_wndSplitterCaption.ModifyStyle(0, WS_CLIPCHILDREN|WS_CLIPSIBLINGS);
  175. if (!InitializeCaptionBar())
  176. return FALSE;
  177. m_pPreviewFrame = (CPreviewFrame*)CPreviewFrame::CreateObject();
  178. m_pPreviewFrame->CreateEx(NULL, NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), &m_wndSplitterCaption, m_wndSplitterCaption.IdFromRowCol(1, 0));
  179. m_wndSplitterCaption.SetSplitterStyle(XT_SPLIT_NOFULLDRAG | XT_SPLIT_NOSIZE | XT_SPLIT_NOBORDER);
  180. return TRUE;
  181. }
  182. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  183. {
  184. if (lpCreateControl->bToolBar)
  185. {
  186. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  187. if (!pToolBar)
  188. return FALSE;
  189. if (lpCreateControl->nID == ID_BUILD_CONFIGURATION && pToolBar->GetBarID() == IDR_BUILD_BAR)
  190. {
  191. CXTPControlComboBox* pComboState = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  192. pComboState->AddString(_T("Debug"));
  193. pComboState->AddString(_T("Release"));
  194. pComboState->AddString(_T("Configuration Manager"));
  195. pComboState->SetDropDownWidth(150);
  196. lpCreateControl->pControl = pComboState;
  197. return TRUE;
  198. }
  199. }
  200. return FALSE;
  201. }
  202. void CMainFrame::OnEmptyCommand()
  203. {
  204. }
  205. void CMainFrame::OnBuildConfiguration(NMHDR* pNMHDR, LRESULT* pResult)
  206. {
  207. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  208. CXTPControlComboBox* pControl = (CXTPControlComboBox*)tagNMCONTROL->pControl;
  209. if (pControl->GetType() == xtpControlComboBox)
  210. {
  211. int nState = pControl->GetCurSel();
  212. if (nState != 2)
  213. {
  214. m_nState = nState;
  215. }
  216. else
  217. {
  218. MessageBox(_T("Configuration Manager"));
  219. pControl->SetCurSel(m_nState);
  220. }
  221. *pResult = TRUE; // Handled
  222. }
  223. }
  224. void CMainFrame::OnUpdateBuildConfiguration(CCmdUI* pCmdUI)
  225. {
  226. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmdUI->m_pOther;
  227. if (pToolBar && !XTPMouseManager()->IsTrackedLock())
  228. {
  229. CXTPControlComboBox* pStateCombo = (CXTPControlComboBox*)pToolBar->GetControls()->GetAt(pCmdUI->m_nIndex);
  230. if (pStateCombo->GetType() == xtpControlComboBox)
  231. {
  232. pStateCombo->SetCurSel(m_nState);
  233. }
  234. }
  235. pCmdUI->Enable(TRUE);
  236. }
  237. void CMainFrame::OnCustomize()
  238. {
  239. CXTPCustomizeSheet cs(GetCommandBars());
  240. CXTPCustomizeOptionsPage pageOptions(&cs);
  241. cs.AddPage(&pageOptions);
  242. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  243. pCommands->AddCategories(IDR_MAINFRAME);
  244. pCommands->InsertAllCommandsCategory();
  245. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  246. pCommands->InsertNewMenuCategory();
  247. cs.DoModal();
  248. }
  249. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  250. {
  251. if (wParam == XTP_DPN_SHOWWINDOW)
  252. {
  253. // get a pointer to the docking pane being shown.
  254. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  255. ASSERT(pPane->GetID() == PANEID_NAVIGATION);
  256. if (!pPane->IsValid())
  257. {
  258. // create and attach the edit control for this pane.
  259. if (!::IsWindow(m_wndTreeCtrl.m_hWnd))
  260. {
  261. // create the tree control.
  262. if (!m_wndTreeCtrl.Create (WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS,
  263. CRect(0,0,0,0), this, 101))
  264. {
  265. TRACE0( "Unable to create tree control.n" );
  266. return -1;
  267. }
  268. m_wndTreeCtrl.SetImageList(&m_ilTreeIcons, TVSIL_NORMAL);
  269. m_wndTreeCtrl.InsertItem(_T("General"), 0, 0);
  270. HTREEITEM hItem = m_wndTreeCtrl.InsertItem(_T("Standard Resource"), 0, 0);
  271. m_wndTreeCtrl.InsertItem(_T("Custom Resource"), 0, 0);
  272. m_wndTreeCtrl.InsertItem(_T("User Interface"), 0, 0);
  273. m_wndTreeCtrl.InsertItem(_T("File System"), 6, 6, hItem);
  274. m_wndTreeCtrl.InsertItem(_T("Perfomance"), 5, 5, hItem);
  275. m_wndTreeCtrl.InsertItem(_T("COM+"), 1, 1, hItem);
  276. m_wndTreeCtrl.InsertItem(_T("System Tools"), 3, 3, hItem);
  277. m_wndTreeCtrl.InsertItem(_T("Local Users"), 4, 4, hItem);
  278. m_wndTreeCtrl.InsertItem(_T("Controls Services"), 2, 2, hItem);
  279. m_wndTreeCtrl.Expand (hItem, TVE_EXPAND);
  280. }
  281. pPane->Attach(&m_wndTreeCtrl);
  282. }
  283. return TRUE; // handled
  284. }
  285. return FALSE;
  286. }
  287. void CMainFrame::OnViewOfficexp()
  288. {
  289. for (int i = 0; i < m_arrManagers.GetSize(); i++) m_arrManagers[i]->SetTheme(xtpPaneThemeOffice);
  290. m_wndCaption.SetCaptionColors (GetXtremeColor(COLOR_3DFACE),
  291. GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_WINDOW) );
  292. XTThemeManager()->SetTheme(xtThemeOfficeXP);
  293. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  294. RedrawWindow(0, 0, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE|RDW_ALLCHILDREN);
  295. }
  296. void CMainFrame::OnUpdateViewOfficexp(CCmdUI* pCmdUI)
  297. {
  298. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOfficeXP );
  299. }
  300. void CMainFrame::OnViewOffice2003()
  301. {
  302. for (int i = 0; i < m_arrManagers.GetSize(); i++) m_arrManagers[i]->SetTheme(xtpPaneThemeOffice2003);
  303. XTThemeManager()->SetTheme(xtThemeOffice2003);
  304. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  305. RedrawWindow(0, 0, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE|RDW_ALLCHILDREN);
  306. }
  307. void CMainFrame::OnUpdateViewOffice2003(CCmdUI* pCmdUI)
  308. {
  309. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003);
  310. }