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

对话框与窗口

开发平台:

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 "ToolTipContext.h"
  22. #include "MainFrm.h"
  23. #include "ExplorerTheme.h"
  24. #include "ControlFavorites.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_DYNAMIC(CMainFrame, CMDIFrameWnd)
  33. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  34. //{{AFX_MSG_MAP(CMainFrame)
  35. ON_WM_CREATE()
  36. ON_WM_CLOSE()
  37. ON_COMMAND(ID_FAVORITES_ADDTOFAVORITES, OnFavoritesAddtofavorites)
  38. //}}AFX_MSG_MAP
  39. ON_XTP_CREATECONTROL()
  40. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  41. END_MESSAGE_MAP()
  42. static UINT indicators[] =
  43. {
  44. ID_SEPARATOR,           // status line indicator
  45. ID_INDICATOR_CAPS,
  46. ID_INDICATOR_NUM,
  47. ID_INDICATOR_SCRL,
  48. };
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CMainFrame construction/destruction
  51. CMainFrame::CMainFrame()
  52. {
  53. srand((unsigned)time(NULL));
  54. }
  55. CMainFrame::~CMainFrame()
  56. {
  57. }
  58. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  59. {
  60. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  61. return -1;
  62. // Create Status bar.
  63. // Important: All control bars including the Status Bar
  64. // must be created before CommandBars....
  65. if (!m_wndStatusBar.Create(this) ||
  66. !m_wndStatusBar.SetIndicators(indicators,
  67. sizeof(indicators)/sizeof(UINT)))
  68. {
  69. TRACE0("Failed to create status barn");
  70. return -1;      // fail to create
  71. }
  72. // Initialize the command bars
  73. if (!InitCommandBars())
  74. return -1;
  75. // Get a pointer to the command bars object.
  76. CXTPCommandBars* pCommandBars = GetCommandBars();
  77. if(pCommandBars == NULL)
  78. {
  79. TRACE0("Failed to create command bars object.n");
  80. return -1;      // fail to create
  81. }
  82. pCommandBars->EnableActions();
  83. // Add the menu bar
  84. CXTPToolBar* pMenuBar = pCommandBars->SetMenu(
  85. _T("Menu Bar"), IDR_MAINFRAME);
  86. if(pMenuBar == NULL)
  87. {
  88. TRACE0("Failed to create menu bar.n");
  89. return -1;      // fail to create
  90. }
  91. //pMenuBar->ModifyBarStyle(CBRS_GRIPPER, 0);
  92. // Create ToolBar
  93. CXTPToolBar* pToolBar = (CXTPToolBar*)
  94. pCommandBars->Add(_T("Standard"), xtpBarTop);
  95. if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
  96. {
  97. TRACE0("Failed to create toolbarn");
  98. return -1;
  99. }
  100. CXTPPaintManager::SetCustomTheme(new CExplorerTheme());
  101. if (pCommandBars->GetImageManager()->IsAlphaIconsSupported())
  102. {
  103. pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME, IDR_TOOLBAR_ALPHA);
  104. UINT uFavorites[] = {ID_FAVORITE_LINK, ID_FAVORITE_FOLDER};
  105. pCommandBars->GetImageManager()->SetIcons(ID_FAVORITES, uFavorites, 2, CSize(16, 16));
  106. }
  107. XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
  108. m_wndProperties.Create(IDD_DIALOG_PROPERTIES, this);
  109. m_wndProperties.CenterWindow(this);
  110. m_wndProperties.ShowWindow(SW_SHOW);
  111. pCommandBars->GetCommandBarsOptions()->bShowPopupBarToolTips = TRUE;
  112. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  113. pCommandBars->GetContextMenus()->Add(IDR_CONTEXT_MENU);
  114. m_wndClient.Attach(this, FALSE);
  115. m_wndClient.EnableToolTips();
  116. if (pCommandBars->GetToolTipContext()->IsBalloonStyleSupported())
  117. {
  118. pCommandBars->GetToolTipContext()->SetStyle(xtpToolTipBalloon);
  119. pCommandBars->GetToolTipContext()->ShowTitleAndDescription(TRUE);
  120. m_wndClient.GetToolTipContext()->SetStyle(xtpToolTipBalloon);
  121. m_wndClient.GetToolTipContext()->ShowTitleAndDescription(TRUE);
  122. }
  123. LoadCommandBars(_T("CommandBars"));
  124. return 0;
  125. }
  126. void CMainFrame::OnClose()
  127. {
  128. SaveCommandBars(_T("CommandBars"));
  129. CMDIFrameWnd::OnClose();
  130. }
  131. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  132. {
  133. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  134. return FALSE;
  135. cs.lpszClass = _T("XTPMainFrame");
  136. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  137. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  138. return TRUE;
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CMainFrame diagnostics
  142. #ifdef _DEBUG
  143. void CMainFrame::AssertValid() const
  144. {
  145. CMDIFrameWnd::AssertValid();
  146. }
  147. void CMainFrame::Dump(CDumpContext& dc) const
  148. {
  149. CMDIFrameWnd::Dump(dc);
  150. }
  151. #endif //_DEBUG
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CMainFrame message handlers
  154. BOOL CMainFrame::GetFavoriteFolder(CString& strFav)
  155. {
  156. LPITEMIDLIST pidlFavorites = NULL;
  157. IMalloc * pMalloc = NULL;
  158. BOOL bResult = FALSE;
  159. TCHAR   szPath[MAX_PATH];
  160. HRESULT hr = SHGetMalloc(&pMalloc);
  161. if (SUCCEEDED(hr))
  162. {
  163. HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidlFavorites);
  164. if (hr == NOERROR )
  165. {
  166. if (SHGetPathFromIDList( pidlFavorites,szPath))
  167. {
  168. strFav = szPath;
  169. bResult = TRUE;
  170. }
  171. }
  172. pMalloc->Free(pidlFavorites);
  173. pMalloc->Release();
  174. }
  175. if (!bResult)
  176. {
  177. HKEY hKey;
  178. TCHAR sz[MAX_PATH];
  179. // find out from the registry where the favorites are located.
  180. if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"), &hKey) == ERROR_SUCCESS)
  181. {
  182. DWORD dwSize = MAX_PATH;
  183. RegQueryValueEx(hKey, _T("Favorites"), NULL, NULL, (LPBYTE)sz, &dwSize);
  184. ExpandEnvironmentStrings(sz, szPath, MAX_PATH);
  185. RegCloseKey(hKey);
  186. strFav = szPath;
  187. bResult = dwSize != 0;
  188. }
  189. }
  190. if (!bResult)
  191. {
  192. GetWindowsDirectory (szPath, MAX_PATH);
  193. strFav = szPath;
  194. strFav += "\Favorites";
  195. }
  196. return TRUE;
  197. }
  198. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  199. {
  200. if (lpCreateControl->nID == ID_FAVORITES)
  201. {
  202. CString strFav;
  203. GetFavoriteFolder(strFav);
  204. lpCreateControl->pControl = new CControlFavorites(strFav);
  205. return TRUE;
  206. }
  207. return FALSE;
  208. }
  209. void CMainFrame::OnFavoritesAddtofavorites() 
  210. {
  211. IShellUIHelper* pShell = NULL;
  212. HRESULT hr = CoCreateInstance(CLSID_ShellUIHelper, NULL, CLSCTX_SERVER,
  213. IID_IShellUIHelper, (void**)&pShell);
  214. if (hr == S_OK)
  215. {
  216. COleVariant vtTitle(_T("Codejock Software"));
  217. pShell->AddFavorite(L"http://www.codejock.com", &vtTitle);
  218. pShell->Release();
  219. }
  220. }
  221. void CMainFrame::OnCustomize()
  222. {
  223. CXTPCustomizeSheet cs(GetCommandBars());
  224. CXTPCustomizeMenusPage pageMenus(&cs);
  225. cs.AddPage(&pageMenus);
  226. CXTPCustomizeOptionsPage pageOptions(&cs);
  227. cs.AddPage(&pageOptions);
  228. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  229. pCommands->AddCategories(IDR_TOOLTITYPE);
  230. pCommands->InsertAllCommandsCategory();
  231. pCommands->InsertBuiltInMenus(IDR_TOOLTITYPE);
  232. pCommands->InsertNewMenuCategory();
  233. cs.DoModal();
  234. }