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.

330 lines
8.6 KiB

  1. /*****************************************************************************
  2. *
  3. * $Workfile: AddMulti.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. #include "precomp.h"
  14. #include "UIMgr.h"
  15. #include "DevPort.h"
  16. #include "AddMulti.h"
  17. #include "Resource.h"
  18. #include "MibABC.h"
  19. #include "TcpMonUI.h"
  20. //
  21. // FUNCTION: CMultiPortDlg constructor
  22. //
  23. // PURPOSE: initialize a CMultiPortDlg class
  24. //
  25. CMultiPortDlg::CMultiPortDlg() : m_DPList( )
  26. {
  27. memset(&m_PortDataStandard, 0, sizeof(m_PortDataStandard));
  28. memset(m_szCurrentSelection, '\0', sizeof( m_szCurrentSelection ));
  29. } // constructor
  30. //
  31. // FUNCTION: CMultiPortDlg destructor
  32. //
  33. // PURPOSE: deinitialize a CMultiPortDlg class
  34. //
  35. CMultiPortDlg::~CMultiPortDlg()
  36. {
  37. } // destructor
  38. //
  39. // FUNCTION: MoreInfoDialog(HWND, UINT, WPARAM, LPARAM)
  40. //
  41. // PURPOSE: To process messages from the summary dialog for adding a port.
  42. //
  43. // MESSAGES:
  44. //
  45. // WM_INITDIALOG - intializes the page
  46. // WM_COMMAND - handles button presses and text changes in edit controls.
  47. //
  48. //
  49. INT_PTR CALLBACK MultiPortDialog(
  50. HWND hDlg,
  51. UINT message,
  52. WPARAM wParam,
  53. LPARAM lParam)
  54. {
  55. CMultiPortDlg *wndDlg = NULL;
  56. wndDlg = (CMultiPortDlg *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  57. switch (message)
  58. {
  59. case WM_INITDIALOG:
  60. wndDlg = new CMultiPortDlg;
  61. if( wndDlg == NULL )
  62. return( FALSE );
  63. SetWindowLongPtr(hDlg, GWLP_USERDATA, (UINT_PTR)wndDlg);
  64. return wndDlg->OnInitDialog(hDlg, wParam, lParam);
  65. break;
  66. case WM_COMMAND:
  67. return wndDlg->OnCommand(hDlg, wParam, lParam);
  68. break;
  69. case WM_NOTIFY:
  70. return wndDlg->OnNotify(hDlg, wParam, lParam);
  71. break;
  72. case WM_DESTROY:
  73. delete wndDlg;
  74. break;
  75. default:
  76. return FALSE;
  77. }
  78. return TRUE;
  79. } // AddPortDialog
  80. //
  81. // FUNCTION: OnInitDialog(HWND hDlg)
  82. //
  83. // PURPOSE: Initialize the dialog.
  84. //
  85. BOOL CMultiPortDlg::OnInitDialog(HWND hDlg, WPARAM, LPARAM lParam)
  86. {
  87. m_pParams = (ADD_PARAM_PACKAGE *) ((PROPSHEETPAGE *) lParam)->lParam;
  88. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_DEVICES), TRUE);
  89. return TRUE;
  90. } // OnInitDialog
  91. //
  92. // FUNCTION: OnCommand()
  93. //
  94. // PURPOSE: Process WM_COMMAND message
  95. //
  96. BOOL CMultiPortDlg::OnCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
  97. {
  98. switch(HIWORD(wParam)) {
  99. case LBN_SELCHANGE:
  100. return OnSelChange(hDlg, wParam, lParam);
  101. break;
  102. default:
  103. return FALSE;
  104. break;
  105. }
  106. return TRUE;
  107. } // OnCommand
  108. //
  109. // FUNCTION: OnSelChange()
  110. //
  111. // PURPOSE: Process WM_COMMAND's LBN_SELCHANGE message
  112. //
  113. BOOL CMultiPortDlg::OnSelChange(HWND hDlg,
  114. WPARAM wParam,
  115. LPARAM lParam)
  116. {
  117. // The selection in the combo box changed.
  118. HWND hwndComboBox = NULL; // handle of list box
  119. hwndComboBox = (HWND) lParam;
  120. GetPrinterData(hwndComboBox, m_pParams->pData->sztHostAddress);
  121. return TRUE;
  122. } // OnSelChange
  123. //
  124. // FUNCTION: GetPrinterData(HWND hwndControl, BOOL *Unknown)
  125. //
  126. // PURPOSE: Gets the socket number of the selected item.
  127. //
  128. // Arguments: hwndControl is the handle of the combo box.
  129. //
  130. // Return Value: Returns the socket number associated with the selected item
  131. //
  132. void CMultiPortDlg::GetPrinterData(HWND hwndControl,
  133. LPCTSTR pszAddress
  134. )
  135. {
  136. LRESULT iSelectedIndex = 0;
  137. CDevicePort *pPortInfo = NULL;
  138. iSelectedIndex = SendMessage(hwndControl,
  139. CB_GETCURSEL,
  140. (WPARAM)0,
  141. (LPARAM)0);
  142. pPortInfo = (CDevicePort *) SendMessage(hwndControl,
  143. CB_GETITEMDATA,
  144. (WPARAM)iSelectedIndex,
  145. (LPARAM)0);
  146. if( (DWORD_PTR)pPortInfo != CB_ERR) {
  147. pPortInfo->ReadPortInfo( pszAddress, &m_PortDataStandard, m_pParams->bBypassNetProbe);
  148. lstrcpyn( m_szCurrentSelection, pPortInfo->GetName(), MAX_SECTION_NAME);
  149. } else {
  150. m_PortDataStandard.dwPortNumber = DEFAULT_PORT_NUMBER;
  151. lstrcpyn(m_PortDataStandard.sztSNMPCommunity, DEFAULT_SNMP_COMUNITY, MAX_SNMP_COMMUNITY_STR_LEN);
  152. m_PortDataStandard.dwSNMPDevIndex = 1;
  153. }
  154. } // GetPrinterData
  155. //
  156. // FUNCTION: OnNotify()
  157. //
  158. // PURPOSE: Process WM_NOTIFY message
  159. //
  160. BOOL CMultiPortDlg::OnNotify(HWND hDlg, WPARAM wParam, LPARAM lParam)
  161. {
  162. switch (((NMHDR FAR *) lParam)->code) {
  163. case PSN_KILLACTIVE:
  164. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  165. return TRUE;
  166. break;
  167. case PSN_RESET:
  168. // reset to the original values
  169. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  170. break;
  171. case PSN_SETACTIVE:
  172. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT | PSWIZB_BACK);
  173. OnSetActive(hDlg);
  174. break;
  175. case PSN_WIZBACK:
  176. if ( m_pParams->dwDeviceType == SUCCESS_DEVICE_MULTI_PORT ) {
  177. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_DIALOG_ADDPORT);
  178. } else {
  179. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_DIALOG_MORE_INFO);
  180. }
  181. memcpy( m_pParams->pData, &m_PortDataStandard, sizeof(PORT_DATA_1) );
  182. break;
  183. case PSN_WIZNEXT:
  184. // the Next button was pressed
  185. memcpy( m_pParams->pData, &m_PortDataStandard, sizeof(PORT_DATA_1) );
  186. return FALSE;
  187. break;
  188. case PSN_QUERYCANCEL:
  189. m_pParams->dwLastError = ERROR_CANCELLED;
  190. return FALSE;
  191. break;
  192. default:
  193. return FALSE;
  194. }
  195. return TRUE;
  196. } // OnCommand
  197. //
  198. // FUNCTION: OnSetActive()
  199. //
  200. // PURPOSE: Process PSN_SETACTIVE part of the WM_NOTIFY message
  201. //
  202. void CMultiPortDlg::OnSetActive(HWND hDlg)
  203. {
  204. TCHAR sztMoreInfoReason[MAX_MULTIREASON_STRLEN] = NULLSTR;
  205. memcpy( &m_PortDataStandard, m_pParams->pData, sizeof(PORT_DATA_1) );
  206. FillComboBox(hDlg);
  207. LoadString(g_hInstance, IDS_STRING_MULTI_PORT_DEV, sztMoreInfoReason, MAX_MULTIREASON_STRLEN);
  208. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_MOREINFO_REASON), sztMoreInfoReason);
  209. } // OnSetActive
  210. //
  211. // FUNCTION: FillComboBox(HWND hDlg)
  212. //
  213. // PURPOSE: Fills the combo box with values gotten from the ini file.
  214. // The associated item data is used to pair the port number with the
  215. // device types.
  216. //
  217. // Arguments: hDlg is the handle of the dialog box.
  218. //
  219. void CMultiPortDlg::FillComboBox(HWND hDlg)
  220. {
  221. LRESULT index = 0;
  222. HWND hList = NULL;
  223. CDevicePort *pDP = NULL;
  224. hList = GetDlgItem(hDlg, IDC_COMBO_DEVICES);
  225. // Possible Values in m_pParams->dwDeviceType:
  226. // ERROR_DEVICE_NOT_FOUND
  227. // SUCCESS_DEVICE_MULTI_PORT
  228. // SUCCESS_DEVICE_UNKNOWN
  229. index = SendMessage(hList, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
  230. //
  231. // Initialize the list of variables
  232. //
  233. m_DPList.GetDevicePortsList(m_pParams->sztSectionName);
  234. for(pDP = m_DPList.GetFirst(); pDP != NULL; pDP = m_DPList.GetNext())
  235. {
  236. index = SendMessage(hList,
  237. CB_ADDSTRING,
  238. (WPARAM)0,
  239. (LPARAM)pDP->GetName());
  240. SendMessage(hList,
  241. CB_SETITEMDATA,
  242. (WPARAM)index,
  243. (LPARAM)pDP);
  244. }
  245. if( *m_szCurrentSelection != '\0' ) {
  246. index = SendMessage(hList,
  247. CB_SELECTSTRING,
  248. (WPARAM)-1,
  249. (LPARAM)m_szCurrentSelection);
  250. if (index == CB_ERR) {
  251. // Error the selected string is not in the list, which implies that the user has
  252. // selected a different network card, so we set the choice to the first one
  253. index = 0;
  254. }
  255. }
  256. else
  257. index = 0;
  258. SendMessage(hList, CB_SETCURSEL, (WPARAM)index, (LPARAM)0);
  259. GetPrinterData( hList, m_pParams->pData->sztHostAddress );
  260. } // FillComboBox