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.

327 lines
10 KiB

  1. /*****************************************************************************
  2. *
  3. * $Workfile: CfgAll.cpp $
  4. *
  5. * Copyright (C) 1997 Hewlett-Packard Company.
  6. * Copyright (c) 1997 Microsoft Corporation.
  7. * All rights reserved.
  8. *
  9. * 11311 Chinden Blvd.
  10. * Boise, Idaho 83714
  11. *
  12. *****************************************************************************/
  13. /*
  14. * Author: Becky Jacobsen
  15. *
  16. * This file contains the dialog for configuring an existing port for the port monitor.
  17. */
  18. #include "precomp.h"
  19. #include "CoreUI.h"
  20. #include "resource.h" // includes the definitions for the resources
  21. #include "RTcpData.h"
  22. #include "CfgAll.h" // includes the application-specific information
  23. #include "TcpMonUI.h"
  24. // Global variables:
  25. extern HINSTANCE g_hInstance;
  26. //
  27. // FUNCTION: AllPortsPage(HWND, UINT, UINT, LONG)
  28. //
  29. // PURPOSE: To process messages from the page for configuring all
  30. // the tcp monitor ports in the system.
  31. //
  32. // MESSAGES:
  33. //
  34. // WM_INITDIALOG - intializes the page
  35. // WM_COMMAND - handle button clicks
  36. // WM_NOTIFY - handle reset
  37. // WM_HSCROLL - handle scroll events from the 2 trackbars
  38. //
  39. BOOL APIENTRY AllPortsPage(HWND hDlg,
  40. UINT message,
  41. WPARAM wParam,
  42. LPARAM lParam)
  43. {
  44. CAllPortsPage *wndDlg = NULL;
  45. wndDlg = (CAllPortsPage *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  46. switch(message)
  47. {
  48. case WM_INITDIALOG:
  49. wndDlg = (CAllPortsPage *) new CAllPortsPage;
  50. if( wndDlg == NULL )
  51. return( FALSE );
  52. SetWindowLongPtr(hDlg, GWLP_USERDATA, (UINT_PTR)wndDlg);
  53. wndDlg->OnInitDialog(hDlg, wParam, lParam);
  54. break;
  55. case WM_COMMAND:
  56. wndDlg->OnCommand(hDlg, wParam, lParam);
  57. break;
  58. case WM_NOTIFY:
  59. return wndDlg->OnWMNotify(hDlg, wParam, lParam);
  60. break;
  61. case WM_HSCROLL:
  62. wndDlg->OnHscroll(hDlg, wParam, lParam);
  63. break;
  64. case WM_HELP:
  65. OnHelp(IDD_DIALOG_CONFIG_ALL, hDlg, lParam);
  66. break;
  67. case WM_DESTROY:
  68. delete wndDlg;
  69. break;
  70. default:
  71. return FALSE;
  72. }
  73. return TRUE;
  74. } // AllPortsPage
  75. //
  76. // FUNCTION: CAllPortsPage Constructor
  77. //
  78. // PURPOSE:
  79. //
  80. CAllPortsPage::CAllPortsPage()
  81. {
  82. } // Constructor
  83. //
  84. // FUNCTION: OnInitDialog(HWND hDlg)
  85. //
  86. // PURPOSE: To initialize the allports dialog. Calls SetupTrackBar for each dialog
  87. // and checks or unchecks the Status Update enabled check box as appropriate.
  88. //
  89. BOOL CAllPortsPage::OnInitDialog(HWND hDlg,
  90. WPARAM,
  91. LPARAM lParam)
  92. {
  93. m_pParams = (CFG_PARAM_PACKAGE *) ((PROPSHEETPAGE *) lParam)->lParam;
  94. SetupTrackBar(hDlg, IDC_TRACKBAR_FAILURE_TIMEOUT, IDC_TRACKBAR_TOP, FT_MIN, FT_MAX, m_pParams->pData->FailureTimeout, FT_PAGESIZE, IDC_DIGITAL_FAILURE_TIMEOUT);
  95. SendMessage(GetDlgItem(hDlg, IDC_CHECK_STATUSUPDATE), BM_SETCHECK, (WPARAM)BST_CHECKED, (LPARAM)0);
  96. if(m_pParams->pData->SUEnabled == FALSE) {
  97. // EnableStatusUpdate(hDlg, FALSE);
  98. CheckDlgButton(hDlg, IDC_CHECK_STATUSUPDATE, BST_UNCHECKED);
  99. } else {
  100. CheckDlgButton(hDlg, IDC_CHECK_STATUSUPDATE, BST_CHECKED);
  101. }
  102. return TRUE;
  103. } // OnAllPortsInitDialog
  104. //
  105. // FUNCTION: OnCommand
  106. //
  107. // PURPOSE: To process windows WM_COMMAND messages
  108. //
  109. BOOL CAllPortsPage::OnCommand(HWND hDlg,
  110. WPARAM wParam,
  111. LPARAM lParam)
  112. {
  113. if(HIWORD(wParam) == BN_CLICKED) {
  114. // a button is being clicked.
  115. OnBnClicked(hDlg, wParam, lParam);
  116. }
  117. return TRUE;
  118. } // OnCommand
  119. //
  120. // FUNCTION: OnWMNotify
  121. //
  122. // PURPOSE: This function is called by the page in response to a WM_NOTIFY message.
  123. //
  124. // lParam - second message parameter of the WM_NOTIFY message
  125. //
  126. BOOL CAllPortsPage::OnWMNotify(HWND hDlg, WPARAM, LPARAM lParam)
  127. {
  128. switch(((NMHDR FAR *) lParam)->code) {
  129. case PSN_APPLY:
  130. //
  131. // The settings will be written by the apply in cfgport.cpp
  132. // OnOk(hDlg);
  133. break;
  134. case PSN_SETACTIVE:
  135. {
  136. }
  137. break;
  138. case PSN_RESET:
  139. {
  140. }
  141. break;
  142. case PSN_QUERYCANCEL:
  143. m_pParams->dwLastError = ERROR_CANCELLED;
  144. return FALSE;
  145. break;
  146. default:
  147. break;// do nothing
  148. }
  149. return TRUE;
  150. } // OnWMNotify
  151. //
  152. // FUNCTION: OnHscroll(HWND hDlg, WPARAM wParam, LPARAM lParam)
  153. //
  154. // PURPOSE: To set the Digital Readout window text when either of the
  155. // trackbar thumbs are moved by the user.
  156. //
  157. void CAllPortsPage::OnHscroll(HWND hDlg,
  158. WPARAM wParam,
  159. LPARAM lParam)
  160. {
  161. TCHAR strValue[15] = NULLSTR;
  162. long idTrackbar = 0;
  163. long idDigitalReadout = 0;
  164. // I need the child window ID of this trackbar to get the id
  165. // of the corresponding static display control.
  166. idTrackbar = GetWindowLong((HWND)lParam, GWL_ID);
  167. if(idTrackbar == IDC_TRACKBAR_FAILURE_TIMEOUT) {
  168. idDigitalReadout = IDC_DIGITAL_FAILURE_TIMEOUT;
  169. }
  170. switch(LOWORD(wParam)) // loword of wparam is the notification code.
  171. {
  172. case TB_BOTTOM: // VK_END
  173. case TB_ENDTRACK: // WM_KEYUP (the user released a key that sent a relevant virtual-key code)
  174. case TB_LINEDOWN: // VK_RIGHT or VK_DOWN
  175. case TB_LINEUP: // VK_LEFT or VK_UP
  176. case TB_PAGEDOWN: // VK_NEXT (the user clicked the channel below or to the right of the slider)
  177. case TB_PAGEUP: // VK_PRIOR (the user clicked the channel above or to the left of the slider)
  178. case TB_TOP: // VK_HOME
  179. {
  180. int iPosition = SendMessage(GetDlgItem(hDlg, idTrackbar), TBM_GETPOS, 0, 0);
  181. if(idTrackbar == IDC_TRACKBAR_FAILURE_TIMEOUT)
  182. {
  183. m_pParams->pData->FailureTimeout = iPosition;
  184. }
  185. _stprintf(strValue, TEXT("%d"), iPosition);
  186. }
  187. break;
  188. case TB_THUMBPOSITION: // WM_LBUTTONUP following a TB_THUMBTRACK notification message
  189. {
  190. // this is the only case where we don't have to do anything.
  191. // int iPosition = HIWORD(wParam);
  192. }
  193. break;
  194. case TB_THUMBTRACK: // Slider movement (the user dragged the slider)
  195. {
  196. int iPosition = HIWORD(wParam);
  197. if(idTrackbar == IDC_TRACKBAR_FAILURE_TIMEOUT)
  198. {
  199. m_pParams->pData->FailureTimeout = iPosition;
  200. }
  201. _stprintf(strValue, TEXT("%d"), iPosition);
  202. }
  203. break;
  204. default:
  205. break;
  206. }
  207. SetWindowText(GetDlgItem(hDlg, idDigitalReadout), strValue);
  208. } // OnHscroll
  209. //
  210. // FUNCTION: OnBnClicked(HWND hDlg, WPARAM wParam, LPARAM lParam)
  211. //
  212. // PURPOSE: When the enable Status Update checkbox is checked or unchecked
  213. // the status update controls are enabled or disabled respectively.
  214. //
  215. void CAllPortsPage::OnBnClicked(HWND hDlg, WPARAM wParam, LPARAM lParam)
  216. {
  217. if(LOWORD(wParam) == IDC_CHECK_STATUSUPDATE) {
  218. // the Enable Status Update button was clicked.
  219. UINT state = IsDlgButtonChecked(hDlg, LOWORD(wParam));
  220. if(state == BST_UNCHECKED) {
  221. m_pParams->pData->SUEnabled = FALSE;
  222. } else {
  223. m_pParams->pData->SUEnabled = TRUE;
  224. }
  225. }
  226. } // OnBnClicked
  227. //
  228. // FUNCTION: SetupTrackBar(...)
  229. //
  230. // PURPOSE: To get the window position, create the track bar and setup it's range
  231. // and current thumb position.
  232. //
  233. // Arguments: hDlg is the dialog box that will be the parent of the track bar.
  234. // iChildWindowID is the id given to the Track Bar
  235. // iPositionCtrl is the id of a picture frame on the dialog that will
  236. // be used to position the track bar.
  237. // iRangeMin is the minimum value the track bar can be set to.
  238. // iRangeMax is the maximum value the track bar can be set to.
  239. // lPosition is the current thumb position.
  240. // lPageSize is the amount the thumb will jump by when the user clicks
  241. // on the track bar instead of dragging the thumb around.
  242. // iAssociatedDigitalReadout is the static text control that displays
  243. // the current value the thumb is indicating.
  244. // hToolTip is the tool tip control to register a tool tip with.
  245. //
  246. void CAllPortsPage::SetupTrackBar(HWND hDlg,
  247. int iChildWindowID,
  248. int iPositionCtrl,
  249. int iRangeMin,
  250. int iRangeMax,
  251. long lPosition,
  252. long lPageSize,
  253. int iAssociatedDigitalReadout)
  254. {
  255. HWND hTrackBar = NULL;
  256. RECT r;
  257. POINT pt1;
  258. POINT pt2;
  259. GetWindowRect(GetDlgItem(hDlg, iPositionCtrl), &r);
  260. pt1.x = r.left;
  261. pt1.y = r.top;
  262. pt2.x = r.right;
  263. pt2.y = r.bottom;
  264. ScreenToClient(hDlg, &pt1);
  265. ScreenToClient(hDlg, &pt2);
  266. hTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, TEXT(""), WS_VISIBLE | WS_CHILD | WS_GROUP | WS_TABSTOP |
  267. TBS_HORZ, pt1.x, pt1.y, pt2.x - pt1.x,
  268. pt2.y - pt1.y, hDlg, (HMENU)iChildWindowID, g_hInstance, NULL);
  269. SendMessage(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(iRangeMin, iRangeMax));
  270. SendMessage(hTrackBar, TBM_SETPAGESIZE, 0, lPageSize);
  271. SendMessage(hTrackBar, TBM_SETPOS, TRUE, lPosition);
  272. TCHAR strValue[5];
  273. _stprintf(strValue, TEXT("%d"), lPosition);
  274. SetWindowText(GetDlgItem(hDlg, iAssociatedDigitalReadout), strValue);
  275. } // SetupTrackBar