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 "CalendarDemo.h"
  22. #include "MainFrm.h"
  23. #include "CalendarDemoView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame
  31. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  32. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  33. //{{AFX_MSG_MAP(CMainFrame)
  34. ON_WM_CREATE()
  35. //}}AFX_MSG_MAP
  36. ON_COMMAND_EX(ID_VIEW_DATEPICKER, OnBarCheck)
  37. ON_UPDATE_COMMAND_UI(ID_VIEW_DATEPICKER, OnUpdateControlBarMenu)
  38. ON_COMMAND_EX(ID_VIEW_PROPERTIES, OnBarCheck)
  39. ON_UPDATE_COMMAND_UI(ID_VIEW_PROPERTIES, OnUpdateControlBarMenu)
  40. ON_XTP_CREATECONTROL()
  41. ON_XTP_EXECUTE(ID_VIEW_OFFICE_THEME, OnOfficeThemeChanged)
  42. END_MESSAGE_MAP()
  43. static UINT indicators[] =
  44. {
  45. ID_SEPARATOR,           // status line indicator
  46. ID_INDICATOR_CAPS,
  47. ID_INDICATOR_NUM,
  48. ID_INDICATOR_SCRL,
  49. };
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMainFrame construction/destruction
  52. CMainFrame::CMainFrame()
  53. {
  54. m_nOfficeTheme = -1;
  55. }
  56. CMainFrame::~CMainFrame()
  57. {
  58. }
  59. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  60. {
  61. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  62. return -1;
  63. if (!m_wndStatusBar.Create(this) ||
  64. !m_wndStatusBar.SetIndicators(indicators,
  65. sizeof(indicators)/sizeof(UINT)))
  66. {
  67. TRACE0("Failed to create status barn");
  68. return -1;      // fail to create
  69. }
  70. if (!InitCommandBars())
  71. return -1;
  72. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  73. CXTPCommandBars* pCommandBars = GetCommandBars();
  74. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  75. CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  76. if (!pCommandBar ||
  77. !pCommandBar->LoadToolBar(IDR_MAINFRAME))
  78. {
  79. TRACE0("Failed to create toolbarn");
  80. return -1;
  81. }
  82. pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME, IDR_TOOLBAR_ALPHA);
  83. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
  84. // Load the previous state for command bars.
  85. LoadCommandBars(_T("CommandBars"));
  86. EnableDocking(CBRS_ALIGN_ANY);
  87. SetOfficeTheme(xtpCalendarThemeOffice2007);
  88. // Initialize dialog bar
  89. if (!m_dlgDatePicker.Create(this, IDD_DATEPICKER,
  90. CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_HIDE_INPLACE, ID_VIEW_DATEPICKER))
  91. return -1; // fail to create
  92. // Initialize dialog bar
  93. if (!m_dlgOptions.Create(this, IDD_CALENDAR_DEMO_VIEW,
  94. CBRS_ALIGN_TOP|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_HIDE_INPLACE, ID_VIEW_PROPERTIES))
  95. return -1; // fail to create
  96. //m_dlgOptions.EnableDocking(CBRS_ALIGN_ANY);
  97. m_dlgOptions.EnableDocking(0);
  98. m_dlgOptions.SetWindowText(_T("Options"));
  99. ShowControlBar(&m_dlgOptions, FALSE, FALSE);
  100. FloatControlBar(&m_dlgOptions, CPoint(100, 200));
  101. // docking for DatePicker
  102. m_dlgDatePicker.EnableDocking(CBRS_ALIGN_LEFT);
  103. m_dlgDatePicker.SetWindowText(_T("Date Picker"));
  104. ShowControlBar(&m_dlgDatePicker, TRUE, FALSE);
  105. //FloatControlBar(&m_dlgDatePicker, CPoint(100, GetSystemMetrics(SM_CYSCREEN) / 3));
  106. return 0;
  107. }
  108. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  109. {
  110. if( !CFrameWnd::PreCreateWindow(cs) )
  111. return FALSE;
  112. cs.lpszClass = _T("XTPMainFrame");
  113. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  114. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  115. // TODO: Modify the Window class or styles here by modifying
  116. //  the CREATESTRUCT cs
  117. cs.dwExStyle &= ~WS_EX_CLIENTEDGE|WS_EX_STATICEDGE;
  118. return TRUE;
  119. }
  120. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  121. {
  122. if (lpCreateControl->nID == ID_VIEW_OFFICE_THEME)
  123. {
  124. CXTPControlComboBox* pComboTheme = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  125. pComboTheme->SetCaption(_T("Theme:"));
  126. pComboTheme->AssignDocTemplate(IDR_MAINFRAME);
  127. pComboTheme->SetStyle(xtpComboLabel);
  128. pComboTheme->SetWidth(200);
  129. //pComboTheme->SetDropDownWidth(pComboTheme->GetWidth());
  130. pComboTheme->SetFlags(xtpFlagManualUpdate);
  131. int nIndex = pComboTheme->AddString(_T("Office 2000"));
  132. pComboTheme->SetItemData(nIndex, xtpCalendarThemeOffice2000);
  133. nIndex = pComboTheme->AddString(_T("Office XP"));
  134. pComboTheme->SetItemData(nIndex, xtpCalendarThemeOfficeXP);
  135. nIndex = pComboTheme->AddString(_T("Office 2003"));
  136. pComboTheme->SetItemData(nIndex, xtpCalendarThemeOffice2003);
  137. int nIndexBlue = pComboTheme->AddString(_T("Office 2007 (Blue)"));
  138. pComboTheme->SetItemData(nIndexBlue, xtpCalendarThemeOffice2007);
  139. // 0 - Blue, 1 - Silver, 2 - Black
  140. if (FILEEXISTS_S(_GetTheme2007Style_file(1)))
  141. {
  142. nIndex = pComboTheme->AddString(_T("Office 2007 (Silver)"));
  143. pComboTheme->SetItemData(nIndex, xtpCalendarThemeOffice2007 + 100 + 1);
  144. }
  145. if (FILEEXISTS_S(_GetTheme2007Style_file(2)))
  146. {
  147. nIndex = pComboTheme->AddString(_T("Office 2007 (Black)"));
  148. pComboTheme->SetItemData(nIndex, xtpCalendarThemeOffice2007 + 100 + 2);
  149. }
  150. lpCreateControl->pControl = pComboTheme;
  151. pComboTheme->SetCurSel(nIndexBlue);
  152. return TRUE;
  153. }
  154. return FALSE;
  155. }
  156. void CMainFrame::OnOfficeThemeChanged(NMHDR* pNMHDR, LRESULT* pResult)
  157. {
  158. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  159. CXTPControlComboBox* pControl = (CXTPControlComboBox*)tagNMCONTROL->pControl;
  160. ASSERT(pControl->GetType() == xtpControlComboBox);
  161. if (pControl->GetType() != xtpControlComboBox)
  162. {
  163. ASSERT(FALSE);
  164. return;
  165. }
  166. int nCurSel = pControl->GetCurSel();
  167. if (nCurSel < 0 || nCurSel >= pControl->GetCount())
  168. {
  169. ASSERT(FALSE);
  170. return;
  171. }
  172. int nTheme = (int)pControl->GetItemData(nCurSel);
  173. #ifdef _DEBUG
  174. if ((GetKeyState(VK_SHIFT) & 0x8000) && (GetKeyState(VK_CONTROL) & 0x8000))
  175. {
  176. if (FILEEXISTS_S(_GetTheme2007Style_file(3)))
  177. {
  178. int nIndex = pControl->AddString(_T("Office 2007 (Aqua)"));
  179. pControl->SetItemData(nIndex, xtpCalendarThemeOffice2007 + 100 + 3);
  180. pControl->SetCurSel(nIndex);
  181. nTheme = xtpCalendarThemeOffice2007 + 100 + 3;
  182. }
  183. }
  184. #endif
  185. SetOfficeTheme(nTheme);
  186. *pResult = 1;
  187. }
  188. void CMainFrame::SetOfficeTheme(int nCalendarTheme)
  189. {
  190. // xtpThemeOffice2000,     // Office 2000 theme.
  191. // xtpThemeOfficeXP,       // Office XP theme.
  192. // xtpThemeOffice2003,     // Office 2003 theme.
  193. // xtpThemeNativeWinXP,    // Windows XP themes support.
  194. // xtpThemeWhidbey,        // Visual Studio 2005 theme.
  195. // xtpThemeOffice2007,     // Office 2007 theme.
  196. // xtpThemeRibbon,         // Office 2007 style ribbon theme
  197. // xtpThemeVisualStudio2008, // Visual Studio 2008 theme
  198. // xtpThemeCustom          // Custom theme.
  199. static int sarThemesMap[xtpCalendarThemeOffice2007+1] = {0};
  200. if (sarThemesMap[xtpCalendarThemeOffice2000] == 0)
  201. {
  202. sarThemesMap[xtpCalendarThemeOffice2000] = xtpThemeOffice2000;
  203. sarThemesMap[xtpCalendarThemeOfficeXP] = xtpThemeOfficeXP;
  204. sarThemesMap[xtpCalendarThemeOffice2003] = xtpThemeOffice2003;
  205. sarThemesMap[xtpCalendarThemeOffice2007] = xtpThemeRibbon;
  206. }
  207. // 0 - Blue, 1 - Silver, 2 - Black
  208. int nTheme2007Style = 0;
  209. if (nCalendarTheme > xtpCalendarThemeOffice2007)
  210. {
  211. nTheme2007Style = nCalendarTheme - xtpCalendarThemeOffice2007 - 100;
  212. nCalendarTheme = xtpCalendarThemeOffice2007;
  213. }
  214. XTPPaintTheme nTheme2 = (XTPPaintTheme)sarThemesMap[nCalendarTheme];
  215. //------------------------------------
  216. CString strFilePath = _GetTheme2007Style_file(nTheme2007Style);
  217. XTPOffice2007Images()->SetHandle(strFilePath);
  218. //===============================================================
  219. #ifdef _XTP_INCLUDE_RIBBON
  220. CXTPPaintManager::SetTheme(nTheme2);
  221. if (nTheme2 == xtpThemeRibbon)
  222. EnableOffice2007Frame(GetCommandBars());
  223. else
  224. EnableOffice2007Frame(0);
  225. #else
  226. CXTPPaintManager::SetTheme((XTPPaintTheme)min(nTheme2, xtpThemeOffice2003));
  227. #endif // _XTP_INCLUDE_RIBBON
  228. XTPColorManager()->SetLunaTheme((nTheme2 == xtpThemeOffice2000) ? xtpSystemThemeUnknown : xtpSystemThemeAuto);
  229. RecalcLayout(FALSE);
  230. GetCommandBars()->RedrawCommandBars();
  231. RedrawWindow();
  232. m_nOfficeTheme = nCalendarTheme;
  233. CCalendarDemoView *pView = DYNAMIC_DOWNCAST(CCalendarDemoView, GetActiveView());
  234. if (pView)
  235. pView->OnOfficeThemeChanged(nCalendarTheme);
  236. }
  237. // nTheme2007Style: 0 - Blue, 1 - Silver, 2 - Black
  238. CString CMainFrame::_GetTheme2007Style_file(int nTheme2007Style)
  239. {
  240. CString strFilePath;
  241. if (nTheme2007Style == 0)
  242. return strFilePath; // use derfault(Blue)
  243. //------------------------------------
  244. TCHAR zsFileName[_MAX_PATH];
  245. DWORD dwRes = ::GetModuleFileName(AfxGetInstanceHandle(), zsFileName, _MAX_PATH);
  246. ASSERT(dwRes);
  247. if (dwRes)
  248. {
  249. strFilePath = zsFileName;
  250. int nFLs = strFilePath.ReverseFind(_T('\'));
  251. if (nFLs > 0)
  252. strFilePath.ReleaseBuffer(nFLs + 1);
  253. //------------------------------------
  254. if (nTheme2007Style == 1)
  255. {
  256. strFilePath += _T("Styles\Office2007Silver.dll");
  257. }
  258. else if (nTheme2007Style == 2)
  259. {
  260. strFilePath += _T("Styles\Office2007Black.dll");
  261. }
  262. else if (nTheme2007Style == 3)
  263. {
  264. strFilePath += _T("Styles\Office2007Aqua.dll");
  265. }
  266. else 
  267. {
  268. strFilePath = _T(""); // use derfault(Blue)
  269. }
  270. }
  271. return strFilePath;
  272. }
  273. /////////////////////////////////////////////////////////////////////////////
  274. // CMainFrame diagnostics
  275. #ifdef _DEBUG
  276. void CMainFrame::AssertValid() const
  277. {
  278. CFrameWnd::AssertValid();
  279. }
  280. void CMainFrame::Dump(CDumpContext& dc) const
  281. {
  282. CFrameWnd::Dump(dc);
  283. }
  284. #endif //_DEBUG
  285. /////////////////////////////////////////////////////////////////////////////
  286. CDatePickerDialogBar::CDatePickerDialogBar()
  287. {
  288. }
  289. BEGIN_MESSAGE_MAP(CDatePickerDialogBar, CDialogBar)
  290. ON_WM_SIZE()
  291. ON_MESSAGE_VOID(WM_INITDIALOG, OnInitDialog)
  292. END_MESSAGE_MAP()
  293. void CDatePickerDialogBar::OnInitDialog() 
  294. {
  295. Default();
  296. VERIFY(m_wndDatePicker.SubclassDlgItem(IDC_DATEPICKER, this));
  297. m_wndDatePicker.SetBorderStyle(xtpDatePickerBorderStatic);
  298. m_wndDatePicker.SetShowWeekNumbers(TRUE);
  299. }
  300. void CDatePickerDialogBar::OnSize(UINT nType, int cx, int cy)
  301. {
  302. CDialogBar::OnSize(nType, cx, cy);
  303. if (!m_wndDatePicker.m_hWnd)
  304. return;
  305. CXTPClientRect rcClient(this);
  306. CXTPWindowRect rcDatePicker(&m_wndDatePicker);
  307. ScreenToClient(&rcDatePicker);
  308. rcDatePicker.top = rcClient.top;
  309. rcDatePicker.bottom = rcClient.bottom;
  310. m_wndDatePicker.MoveWindow(&rcDatePicker);
  311. }