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.

326 lines
8.5 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*******************************************************************************
  3. *
  4. * mainfrm.cpp
  5. *
  6. * implementation of CMainFrame class
  7. *
  8. * copyright notice: Copyright 1994, Citrix Systems Inc.
  9. *
  10. * $Author: butchd $ Butch Davis
  11. *
  12. * $Log: N:\NT\PRIVATE\UTILS\CITRIX\WINUTILS\WINCFG\VCS\MAINFRM.CPP $
  13. *
  14. * Rev 1.5 27 Sep 1996 17:52:30 butchd
  15. * update
  16. *
  17. * Rev 1.4 24 Sep 1996 16:21:46 butchd
  18. * update
  19. *
  20. *******************************************************************************/
  21. #include "stdafx.h"
  22. #include "wincfg.h"
  23. #include "mainfrm.h"
  24. #include "appsvdoc.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char BASED_CODE THIS_FILE[] = __FILE__;
  28. #endif
  29. extern CWincfgApp *pApp;
  30. /*
  31. * Global command line variables.
  32. */
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMainFrame class implementation / construction, destruction
  35. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  36. /*******************************************************************************
  37. *
  38. * CMainFrame - CMainFrame constructor
  39. *
  40. * ENTRY:
  41. * EXIT:
  42. *
  43. ******************************************************************************/
  44. CMainFrame::CMainFrame()
  45. {
  46. } // end CMainFrame::CMainFrame
  47. /*******************************************************************************
  48. *
  49. * ~CMainFrame - CMainFrame destructor
  50. *
  51. * ENTRY:
  52. * EXIT:
  53. *
  54. ******************************************************************************/
  55. CMainFrame::~CMainFrame()
  56. {
  57. pApp->Terminate();
  58. } // end CMainFrame::~CMainFrame
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CMainFrame debug diagnostics
  61. #ifdef _DEBUG
  62. void CMainFrame::AssertValid() const
  63. {
  64. CFrameWnd::AssertValid();
  65. }
  66. void CMainFrame::Dump(CDumpContext& dc) const
  67. {
  68. CFrameWnd::Dump(dc);
  69. }
  70. #endif //_DEBUG
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CMainFrame Overrides of MFC CFrameWnd class
  73. /*******************************************************************************
  74. *
  75. * ActivateFrame - CMainFrame member function: override
  76. *
  77. * Place and show the main frame window.
  78. *
  79. * ENTRY:
  80. * nCmdShow (input)
  81. * Default application 'show' state.
  82. *
  83. * EXIT:
  84. *
  85. ******************************************************************************/
  86. void
  87. CMainFrame::ActivateFrame(int nCmdShow)
  88. {
  89. if ( g_Batch ) {
  90. /*
  91. * Always hide our main window if we're in batch mode.
  92. */
  93. ShowWindow(SW_HIDE);
  94. } else {
  95. if ( pApp->m_Placement.length == -1 ) {
  96. /*
  97. * This is the first time that this is called, set the window
  98. * placement and show state to the previously saved state.
  99. */
  100. pApp->m_Placement.length = sizeof(pApp->m_Placement);
  101. /*
  102. * If we're in batch mode, make window hidden.
  103. */
  104. if ( g_Batch )
  105. nCmdShow = SW_HIDE;
  106. /*
  107. * If we have a previously saved placement state: set it.
  108. */
  109. if ( pApp->m_Placement.rcNormalPosition.right != -1 ) {
  110. if ( nCmdShow != SW_SHOWNORMAL )
  111. pApp->m_Placement.showCmd = nCmdShow;
  112. else
  113. nCmdShow = pApp->m_Placement.showCmd;
  114. SetWindowPlacement(&(pApp->m_Placement));
  115. }
  116. }
  117. /*
  118. * Perform the parent classes' ActivateFrame().
  119. */
  120. CFrameWnd::ActivateFrame(nCmdShow);
  121. }
  122. } // end CMainFrame::ActivateFrame
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CMainFrame message map
  125. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  126. //{{AFX_MSG_MAP(CMainFrame)
  127. //ON_WM_CLOSE()
  128. ON_WM_INITMENUPOPUP()
  129. ON_WM_SYSCOMMAND()
  130. ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateAppExit)
  131. ON_MESSAGE(WM_ADDWINSTATION, OnAddWinstation)
  132. //}}AFX_MSG_MAP
  133. END_MESSAGE_MAP()
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CMainFrame message handlers
  136. /*******************************************************************************
  137. *
  138. * OnClose - CMainFrame member function: command
  139. *
  140. * Save application defaults and clean-up, then perform default
  141. * OnClose
  142. *
  143. * ENTRY:
  144. * EXIT:
  145. * (refer to the CWnd::OnClose documentation)
  146. *
  147. ******************************************************************************/
  148. //void
  149. //CMainFrame::OnClose()
  150. //{
  151. /*
  152. * Call CWinquery::Terminate member function to save application defaults
  153. * and clean-up.
  154. */
  155. // pApp->Terminate();
  156. /*
  157. * Call the default OnClose() member function.
  158. */
  159. //CFrameWnd::OnClose();
  160. //} // end CMainFrame::OnClose
  161. /*******************************************************************************
  162. *
  163. * OnInitMenuPopup - CMainFrame member function: command
  164. *
  165. * When the system control menu is about to be displayed, set the state of
  166. * the "close" item to allow or disallow closing the application.
  167. *
  168. * ENTRY:
  169. * EXIT:
  170. * (refer to the CWnd::OnInitMenuPopup documentation)
  171. *
  172. ******************************************************************************/
  173. void
  174. CMainFrame::OnInitMenuPopup( CMenu* pPopupMenu,
  175. UINT nIndex,
  176. BOOL bSysMenu )
  177. {
  178. /*
  179. * Call the parent classes OnInitMenuPopup first.
  180. */
  181. CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  182. /*
  183. * If this is the system menu, enable or disable the Close menu item based
  184. * on whether our current document says that we can exit.
  185. */
  186. if ( bSysMenu )
  187. pPopupMenu->EnableMenuItem( SC_CLOSE, MF_BYCOMMAND |
  188. (((CAppServerDoc *)GetActiveDocument())->IsExitAllowed() ? MF_ENABLED : MF_GRAYED) );
  189. } // end CMainFrame::OnInitMenuPopup
  190. /*******************************************************************************
  191. *
  192. * OnSysCommand - CMainFrame member function: command
  193. *
  194. * In case the user presses the ALT-F4 accelerator key, which can't be
  195. * disabled in the OnUpdateAppExit() and OnInitMenuPopup() command
  196. * functions.
  197. *
  198. * ENTRY:
  199. * EXIT:
  200. * (refer to the CWnd::OnSysCommand documentation)
  201. *
  202. ******************************************************************************/
  203. void
  204. CMainFrame::OnSysCommand( UINT nId,
  205. LPARAM lParam )
  206. {
  207. /*
  208. * If this is the SC_CLOSE command and exiting is not allowed, return.
  209. */
  210. if ( (nId == SC_CLOSE) &&
  211. !((CAppServerDoc *)GetActiveDocument())->IsExitAllowed() )
  212. return;
  213. /*
  214. * Call the parent classes OnSysCommand() function.
  215. */
  216. CFrameWnd::OnSysCommand( nId, lParam );
  217. } // end CMainFrame::OnSysCommand
  218. /*******************************************************************************
  219. *
  220. * OnUpdateAppExit - CMainFrame member function: command
  221. *
  222. * Enables or disables the "exit" command item based on whether or not
  223. * we're allowed to close the application.
  224. *
  225. * ENTRY:
  226. * pCmdUI (input)
  227. * Points to the CCmdUI object of the "exit" command item.
  228. *
  229. * EXIT:
  230. *
  231. ******************************************************************************/
  232. void
  233. CMainFrame::OnUpdateAppExit(CCmdUI* pCmdUI)
  234. {
  235. pCmdUI->Enable( ((CAppServerDoc *)GetActiveDocument())->IsExitAllowed() ? TRUE : FALSE );
  236. } // end CMainFrame::OnUpdateAppExit
  237. /*******************************************************************************
  238. *
  239. * OnAddWinstation - CMainFrame member function: command
  240. *
  241. * Perform batch-mode add of winstation(s).
  242. *
  243. * ENTRY:
  244. * wParam (input)
  245. * WPARAM associated with the window message: not used.
  246. * wLparam (input)
  247. * LPARAM associated with the window message: not used.
  248. *
  249. * EXIT:
  250. * (LRESULT) always returns 0 to indicate operation complete.
  251. *
  252. ******************************************************************************/
  253. LRESULT
  254. CMainFrame::OnAddWinstation( WPARAM wParam,
  255. LPARAM lParam )
  256. {
  257. /*
  258. * Call AddWinStation() in document to perform the add operation. If the
  259. * add failed in any way (index <= 0), post a WM_CLOSE message
  260. * to ourself so that we go away. Sucessful add will be closed when final
  261. * add operaion completes (in the document's OperationDone() function).
  262. */
  263. if ( ((CAppServerDoc *)GetActiveDocument())->AddWinStation(0) <= 0 )
  264. PostMessage(WM_CLOSE);
  265. return(0);
  266. } // end CMainFrame::OnAddWinstation
  267. /////////////////////////////////////////////////////////////////////////////