Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

454 lines
11 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // MainFrm.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CMainFrame class.
  10. //
  11. // Author:
  12. // David Potter (davidp) May 1, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "CluAdmin.h"
  21. #include "ConstDef.h"
  22. #include "MainFrm.h"
  23. #include "TraceTag.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Global Variables
  31. /////////////////////////////////////////////////////////////////////////////
  32. #ifdef _DEBUG
  33. CTraceTag g_tagMainFrame(TEXT("UI"), TEXT("MAIN FRAME"), 0);
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMainFrame
  37. /////////////////////////////////////////////////////////////////////////////
  38. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  39. static UINT indicators[] =
  40. {
  41. ID_SEPARATOR, // status line indicator
  42. ID_INDICATOR_CAPS,
  43. ID_INDICATOR_NUM,
  44. ID_INDICATOR_SCRL,
  45. };
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Message Maps
  48. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  49. //{{AFX_MSG_MAP(CMainFrame)
  50. ON_WM_CREATE()
  51. ON_WM_CLOSE()
  52. //}}AFX_MSG_MAP
  53. // Global help commands
  54. ON_COMMAND(ID_HELP_FINDER, OnHelp)
  55. ON_COMMAND(ID_HELP, OnHelp)
  56. ON_COMMAND(ID_CONTEXT_HELP, OnHelp)
  57. ON_COMMAND(ID_DEFAULT_HELP, OnHelp)
  58. ON_MESSAGE(WM_CAM_RESTORE_DESKTOP, OnRestoreDesktop)
  59. ON_MESSAGE(WM_CAM_CLUSTER_NOTIFY, OnClusterNotify)
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. //++
  63. //
  64. // CMainFrame::CMainFrame
  65. //
  66. // Routine Description:
  67. // Default construtor.
  68. //
  69. // Arguments:
  70. // None.
  71. //
  72. // Return Value:
  73. // None.
  74. //
  75. //--
  76. /////////////////////////////////////////////////////////////////////////////
  77. CMainFrame::CMainFrame(void)
  78. {
  79. } //*** CMainFrame::CMainFrame()
  80. /////////////////////////////////////////////////////////////////////////////
  81. //++
  82. //
  83. // CMainFrame::OnCreate
  84. //
  85. // Routine Description:
  86. // Handler for the WM_CREATE message. Create the contents of the frame,
  87. // including toolbars, status bars, etc.
  88. //
  89. // Arguments:
  90. // lpCreateStruct Pointer to a CREATESTRUCT.
  91. //
  92. // Return Value:
  93. // -1 Failed to create.
  94. // 0 Created successfully.
  95. //
  96. //--
  97. /////////////////////////////////////////////////////////////////////////////
  98. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  99. {
  100. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  101. return -1;
  102. if (!m_wndToolBar.Create(this) ||
  103. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  104. {
  105. Trace(g_tagMainFrame, _T("Failed to create toolbar"));
  106. return -1; // fail to create
  107. }
  108. if (!m_wndStatusBar.Create(this)
  109. || !m_wndStatusBar.SetIndicators(
  110. indicators,
  111. sizeof(indicators)/sizeof(UINT)
  112. ))
  113. {
  114. Trace(g_tagMainFrame, _T("Failed to create status bar"));
  115. return -1; // fail to create
  116. }
  117. // TODO: Remove this if you don't want tool tips or a resizeable toolbar
  118. m_wndToolBar.SetBarStyle(
  119. m_wndToolBar.GetBarStyle()
  120. | CBRS_TOOLTIPS
  121. | CBRS_FLYBY
  122. | CBRS_SIZE_DYNAMIC
  123. );
  124. // TODO: Delete these three lines if you don't want the toolbar to
  125. // be dockable
  126. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  127. EnableDocking(CBRS_ALIGN_ANY);
  128. DockControlBar(&m_wndToolBar);
  129. // Hide the toolbar and/or status bar is that is the current setting.
  130. {
  131. BOOL bShowToolBar;
  132. BOOL bShowStatusBar;
  133. // Read the settings from the user's profile.
  134. bShowToolBar = AfxGetApp()->GetProfileInt(
  135. REGPARAM_SETTINGS,
  136. REGPARAM_SHOW_TOOL_BAR,
  137. TRUE
  138. );
  139. bShowStatusBar = AfxGetApp()->GetProfileInt(
  140. REGPARAM_SETTINGS,
  141. REGPARAM_SHOW_STATUS_BAR,
  142. TRUE
  143. );
  144. // Show or hide the toolbar and status bar.
  145. m_wndToolBar.ShowWindow(bShowToolBar);
  146. m_wndStatusBar.ShowWindow(bShowStatusBar);
  147. } // Hide the toolbar and/or status bar is that is the current setting
  148. return 0;
  149. } //*** CMainFrame::OnCreate()
  150. /////////////////////////////////////////////////////////////////////////////
  151. //++
  152. //
  153. // CMainFrame::GetMessageString
  154. //
  155. // Routine Description:
  156. // Get a string for a command ID.
  157. //
  158. // Arguments:
  159. // nID [IN] Command ID for which a string should be returned.
  160. // rMessage [OUT] String in which to return the message.
  161. //
  162. // Return Value:
  163. // None.
  164. //
  165. //--
  166. /////////////////////////////////////////////////////////////////////////////
  167. void CMainFrame::GetMessageString(UINT nID, CString& rMessage) const
  168. {
  169. CFrameWnd * pframe;
  170. // Pass off to the active MDI child frame window, if there is one.
  171. pframe = MDIGetActive();
  172. if (pframe == NULL)
  173. CMDIFrameWnd::GetMessageString(nID, rMessage);
  174. else
  175. pframe->GetMessageString(nID, rMessage);
  176. } //*** CMainFrame::GetMessageString()
  177. /////////////////////////////////////////////////////////////////////////////
  178. // CMainFrame diagnostics
  179. /////////////////////////////////////////////////////////////////////////////
  180. #ifdef _DEBUG
  181. void CMainFrame::AssertValid(void) const
  182. {
  183. CMDIFrameWnd::AssertValid();
  184. } //*** CMainFrame::AssertValid()
  185. void CMainFrame::Dump(CDumpContext& dc) const
  186. {
  187. CMDIFrameWnd::Dump(dc);
  188. } //*** CMainFrame::Dump()
  189. #endif //_DEBUG
  190. /////////////////////////////////////////////////////////////////////////////
  191. //++
  192. //
  193. // CMainFrame::OnClusterNotify
  194. //
  195. // Routine Description:
  196. // Handler for the WM_CAM_CLUSTER_NOTIFY message.
  197. // Processes cluster notifications.
  198. //
  199. // Arguments:
  200. // None.
  201. //
  202. // Return Value:
  203. // Value returned from the application method.
  204. //
  205. //--
  206. /////////////////////////////////////////////////////////////////////////////
  207. void CMainFrame::OnClose(void)
  208. {
  209. // Save the current window position and size.
  210. {
  211. WINDOWPLACEMENT wp;
  212. wp.length = sizeof wp;
  213. if (GetWindowPlacement(&wp))
  214. {
  215. wp.flags = 0;
  216. if (IsZoomed())
  217. wp.flags |= WPF_RESTORETOMAXIMIZED;
  218. if (IsIconic())
  219. wp.showCmd = SW_SHOWMINNOACTIVE;
  220. // and write it to the .INI file
  221. WriteWindowPlacement(&wp, REGPARAM_SETTINGS, 0);
  222. } // if: window placement retrieved successfully
  223. } // Save the current window position and size
  224. // Save the current connections.
  225. GetClusterAdminApp()->SaveConnections();
  226. // Save the current toolbar and status bar show state.
  227. AfxGetApp()->WriteProfileInt(
  228. REGPARAM_SETTINGS,
  229. REGPARAM_SHOW_TOOL_BAR,
  230. ((m_wndToolBar.GetStyle() & WS_VISIBLE) ? TRUE : FALSE)
  231. );
  232. AfxGetApp()->WriteProfileInt(
  233. REGPARAM_SETTINGS,
  234. REGPARAM_SHOW_STATUS_BAR,
  235. ((m_wndStatusBar.GetStyle() & WS_VISIBLE) ? TRUE : FALSE)
  236. );
  237. CMDIFrameWnd::OnClose();
  238. } //*** CMainFrame::OnClose()
  239. /////////////////////////////////////////////////////////////////////////////
  240. //++
  241. //
  242. // CMainFrame::OnRestoreDesktop
  243. //
  244. // Routine Description:
  245. // Handler for the WM_CAM_RESTORE_DESKTOP message.
  246. // Restores the desktop from the saved parameters.
  247. //
  248. // Arguments:
  249. // wparam 1st parameter.
  250. // lparam 2nd parameter.
  251. //
  252. // Return Value:
  253. // Value returned from the application method.
  254. //
  255. //--
  256. /////////////////////////////////////////////////////////////////////////////
  257. LRESULT CMainFrame::OnRestoreDesktop(WPARAM wparam, LPARAM lparam)
  258. {
  259. // Call this method on the application.
  260. return GetClusterAdminApp()->OnRestoreDesktop(wparam, lparam);
  261. } //*** CMainFrame::OnRestoreDesktop()
  262. /////////////////////////////////////////////////////////////////////////////
  263. //++
  264. //
  265. // CMainFrame::OnClusterNotify
  266. //
  267. // Routine Description:
  268. // Handler for the WM_CAM_CLUSTER_NOTIFY message.
  269. // Processes cluster notifications.
  270. //
  271. // Arguments:
  272. // wparam 1st parameter.
  273. // lparam 2nd parameter.
  274. //
  275. // Return Value:
  276. // Value returned from the application method.
  277. //
  278. //--
  279. /////////////////////////////////////////////////////////////////////////////
  280. LRESULT CMainFrame::OnClusterNotify(WPARAM wparam, LPARAM lparam)
  281. {
  282. CClusterAdminApp * papp = GetClusterAdminApp();
  283. // Call this method on the application.
  284. return papp->OnClusterNotify(wparam, lparam);
  285. } //*** CMainFrame::OnClusterNotify()
  286. /////////////////////////////////////////////////////////////////////////////
  287. //++
  288. //
  289. // CMainFrame::OnHelp
  290. //
  291. // Routine Description:
  292. // Handler for the IDM_HELP_FINDER menu command.
  293. //
  294. // Arguments:
  295. // None.
  296. //
  297. // Return Value:
  298. // None.
  299. //
  300. //--
  301. /////////////////////////////////////////////////////////////////////////////
  302. void CMainFrame::OnHelp(void)
  303. {
  304. HtmlHelpW( m_hWnd, _T("MSCSConcepts.chm"), HH_DISPLAY_TOPIC, 0L );
  305. } //*** CMainFrame::OnHelp()
  306. //*************************************************************************//
  307. /////////////////////////////////////////////////////////////////////////////
  308. // Helpers for saving/restoring window state
  309. static TCHAR g_szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  310. /////////////////////////////////////////////////////////////////////////////
  311. //++
  312. //
  313. // ReadWindowPlacement
  314. //
  315. // Routine Description:
  316. // Read window placement parameters.
  317. //
  318. // Arguments:
  319. // pwp [OUT] WINDOWPLACEMENT structure to fill.
  320. // pszSection [IN] Section name under which to read data.
  321. // nValueNum [IN] Number of the value to read.
  322. //
  323. // Return Value:
  324. // TRUE Parameters read.
  325. // FALSE Parameters not read.
  326. //
  327. //--
  328. /////////////////////////////////////////////////////////////////////////////
  329. BOOL ReadWindowPlacement(
  330. OUT LPWINDOWPLACEMENT pwp,
  331. IN LPCTSTR pszSection,
  332. IN DWORD nValueNum
  333. )
  334. {
  335. CString strBuffer;
  336. CString strValueName;
  337. if (nValueNum <= 1)
  338. strValueName = REGPARAM_WINDOW_POS;
  339. else
  340. strValueName.Format(REGPARAM_WINDOW_POS _T("-%d"), nValueNum);
  341. strBuffer = AfxGetApp()->GetProfileString(pszSection, strValueName);
  342. if (strBuffer.IsEmpty())
  343. return FALSE;
  344. WINDOWPLACEMENT wp;
  345. int nRead = _stscanf(strBuffer, g_szFormat,
  346. &wp.flags, &wp.showCmd,
  347. &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  348. &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  349. &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  350. &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  351. if (nRead != 10)
  352. return FALSE;
  353. wp.length = sizeof wp;
  354. *pwp = wp;
  355. return TRUE;
  356. } //*** ReadWindowPlacement()
  357. /////////////////////////////////////////////////////////////////////////////
  358. //++
  359. //
  360. // WriteWindowPlacement
  361. //
  362. // Routine Description:
  363. // Write window placement parameters.
  364. //
  365. // Arguments:
  366. // pwp [IN] WINDOWPLACEMENT structure to save.
  367. // pszSection [IN] Section name under which to write data.
  368. // nValueNum [IN] Number of the value to write.
  369. //
  370. // Return Value:
  371. // TRUE Parameters read.
  372. // FALSE Parameters not read.
  373. //
  374. //--
  375. /////////////////////////////////////////////////////////////////////////////
  376. void WriteWindowPlacement(
  377. IN const LPWINDOWPLACEMENT pwp,
  378. IN LPCTSTR pszSection,
  379. IN DWORD nValueNum
  380. )
  381. {
  382. TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
  383. CString strBuffer;
  384. CString strValueName;
  385. if (nValueNum <= 1)
  386. strValueName = REGPARAM_WINDOW_POS;
  387. else
  388. strValueName.Format(REGPARAM_WINDOW_POS _T("-%d"), nValueNum);
  389. wsprintf(szBuffer, g_szFormat,
  390. pwp->flags, pwp->showCmd,
  391. pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  392. pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  393. pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  394. pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  395. AfxGetApp()->WriteProfileString(pszSection, strValueName, szBuffer);
  396. } //*** WriteWindowPlacement()