Leaked source code of windows server 2003
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.

484 lines
14 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 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. int nCreateStatus = -1;
  101. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  102. {
  103. goto Cleanup;
  104. }
  105. if (!m_wndToolBar.Create(this) ||
  106. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  107. {
  108. Trace(g_tagMainFrame, _T("Failed to create toolbar"));
  109. goto Cleanup; // fail to create
  110. }
  111. if (!m_wndStatusBar.Create(this)
  112. || !m_wndStatusBar.SetIndicators(
  113. indicators,
  114. sizeof(indicators)/sizeof(UINT)
  115. ))
  116. {
  117. Trace(g_tagMainFrame, _T("Failed to create status bar"));
  118. goto Cleanup; // fail to create
  119. }
  120. // TODO: Remove this if you don't want tool tips or a resizeable toolbar
  121. m_wndToolBar.SetBarStyle(
  122. m_wndToolBar.GetBarStyle()
  123. | CBRS_TOOLTIPS
  124. | CBRS_FLYBY
  125. | CBRS_SIZE_DYNAMIC
  126. );
  127. // TODO: Delete these three lines if you don't want the toolbar to
  128. // be dockable
  129. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  130. EnableDocking(CBRS_ALIGN_ANY);
  131. DockControlBar(&m_wndToolBar);
  132. // Hide the toolbar and/or status bar is that is the current setting.
  133. {
  134. BOOL bShowToolBar;
  135. BOOL bShowStatusBar;
  136. // Read the settings from the user's profile.
  137. bShowToolBar = AfxGetApp()->GetProfileInt(
  138. REGPARAM_SETTINGS,
  139. REGPARAM_SHOW_TOOL_BAR,
  140. TRUE
  141. );
  142. bShowStatusBar = AfxGetApp()->GetProfileInt(
  143. REGPARAM_SETTINGS,
  144. REGPARAM_SHOW_STATUS_BAR,
  145. TRUE
  146. );
  147. // Show or hide the toolbar and status bar.
  148. m_wndToolBar.ShowWindow(bShowToolBar);
  149. m_wndStatusBar.ShowWindow(bShowStatusBar);
  150. } // Hide the toolbar and/or status bar is that is the current setting
  151. nCreateStatus = 0;
  152. Cleanup:
  153. return nCreateStatus;
  154. } //*** CMainFrame::OnCreate()
  155. /////////////////////////////////////////////////////////////////////////////
  156. //++
  157. //
  158. // CMainFrame::GetMessageString
  159. //
  160. // Routine Description:
  161. // Get a string for a command ID.
  162. //
  163. // Arguments:
  164. // nID [IN] Command ID for which a string should be returned.
  165. // rMessage [OUT] String in which to return the message.
  166. //
  167. // Return Value:
  168. // None.
  169. //
  170. //--
  171. /////////////////////////////////////////////////////////////////////////////
  172. void CMainFrame::GetMessageString(UINT nID, CString& rMessage) const
  173. {
  174. CFrameWnd * pframe;
  175. // Pass off to the active MDI child frame window, if there is one.
  176. pframe = MDIGetActive();
  177. if (pframe == NULL)
  178. {
  179. CMDIFrameWnd::GetMessageString(nID, rMessage);
  180. }
  181. else
  182. {
  183. pframe->GetMessageString(nID, rMessage);
  184. }
  185. } //*** CMainFrame::GetMessageString()
  186. /////////////////////////////////////////////////////////////////////////////
  187. // CMainFrame diagnostics
  188. /////////////////////////////////////////////////////////////////////////////
  189. #ifdef _DEBUG
  190. void CMainFrame::AssertValid(void) const
  191. {
  192. CMDIFrameWnd::AssertValid();
  193. } //*** CMainFrame::AssertValid()
  194. void CMainFrame::Dump(CDumpContext& dc) const
  195. {
  196. CMDIFrameWnd::Dump(dc);
  197. } //*** CMainFrame::Dump()
  198. #endif //_DEBUG
  199. /////////////////////////////////////////////////////////////////////////////
  200. //++
  201. //
  202. // CMainFrame::OnClusterNotify
  203. //
  204. // Routine Description:
  205. // Handler for the WM_CAM_CLUSTER_NOTIFY message.
  206. // Processes cluster notifications.
  207. //
  208. // Arguments:
  209. // None.
  210. //
  211. // Return Value:
  212. // Value returned from the application method.
  213. //
  214. //--
  215. /////////////////////////////////////////////////////////////////////////////
  216. void CMainFrame::OnClose(void)
  217. {
  218. // Save the current window position and size.
  219. {
  220. WINDOWPLACEMENT wp;
  221. wp.length = sizeof wp;
  222. if (GetWindowPlacement(&wp))
  223. {
  224. wp.flags = 0;
  225. if (IsZoomed())
  226. {
  227. wp.flags |= WPF_RESTORETOMAXIMIZED;
  228. }
  229. if (IsIconic())
  230. {
  231. wp.showCmd = SW_SHOWMINNOACTIVE;
  232. }
  233. // and write it to the .INI file
  234. WriteWindowPlacement(&wp, REGPARAM_SETTINGS, 0);
  235. } // if: window placement retrieved successfully
  236. } // Save the current window position and size
  237. // Save the current connections.
  238. GetClusterAdminApp()->SaveConnections();
  239. // Save the current toolbar and status bar show state.
  240. AfxGetApp()->WriteProfileInt(
  241. REGPARAM_SETTINGS,
  242. REGPARAM_SHOW_TOOL_BAR,
  243. ((m_wndToolBar.GetStyle() & WS_VISIBLE) ? TRUE : FALSE)
  244. );
  245. AfxGetApp()->WriteProfileInt(
  246. REGPARAM_SETTINGS,
  247. REGPARAM_SHOW_STATUS_BAR,
  248. ((m_wndStatusBar.GetStyle() & WS_VISIBLE) ? TRUE : FALSE)
  249. );
  250. CMDIFrameWnd::OnClose();
  251. } //*** CMainFrame::OnClose()
  252. /////////////////////////////////////////////////////////////////////////////
  253. //++
  254. //
  255. // CMainFrame::OnRestoreDesktop
  256. //
  257. // Routine Description:
  258. // Handler for the WM_CAM_RESTORE_DESKTOP message.
  259. // Restores the desktop from the saved parameters.
  260. //
  261. // Arguments:
  262. // wparam 1st parameter.
  263. // lparam 2nd parameter.
  264. //
  265. // Return Value:
  266. // Value returned from the application method.
  267. //
  268. //--
  269. /////////////////////////////////////////////////////////////////////////////
  270. LRESULT CMainFrame::OnRestoreDesktop(WPARAM wparam, LPARAM lparam)
  271. {
  272. // Call this method on the application.
  273. return GetClusterAdminApp()->OnRestoreDesktop(wparam, lparam);
  274. } //*** CMainFrame::OnRestoreDesktop()
  275. /////////////////////////////////////////////////////////////////////////////
  276. //++
  277. //
  278. // CMainFrame::OnClusterNotify
  279. //
  280. // Routine Description:
  281. // Handler for the WM_CAM_CLUSTER_NOTIFY message.
  282. // Processes cluster notifications.
  283. //
  284. // Arguments:
  285. // wparam 1st parameter.
  286. // lparam 2nd parameter.
  287. //
  288. // Return Value:
  289. // Value returned from the application method.
  290. //
  291. //--
  292. /////////////////////////////////////////////////////////////////////////////
  293. LRESULT CMainFrame::OnClusterNotify(WPARAM wparam, LPARAM lparam)
  294. {
  295. CClusterAdminApp * papp = GetClusterAdminApp();
  296. // Call this method on the application.
  297. return papp->OnClusterNotify(wparam, lparam);
  298. } //*** CMainFrame::OnClusterNotify()
  299. /////////////////////////////////////////////////////////////////////////////
  300. //++
  301. //
  302. // CMainFrame::OnHelp
  303. //
  304. // Routine Description:
  305. // Handler for the IDM_HELP_FINDER menu command.
  306. //
  307. // Arguments:
  308. // None.
  309. //
  310. // Return Value:
  311. // None.
  312. //
  313. //--
  314. /////////////////////////////////////////////////////////////////////////////
  315. void CMainFrame::OnHelp(void)
  316. {
  317. HtmlHelpW( m_hWnd, _T("MSCSConcepts.chm"), HH_DISPLAY_TOPIC, 0L );
  318. } //*** CMainFrame::OnHelp()
  319. //*************************************************************************//
  320. /////////////////////////////////////////////////////////////////////////////
  321. // Helpers for saving/restoring window state
  322. static TCHAR g_szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  323. /////////////////////////////////////////////////////////////////////////////
  324. //++
  325. //
  326. // ReadWindowPlacement
  327. //
  328. // Routine Description:
  329. // Read window placement parameters.
  330. //
  331. // Arguments:
  332. // pwp [OUT] WINDOWPLACEMENT structure to fill.
  333. // pszSection [IN] Section name under which to read data.
  334. // nValueNum [IN] Number of the value to read.
  335. //
  336. // Return Value:
  337. // TRUE Parameters read.
  338. // FALSE Parameters not read.
  339. //
  340. //--
  341. /////////////////////////////////////////////////////////////////////////////
  342. BOOL ReadWindowPlacement(
  343. OUT LPWINDOWPLACEMENT pwp,
  344. IN LPCTSTR pszSection,
  345. IN DWORD nValueNum
  346. )
  347. {
  348. CString strBuffer;
  349. CString strValueName;
  350. BOOL bParametersRead = FALSE;
  351. if (nValueNum <= 1)
  352. {
  353. strValueName = REGPARAM_WINDOW_POS;
  354. }
  355. else
  356. {
  357. strValueName.Format(REGPARAM_WINDOW_POS _T("-%d"), nValueNum);
  358. }
  359. strBuffer = AfxGetApp()->GetProfileString(pszSection, strValueName);
  360. if (strBuffer.IsEmpty())
  361. {
  362. goto Cleanup;
  363. }
  364. WINDOWPLACEMENT wp;
  365. int nRead = _stscanf(strBuffer, g_szFormat,
  366. &wp.flags, &wp.showCmd,
  367. &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  368. &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  369. &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  370. &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  371. if (nRead != 10)
  372. {
  373. goto Cleanup;
  374. }
  375. wp.length = sizeof wp;
  376. *pwp = wp;
  377. bParametersRead = TRUE;
  378. Cleanup:
  379. return bParametersRead;
  380. } //*** ReadWindowPlacement()
  381. /////////////////////////////////////////////////////////////////////////////
  382. //++
  383. //
  384. // WriteWindowPlacement
  385. //
  386. // Routine Description:
  387. // Write window placement parameters.
  388. //
  389. // Arguments:
  390. // pwp [IN] WINDOWPLACEMENT structure to save.
  391. // pszSection [IN] Section name under which to write data.
  392. // nValueNum [IN] Number of the value to write.
  393. //
  394. // Return Value:
  395. // TRUE Parameters read.
  396. // FALSE Parameters not read.
  397. //
  398. //--
  399. /////////////////////////////////////////////////////////////////////////////
  400. void WriteWindowPlacement(
  401. IN const LPWINDOWPLACEMENT pwp,
  402. IN LPCTSTR pszSection,
  403. IN DWORD nValueNum
  404. )
  405. {
  406. TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
  407. CString strBuffer;
  408. CString strValueName;
  409. HRESULT hr;
  410. if (nValueNum <= 1)
  411. strValueName = REGPARAM_WINDOW_POS;
  412. else
  413. strValueName.Format(REGPARAM_WINDOW_POS _T("-%d"), nValueNum);
  414. hr = StringCchPrintf(szBuffer, RTL_NUMBER_OF( szBuffer ), g_szFormat,
  415. pwp->flags, pwp->showCmd,
  416. pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  417. pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  418. pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  419. pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  420. AfxGetApp()->WriteProfileString(pszSection, strValueName, szBuffer);
  421. } //*** WriteWindowPlacement()