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.

528 lines
15 KiB

  1. /*****************************************************************************
  2. *
  3. * $Workfile: AddMInfo.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 "AddMInfo.h"
  17. #include "Resource.h"
  18. #include "MibABC.h"
  19. #include "TcpMonUI.h"
  20. //
  21. // FUNCTION: CMoreInfoDlg constructor
  22. //
  23. // PURPOSE: initialize a CMoreInfoDlg class
  24. //
  25. CMoreInfoDlg::CMoreInfoDlg() : m_DPList( )
  26. {
  27. memset(&m_PortDataStandard, 0, sizeof(m_PortDataStandard));
  28. memset(&m_PortDataCustom, 0, sizeof(m_PortDataCustom));
  29. lstrcpyn(m_szCurrentSelection, DEFAULT_COMBO_SELECTION, MAX_SECTION_NAME);
  30. } // constructor
  31. //
  32. // FUNCTION: CMoreInfoDlg destructor
  33. //
  34. // PURPOSE: deinitialize a CMoreInfoDlg class
  35. //
  36. CMoreInfoDlg::~CMoreInfoDlg()
  37. {
  38. } // destructor
  39. //
  40. // FUNCTION: MoreInfoDialog(HWND, UINT, WPARAM, LPARAM)
  41. //
  42. // PURPOSE: To process messages from the summary dialog for adding a port.
  43. //
  44. // MESSAGES:
  45. //
  46. // WM_INITDIALOG - intializes the page
  47. // WM_COMMAND - handles button presses and text changes in edit controls.
  48. //
  49. //
  50. INT_PTR CALLBACK MoreInfoDialog(
  51. HWND hDlg,
  52. UINT message,
  53. WPARAM wParam,
  54. LPARAM lParam)
  55. {
  56. CMoreInfoDlg *wndDlg = NULL;
  57. wndDlg = (CMoreInfoDlg *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  58. switch (message) {
  59. case WM_INITDIALOG:
  60. wndDlg = new CMoreInfoDlg;
  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 CMoreInfoDlg::OnInitDialog(HWND hDlg, WPARAM, LPARAM lParam)
  86. {
  87. m_pParams = (ADD_PARAM_PACKAGE *) ((PROPSHEETPAGE *) lParam)->lParam;
  88. CheckRadioButton(hDlg, IDC_RADIO_STANDARD, IDC_RADIO_CUSTOM, IDC_RADIO_STANDARD);
  89. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_DEVICES), TRUE);
  90. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS), FALSE);
  91. return TRUE;
  92. } // OnInitDialog
  93. //
  94. // FUNCTION: OnCommand()
  95. //
  96. // PURPOSE: Process WM_COMMAND message
  97. //
  98. BOOL CMoreInfoDlg::OnCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
  99. {
  100. switch(HIWORD(wParam)) {
  101. case BN_CLICKED:
  102. return OnButtonClicked(hDlg, wParam, lParam);
  103. break;
  104. /*
  105. case LBN_SELCHANGE:
  106. return OnSelChange(hDlg, wParam, lParam);
  107. break;
  108. */
  109. default:
  110. return FALSE;
  111. }
  112. return TRUE;
  113. } // OnCommand
  114. #if 0
  115. //
  116. // FUNCTION: OnSelChange()
  117. //
  118. // PURPOSE: Process WM_COMMAND's LBN_SELCHANGE message
  119. //
  120. BOOL CMoreInfoDlg::OnSelChange(HWND hDlg,
  121. WPARAM wParam,
  122. LPARAM lParam)
  123. {
  124. // The selection in the combo box changed.
  125. HWND hwndComboBox = NULL;
  126. hwndComboBox = (HWND) lParam; // handle of list box
  127. GetPrinterData(hwndComboBox, m_pParams->pData->sztHostAddress);
  128. return TRUE;
  129. } // OnSelChange
  130. #endif
  131. //
  132. // FUNCTION: GetPrinterData(HWND hwndControl, BOOL *Unknown)
  133. //
  134. // PURPOSE: Gets the socket number of the selected item.
  135. //
  136. // Arguments: hwndControl is the handle of the combo box.
  137. //
  138. // Return Value: Returns the socket number associated with the selected item
  139. //
  140. void CMoreInfoDlg::GetPrinterData(HWND hwndControl,
  141. LPCTSTR pszAddress
  142. )
  143. {
  144. LRESULT iSelectedIndex = 0;
  145. CDevicePort *pPortInfo = NULL;
  146. iSelectedIndex = SendMessage(hwndControl,
  147. CB_GETCURSEL,
  148. (WPARAM)0,
  149. (LPARAM)0);
  150. pPortInfo = (CDevicePort *) SendMessage(hwndControl,
  151. CB_GETITEMDATA,
  152. (WPARAM)iSelectedIndex,
  153. (LPARAM)0);
  154. if ( (DWORD_PTR)pPortInfo != CB_ERR) {
  155. pPortInfo->ReadPortInfo(pszAddress, &m_PortDataStandard, m_pParams->bBypassNetProbe);
  156. lstrcpyn( m_szCurrentSelection, pPortInfo->GetName(), MAX_SECTION_NAME);
  157. m_pParams->bMultiPort = ( pPortInfo->GetPortIndex() == 0);
  158. lstrcpyn(m_pParams->sztSectionName,pPortInfo->GetPortKeyName(), MAX_SECTION_NAME);
  159. } else {
  160. //
  161. // DSN Fill out the default structure
  162. //
  163. m_PortDataStandard.dwPortNumber = DEFAULT_PORT_NUMBER;
  164. lstrcpyn(m_PortDataStandard.sztSNMPCommunity,
  165. DEFAULT_SNMP_COMUNITY,
  166. MAX_SNMP_COMMUNITY_STR_LEN);
  167. m_PortDataStandard.dwSNMPDevIndex = 1;
  168. }
  169. } // GetPrinterData
  170. //
  171. // FUNCTION: OnNotify()
  172. //
  173. // PURPOSE: Process WM_NOTIFY message
  174. //
  175. BOOL CMoreInfoDlg::OnNotify(HWND hDlg, WPARAM wParam, LPARAM lParam)
  176. {
  177. switch (((NMHDR FAR *) lParam)->code) {
  178. case PSN_KILLACTIVE:
  179. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  180. return 1;
  181. case PSN_RESET:
  182. //
  183. // reset to the original values
  184. //
  185. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  186. break;
  187. case PSN_SETACTIVE:
  188. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT | PSWIZB_BACK);
  189. OnSetActive(hDlg);
  190. break;
  191. case PSN_WIZBACK:
  192. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_DIALOG_ADDPORT);
  193. memcpy(m_pParams->pData, &m_PortDataStandard, sizeof(PORT_DATA_1));
  194. break;
  195. case PSN_WIZNEXT:
  196. //
  197. // the Next button was pressed
  198. //
  199. if( IsDlgButtonChecked(hDlg, IDC_RADIO_STANDARD) == BST_CHECKED ) {
  200. HWND hList = NULL;
  201. HCURSOR hNewCursor = NULL;
  202. HCURSOR hOldCursor = NULL;
  203. if ( hNewCursor = LoadCursor(NULL, IDC_WAIT) )
  204. hOldCursor = SetCursor(hNewCursor);
  205. hList = GetDlgItem(hDlg, IDC_COMBO_DEVICES);
  206. GetPrinterData(hList, m_pParams->pData->sztHostAddress);
  207. if ( m_pParams->bMultiPort == FALSE ) {
  208. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_DIALOG_SUMMARY);
  209. }
  210. memcpy(m_pParams->pData,
  211. &m_PortDataStandard,
  212. sizeof(PORT_DATA_1));
  213. lstrcpyn(m_pParams->sztPortDesc,
  214. m_szCurrentSelection,
  215. SIZEOF_IN_CHAR(m_pParams->sztPortDesc));
  216. if ( hNewCursor )
  217. SetCursor(hOldCursor);
  218. } else {
  219. //
  220. // if(IsDlgButtonChecked(hDlg, IDC_RADIO_CUSTOM) == BST_CHECKED)
  221. //
  222. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_DIALOG_SUMMARY);
  223. memcpy(m_pParams->pData, &m_PortDataCustom, sizeof(PORT_DATA_1));
  224. m_pParams->bMultiPort = FALSE;
  225. *m_pParams->sztPortDesc = '\0';
  226. }
  227. break;
  228. case PSN_QUERYCANCEL:
  229. m_pParams->dwLastError = ERROR_CANCELLED;
  230. return FALSE;
  231. break;
  232. default:
  233. return FALSE;
  234. }
  235. return TRUE;
  236. } // OnCommand
  237. HRESULT
  238. DynamicLoadString (
  239. IN HINSTANCE hInst,
  240. IN UINT uID,
  241. IN UINT cchInitialCount,
  242. OUT LPWSTR* ppszString
  243. )
  244. /*++
  245. This function allocates memory using 'new' operator and loads string using LoadString call.
  246. Caller is responsible for deleting the allocated memory.
  247. The buffer space is insufficient if there is no extra character left after terminating char.
  248. In this case, it releases the memory, allocates new bigger buffer and calls LoadString again.
  249. --*/
  250. {
  251. HRESULT hr = S_OK;
  252. UINT cchCount = cchInitialCount + 1;
  253. for (;;)
  254. {
  255. LPWSTR pszString = new WCHAR [cchCount];
  256. if (pszString == NULL)
  257. {
  258. hr = E_OUTOFMEMORY;
  259. break;
  260. }
  261. UINT cchLoadStringCount = LoadString (hInst,
  262. uID,
  263. pszString,
  264. cchCount);
  265. if (cchLoadStringCount == 0)
  266. {
  267. //
  268. // String does not exist
  269. //
  270. *pszString = L'\0';
  271. *ppszString = pszString;
  272. hr = S_FALSE;
  273. break;
  274. }
  275. //
  276. // If the buffer is full (string content plus terminating char)
  277. // we need to increase the buffer to be sure the whole string is loaded
  278. //
  279. if (cchLoadStringCount + 1 < cchCount)
  280. {
  281. //
  282. // After terminating char of the copied string must remain at least one empty place
  283. // This is a sign that we have whole string
  284. //
  285. *ppszString = pszString;
  286. hr = S_OK;
  287. break;
  288. }
  289. //
  290. // Increase the size of the buffer and load string again
  291. //
  292. delete [] pszString;
  293. cchCount *= 2;
  294. }
  295. return hr;
  296. }//end DynamicLoadString
  297. //
  298. // FUNCTION: OnSetActive()
  299. //
  300. // PURPOSE: Process PSN_SETACTIVE part of the WM_NOTIFY message
  301. //
  302. void CMoreInfoDlg::OnSetActive(HWND hDlg)
  303. {
  304. WCHAR* pszMoreInfoReason = NULL;
  305. memcpy( &m_PortDataStandard, m_pParams->pData, sizeof(PORT_DATA_1) );
  306. memcpy( &m_PortDataCustom, m_pParams->pData, sizeof(PORT_DATA_1) );
  307. FillComboBox(hDlg);
  308. switch(m_pParams->dwDeviceType) {
  309. case ERROR_DEVICE_NOT_FOUND:
  310. (VOID) DynamicLoadString (g_hInstance,
  311. IDS_STRING_DEV_NOT_FOUND,
  312. MAX_REASON_STRLEN,
  313. &pszMoreInfoReason);
  314. break;
  315. case SUCCESS_DEVICE_UNKNOWN:
  316. (VOID) DynamicLoadString (g_hInstance,
  317. IDS_STRING_UNKNOWN_DEV,
  318. MAX_REASON_STRLEN,
  319. &pszMoreInfoReason);
  320. break;
  321. default:
  322. break;
  323. }
  324. if (pszMoreInfoReason)
  325. {
  326. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_MOREINFO_REASON), pszMoreInfoReason);
  327. }
  328. else
  329. {
  330. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_MOREINFO_REASON), L"");
  331. }
  332. delete [] pszMoreInfoReason;
  333. } // OnSetActive
  334. //
  335. // FUNCTION: OnButtonClicked()
  336. //
  337. // PURPOSE: Process BN_CLICKED message
  338. //
  339. BOOL CMoreInfoDlg::OnButtonClicked(HWND hDlg, WPARAM wParam, LPARAM)
  340. {
  341. int idButton = (int) LOWORD(wParam); // identifier of button
  342. // HWND hwndButton = (HWND) lParam;
  343. switch(idButton)
  344. {
  345. case IDC_BUTTON_SETTINGS:
  346. m_pParams->UIManager->ConfigPortUI(hDlg,
  347. &m_PortDataCustom,
  348. m_pParams->hXcvPrinter,
  349. m_pParams->pszServer,
  350. TRUE);
  351. break;
  352. case IDC_RADIO_STANDARD:
  353. CheckRadioButton(hDlg, IDC_RADIO_STANDARD, IDC_RADIO_CUSTOM, IDC_RADIO_STANDARD);
  354. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_DEVICES), TRUE);
  355. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS), FALSE);
  356. SetFocus(GetDlgItem(hDlg, IDC_COMBO_DEVICES));
  357. break;
  358. case IDC_RADIO_CUSTOM:
  359. CheckRadioButton(hDlg, IDC_RADIO_STANDARD, IDC_RADIO_CUSTOM, IDC_RADIO_CUSTOM);
  360. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_DEVICES), FALSE);
  361. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS), TRUE);
  362. SetFocus(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS));
  363. break;
  364. default:
  365. return FALSE;
  366. break;
  367. }
  368. return TRUE;
  369. } // OnButtonClicked
  370. //
  371. // FUNCTION: FillComboBox(HWND hDlg)
  372. //
  373. // PURPOSE: Fills the combo box with values gotten from the ini file.
  374. // The associated item data is used to pair the port number with the
  375. // device types.
  376. //
  377. // Arguments: hDlg is the handle of the dialog box.
  378. //
  379. void CMoreInfoDlg::FillComboBox(HWND hDlg)
  380. {
  381. LRESULT index = 0;
  382. HWND hList = NULL;
  383. CDevicePort *pDP = NULL;
  384. TCHAR sztGenericNetworkCard[MAX_TITLE_LENGTH];
  385. hList = GetDlgItem(hDlg, IDC_COMBO_DEVICES);
  386. // Possible Values in m_pParams->dwDeviceType:
  387. // ERROR_DEVICE_NOT_FOUND
  388. // SUCCESS_DEVICE_MULTI_PORT
  389. // SUCCESS_DEVICE_UNKNOWN
  390. index = SendMessage(hList,
  391. CB_GETCURSEL,
  392. (WPARAM)0,
  393. (LPARAM)0);
  394. if (index == CB_ERR) {
  395. // This is the first time, initiliaze the list
  396. index = SendMessage(hList, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
  397. //
  398. // Initialize the list of variables
  399. //
  400. if(m_pParams->dwDeviceType == ERROR_DEVICE_NOT_FOUND ||
  401. m_pParams->dwDeviceType == SUCCESS_DEVICE_UNKNOWN) {
  402. m_DPList.GetDevicePortsList(NULL);
  403. } else { // SUCCESS_DEVICE_MULTI_PORT
  404. m_DPList.GetDevicePortsList(m_pParams->sztSectionName);
  405. }
  406. for(pDP = m_DPList.GetFirst(); pDP != NULL; pDP = m_DPList.GetNext()) {
  407. index = SendMessage(hList,
  408. CB_ADDSTRING,
  409. (WPARAM)0,
  410. (LPARAM)pDP->GetName());
  411. SendMessage(hList,
  412. CB_SETITEMDATA,
  413. (WPARAM)index,
  414. (LPARAM)pDP);
  415. }
  416. index = SendMessage(hList,
  417. CB_SETCURSEL,
  418. (WPARAM)0,
  419. (LPARAM)0);
  420. if((m_pParams->dwDeviceType == ERROR_DEVICE_NOT_FOUND ||
  421. m_pParams->dwDeviceType == SUCCESS_DEVICE_UNKNOWN) &&
  422. (*m_szCurrentSelection != '\0') ) {
  423. index = SendMessage(hList,
  424. CB_SELECTSTRING,
  425. (WPARAM)-1,
  426. (LPARAM)m_szCurrentSelection);
  427. }
  428. SendMessage(hList, CB_SETCURSEL, (WPARAM)index, (LPARAM)0);
  429. if (LoadString(g_hInstance, IDS_GENERIC_NETWORK_CARD, sztGenericNetworkCard, MAX_TITLE_LENGTH))
  430. SendMessage(hList, CB_SELECTSTRING, 0, (LPARAM)sztGenericNetworkCard);
  431. }
  432. } // FillComboBox