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

对话框与窗口

开发平台:

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 "TaskPanel.h"
  22. #include "MainFrm.h"
  23. #include "SlidersTheme.h"
  24. #include "SearchDlg.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  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_THEME_OFFICE2000, OnThemeOffice2000)
  37. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2000, OnUpdateThemeOffice2000)
  38. ON_COMMAND(ID_THEME_OFFICE2003, OnThemeOffice2003)
  39. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2003, OnUpdateThemeOffice2003)
  40. ON_COMMAND(ID_THEME_NATIVEWINXP, OnThemeNativewinxp)
  41. ON_UPDATE_COMMAND_UI(ID_THEME_NATIVEWINXP, OnUpdateThemeNativewinxp)
  42. ON_COMMAND(ID_THEME_OFFICE2000PLAIN, OnThemeOffice2000plain)
  43. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2000PLAIN, OnUpdateThemeOffice2000plain)
  44. ON_COMMAND(ID_THEME_OFFICEXPPLAIN, OnThemeOfficexpplain)
  45. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICEXPPLAIN, OnUpdateThemeOfficexpplain)
  46. ON_COMMAND(ID_THEME_OFFICE2003PLAIN, OnThemeOffice2003plain)
  47. ON_UPDATE_COMMAND_UI(ID_THEME_OFFICE2003PLAIN, OnUpdateThemeOffice2003plain)
  48. ON_COMMAND(ID_THEME_NATIVEWINXPPLAIN, OnThemeNativewinxpplain)
  49. ON_UPDATE_COMMAND_UI(ID_THEME_NATIVEWINXPPLAIN, OnUpdateThemeNativewinxpplain)
  50. ON_COMMAND(ID_TASKPANEL_ANIMATION, OnTaskpanelAnimation)
  51. ON_UPDATE_COMMAND_UI(ID_TASKPANEL_ANIMATION, OnUpdateTaskpanelAnimation)
  52. ON_COMMAND(ID_VIEW_SEARCH, OnViewSearch)
  53. ON_COMMAND(ID_THEME_CUSTOM, OnThemeCustom)
  54. ON_WM_CLOSE()
  55. ON_COMMAND(ID_VIEW_UISAMPLE, OnViewUisample)
  56. ON_UPDATE_COMMAND_UI(ID_VIEW_UISAMPLE, OnUpdateViewUisample)
  57. //}}AFX_MSG_MAP
  58. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  59. ON_MESSAGE(XTPWM_TASKPANEL_NOTIFY, OnTaskPanelNotify)
  60. END_MESSAGE_MAP()
  61. static UINT indicators[] =
  62. {
  63. ID_SEPARATOR,           // status line indicator
  64. ID_INDICATOR_CAPS,
  65. ID_INDICATOR_NUM,
  66. ID_INDICATOR_SCRL,
  67. };
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CMainFrame construction/destruction
  70. CMainFrame::CMainFrame()
  71. {
  72. m_pUIFrame = 0;
  73. }
  74. CMainFrame::~CMainFrame()
  75. {
  76. }
  77. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  78. {
  79. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  80. return -1;
  81. if (!m_wndStatusBar.Create(this) ||
  82. !m_wndStatusBar.SetIndicators(indicators,
  83.   sizeof(indicators)/sizeof(UINT)))
  84. {
  85. TRACE0("Failed to create status barn");
  86. return -1;      // fail to create
  87. }
  88. if (!InitCommandBars())
  89. return -1;
  90. CXTPPaintManager::SetTheme(xtpThemeNativeWinXP);
  91. CXTPCommandBars* pCommandBars = GetCommandBars();
  92. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  93. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  94. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  95. if (!pStandardBar ||
  96. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  97. {
  98. TRACE0("Failed to create toolbarn");
  99. return -1;
  100. }
  101. if (pCommandBars->GetImageManager()->IsAlphaIconsSupported())
  102. {
  103. pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME, IDR_TOOLBAR_A);
  104. }
  105. pStandardBar->GetControls()->FindControl(ID_VIEW_SEARCH)->SetStyle(xtpButtonIconAndCaption);
  106. pStandardBar->GetControls()->CreateOriginalControls();
  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( !CFrameWnd::PreCreateWindow(cs) )
  114. return FALSE;
  115. cs.lpszClass = _T("XTPMainFrame");
  116. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  117. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  118. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  119. return TRUE;
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CMainFrame diagnostics
  123. #ifdef _DEBUG
  124. void CMainFrame::AssertValid() const
  125. {
  126. CFrameWnd::AssertValid();
  127. }
  128. void CMainFrame::Dump(CDumpContext& dc) const
  129. {
  130. CFrameWnd::Dump(dc);
  131. }
  132. #endif //_DEBUG
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CMainFrame message handlers
  135. void CMainFrame::CreateTaskPanelItems()
  136. {
  137. CXTPTaskPanelGroup* pGroupSystem = m_wndTaskPanel.AddGroup(ID_TASKGROUP_SYSTEM);
  138. pGroupSystem->SetIconIndex(IDI_SYSTEM_TASKS);
  139. pGroupSystem->AddLinkItem(ID_TASKITEM_HIDECONTENTS, 0);
  140. pGroupSystem->AddLinkItem(ID_TASKITEM_ADDORREMOVE, 1);
  141. pGroupSystem->AddLinkItem(ID_TASKITEM_SEARCH, 2);
  142. pGroupSystem->SetSpecialGroup();
  143. CXTPTaskPanelGroup* pGroupFiles = m_wndTaskPanel.AddGroup(ID_TASKGROUP_FILES);
  144. pGroupFiles->AddLinkItem(ID_TASKITEM_NEWFOLDER, 3);
  145. pGroupFiles->AddLinkItem(ID_TASKITEM_PUBLISH, 4);
  146. pGroupFiles->AddLinkItem(ID_TASKITEM_SHARE, 5);
  147. CXTPTaskPanelGroup* pGroupOtherPlaces = m_wndTaskPanel.AddGroup(ID_TASKGROUP_OTHERPLACES);
  148. pGroupOtherPlaces->AddLinkItem(ID_TASKITEM_MYCOMPUTER, 6);
  149. pGroupOtherPlaces->AddLinkItem(ID_TASKITEM_MYDOCUMENTS, 7);
  150. pGroupOtherPlaces->AddLinkItem(ID_TASKITEM_SHAREDDOCUMENTS, 8);
  151. pGroupOtherPlaces->AddLinkItem(ID_TASKITEM_MYNETWORKPLACES, 9);
  152. //pGroupOtherPlaces->ShowCaption(FALSE);
  153. //pGroupOtherPlaces->SetExpanded(FALSE);
  154. //pGroupOtherPlaces->SetExpandable(FALSE);
  155. CXTPTaskPanelGroup* pGroupDetails = m_wndTaskPanel.AddGroup(ID_TASKGROUP_DETAILS);
  156. CXTPTaskPanelGroupItem* pItemDisk = pGroupDetails->AddTextItem(_T("Local Disk (C:)"));
  157. pItemDisk->SetBold(TRUE);
  158. pItemDisk->GetMargins().SetRectEmpty();
  159. pGroupDetails->AddTextItem(_T("Local Disk"));
  160. pGroupDetails->AddTextItem(_T("File Sytem: FAT32"));
  161. pGroupDetails->AddTextItem(_T("Free Space: 23,3 GB"));
  162. pGroupDetails->AddTextItem(_T("Total Size: 76,2 GB"));
  163. m_wndTaskPanel.GetImageManager()->SetIcons(XTPImageManager()->IsAlphaIconsSupported()?
  164. IDB_TASKICONS_ALPHA: IDB_TASKICONS_NORMAL, 0, 0, CSize(16, 16));
  165. m_wndTaskPanel.GetImageManager()->SetIcon(IDI_SYSTEM_TASKS, IDI_SYSTEM_TASKS, CSize(32, 32));
  166. }
  167. BOOL CMainFrame::CreateTaskPanel()
  168. {
  169. if (!m_wndTaskPanel.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP, CRect(0, 0, 0, 0), &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0)))
  170. return FALSE;
  171. m_wndTaskPanel.SetOwner(this);
  172. m_wndSplitter.SetColumnInfo(0, 210, 0);
  173. CreateTaskPanelItems();
  174. return TRUE;
  175. }
  176. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
  177. {
  178. m_wndSplitter.CreateStatic(this, 1, 2);
  179. if (!CreateTaskPanel())
  180. return FALSE;
  181. m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, CSize(300, 0), pContext);
  182. m_wndSplitter.ShowTopBorder(FALSE, 0);
  183. return TRUE;
  184. }
  185. void CMainFrame::SetTheme(XTPTaskPanelPaintTheme taskPanelTheme)
  186. {
  187. m_wndTaskPanel.SetTheme(taskPanelTheme);
  188. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  189. }
  190. void CMainFrame::OnThemeOffice2000()
  191. {
  192. XTPPaintManager()->SetTheme(xtpThemeOffice2000);
  193. GetCommandBars()->RedrawCommandBars();
  194. SetTheme(xtpTaskPanelThemeOffice2000);
  195. }
  196. void CMainFrame::OnUpdateThemeOffice2000(CCmdUI* pCmdUI)
  197. {
  198. pCmdUI->SetCheck(m_wndTaskPanel.GetCurrentTheme() == xtpTaskPanelThemeOffice2000);
  199. }
  200. void CMainFrame::OnThemeOffice2003()
  201. {
  202. XTPPaintManager()->SetTheme(xtpThemeOffice2003);
  203. GetCommandBars()->RedrawCommandBars();
  204. SetTheme(xtpTaskPanelThemeOffice2003);
  205. }
  206. void CMainFrame::OnUpdateThemeOffice2003(CCmdUI* pCmdUI)
  207. {
  208. pCmdUI->SetCheck(m_wndTaskPanel.GetCurrentTheme() == xtpTaskPanelThemeOffice2003);
  209. }
  210. void CMainFrame::OnThemeNativewinxp()
  211. {
  212. XTPPaintManager()->SetTheme(xtpThemeNativeWinXP);
  213. GetCommandBars()->RedrawCommandBars();
  214. SetTheme(xtpTaskPanelThemeNativeWinXP);
  215. }
  216. void CMainFrame::OnUpdateThemeNativewinxp(CCmdUI* pCmdUI)
  217. {
  218. pCmdUI->SetCheck(m_wndTaskPanel.GetCurrentTheme() == xtpTaskPanelThemeNativeWinXP);
  219. }
  220. void CMainFrame::OnThemeOffice2000plain()
  221. {
  222. XTPPaintManager()->SetTheme(xtpThemeOffice2000);
  223. GetCommandBars()->RedrawCommandBars();
  224. SetTheme(xtpTaskPanelThemeOffice2000Plain);
  225. }
  226. void CMainFrame::OnUpdateThemeOffice2000plain(CCmdUI* pCmdUI)
  227. {
  228. pCmdUI->SetCheck(m_wndTaskPanel.GetCurrentTheme() == xtpTaskPanelThemeOffice2000Plain);
  229. }
  230. void CMainFrame::OnThemeOfficexpplain()
  231. {
  232. XTPPaintManager()->SetTheme(xtpThemeOfficeXP);
  233. GetCommandBars()->RedrawCommandBars();
  234. SetTheme(xtpTaskPanelThemeOfficeXPPlain);
  235. }
  236. void CMainFrame::OnUpdateThemeOfficexpplain(CCmdUI* pCmdUI)
  237. {
  238. pCmdUI->SetCheck(m_wndTaskPanel.GetCurrentTheme() == xtpTaskPanelThemeOfficeXPPlain);
  239. }
  240. void CMainFrame::OnThemeOffice2003plain()
  241. {
  242. XTPPaintManager()->SetTheme(xtpThemeOffice2003);
  243. GetCommandBars()->RedrawCommandBars();
  244. SetTheme(xtpTaskPanelThemeOffice2003Plain);
  245. }
  246. void CMainFrame::OnUpdateThemeOffice2003plain(CCmdUI* pCmdUI)
  247. {
  248. pCmdUI->SetCheck(m_wndTaskPanel.GetCurrentTheme() == xtpTaskPanelThemeOffice2003Plain);
  249. }
  250. void CMainFrame::OnThemeNativewinxpplain()
  251. {
  252. XTPPaintManager()->SetTheme(xtpThemeNativeWinXP);
  253. GetCommandBars()->RedrawCommandBars();
  254. SetTheme(xtpTaskPanelThemeNativeWinXPPlain);
  255. }
  256. void CMainFrame::OnUpdateThemeNativewinxpplain(CCmdUI* pCmdUI)
  257. {
  258. pCmdUI->SetCheck(m_wndTaskPanel.GetCurrentTheme() == xtpTaskPanelThemeNativeWinXPPlain);
  259. }
  260. void CMainFrame::OnTaskpanelAnimation()
  261. {
  262. m_wndTaskPanel.SetAnimation(m_wndTaskPanel.GetAnimation() == xtpTaskPanelAnimationNo? xtpTaskPanelAnimationYes: xtpTaskPanelAnimationNo);
  263. }
  264. void CMainFrame::OnUpdateTaskpanelAnimation(CCmdUI* pCmdUI)
  265. {
  266. pCmdUI->SetCheck(m_wndTaskPanel.GetAnimation() == xtpTaskPanelAnimationYes);
  267. }
  268. LRESULT CMainFrame::OnTaskPanelNotify(WPARAM wParam, LPARAM lParam)
  269. {
  270. switch(wParam) {
  271. case XTP_TPN_CLICK:
  272. {
  273. CXTPTaskPanelGroupItem* pItem = (CXTPTaskPanelGroupItem*)lParam;
  274. TRACE(_T("Click Event: pItem.Caption = %s, pItem.ID = %in"), pItem->GetCaption(), pItem->GetID());
  275. }
  276. break;
  277. case XTP_TPN_RCLICK:
  278. {
  279. CXTPTaskPanelItem* pItem = (CXTPTaskPanelItem*)lParam;
  280. TRACE(_T("RClick Event: pItem.Caption = %s, pItem.ID = %in"), pItem->GetCaption(), pItem->GetID());
  281. }
  282. break;
  283. }
  284. return 0;
  285. }
  286. void CMainFrame::OnViewSearch()
  287. {
  288. CSearchDlg sd;
  289. sd.DoModal();
  290. }
  291. void CMainFrame::OnThemeCustom()
  292. {
  293. XTPPaintManager()->SetTheme(xtpThemeOfficeXP);
  294. GetCommandBars()->RedrawCommandBars();
  295. m_wndTaskPanel.SetCustomTheme(new CSlidersTheme);
  296. RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
  297. }
  298. void CMainFrame::OnClose()
  299. {
  300. // Save the current state for command bars.
  301. SaveCommandBars(_T("CommandBars"));
  302. if (m_pUIFrame)
  303. {
  304. m_pUIFrame->SendMessage(WM_CLOSE);
  305. }
  306. CFrameWnd::OnClose();
  307. }
  308. void CMainFrame::OnCustomize()
  309. {
  310. // get a pointer to the command bars object.
  311. CXTPCommandBars* pCommandBars = GetCommandBars();
  312. if (pCommandBars == NULL)
  313. return;
  314. // instanciate the customize dialog
  315. CXTPCustomizeSheet dlg(pCommandBars);
  316. // add the options page to the customize dialog.
  317. CXTPCustomizeOptionsPage pageOptions(&dlg);
  318. dlg.AddPage(&pageOptions);
  319. // add the commands page to the customize dialog.
  320. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  321. pPageCommands->AddCategories(IDR_MAINFRAME);
  322. // initialize the commands page page.
  323. pPageCommands->InsertAllCommandsCategory();
  324. pPageCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  325. pPageCommands->InsertNewMenuCategory();
  326. // display the customize dialog.
  327. dlg.DoModal();
  328. }
  329. void CMainFrame::OnViewUisample() 
  330. {
  331. if (m_pUIFrame)
  332. {
  333. m_pUIFrame->BringWindowToTop();
  334. return;
  335. }
  336. m_pUIFrame = new CUIFrame;
  337. m_pUIFrame->LoadFrame(IDR_MAINFRAME,
  338. WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE |WS_CLIPCHILDREN|WS_CLIPSIBLINGS, NULL, NULL);
  339. // The one and only window has been initialized, so show and update it.
  340. m_pUIFrame->ShowWindow(SW_SHOW);
  341. m_pUIFrame->UpdateWindow();
  342. }
  343. void CMainFrame::OnUpdateViewUisample(CCmdUI* pCmdUI) 
  344. {
  345. pCmdUI->SetCheck(m_pUIFrame != NULL ? TRUE: FALSE);
  346. }