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.

1978 lines
58 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. // Advanced Dialog Functions
  3. ///////////////////////////////////////////////////////////////////////////
  4. #include "cyzhelp.h"
  5. #include "cyzports.h"
  6. #include "advandlg.h"
  7. #include <htmlhelp.h>
  8. #include <windowsx.h>
  9. TCHAR m_szDevMgrHelp[] = _T("devmgr.hlp");
  10. TCHAR m_szCyzcoinsHelp[] = _T("cyzcoins.chm");
  11. // For Cyclades-Z
  12. //TCHAR m_szPPPAware[] = TEXT( "PPPaware" );
  13. TCHAR m_szWriteComplete[] = TEXT( "WriteComplete" );
  14. const DWORD HelpIDs[]=
  15. {
  16. IDC_STATIC, IDH_NOHELP,
  17. IDC_ADVANCED, IDH_DEVMGR_PORTSET_ADVANCED, // "&Advanced" (Button)
  18. PP_PORT_BAUDRATE, IDH_DEVMGR_PORTSET_BPS, // "" (ComboBox)
  19. PP_PORT_DATABITS, IDH_DEVMGR_PORTSET_DATABITS, // "" (ComboBox)
  20. PP_PORT_PARITY, IDH_DEVMGR_PORTSET_PARITY, // "" (ComboBox)
  21. PP_PORT_STOPBITS, IDH_DEVMGR_PORTSET_STOPBITS, // "" (ComboBox)
  22. PP_PORT_FLOWCTL, IDH_DEVMGR_PORTSET_FLOW, // "" (ComboBox)
  23. IDC_RESTORE_PORT, IDH_DEVMGR_PORTSET_DEFAULTS, // "&Restore Defaults" (Button)
  24. 0, 0
  25. };
  26. //
  27. // write out values in tenths of a sec
  28. //
  29. #define SECONDS_CONVERSION_FACTOR (10)
  30. #define NUM_POLLING_PERIODS 7
  31. DWORD PollingPeriods[NUM_POLLING_PERIODS] = {
  32. -1,
  33. 0,
  34. 1 * SECONDS_CONVERSION_FACTOR,
  35. 5 * SECONDS_CONVERSION_FACTOR,
  36. 10 * SECONDS_CONVERSION_FACTOR,
  37. 30 * SECONDS_CONVERSION_FACTOR,
  38. 60 * SECONDS_CONVERSION_FACTOR
  39. };
  40. TCHAR PeriodDescription[NUM_POLLING_PERIODS+1][40] = {
  41. { _T("Disabled") },
  42. { _T("Manually") },
  43. { _T("Every second") },
  44. { _T("Every 5 seconds") },
  45. { _T("Every 10 seconds") },
  46. { _T("Every 30 seconds") },
  47. { _T("Every minute") },
  48. { _T("Other (every %d sec)") }
  49. };
  50. ULONG RxValues[4] = { 1, 4, 8, 14};
  51. TCHAR m_szRxFIFO[] = _T("RxFIFO");
  52. TCHAR m_szTxFIFO[] = _T("TxFIFO");
  53. TCHAR m_szFifoRxMax[] = _T("FifoRxMax");
  54. TCHAR m_szFifoTxMax[] = _T("FifoTxMax");
  55. //const DWORD AdvanHelpIDs[] =
  56. //{
  57. // IDC_DESC_1, IDH_NOHELP,
  58. // IDC_DESC_2, IDH_NOHELP,
  59. //
  60. // IDC_FIFO, IDH_DEVMGR_PORTSET_ADV_USEFIFO, // "Use FIFO buffers (requires 16550 compatible UART)" (Button)
  61. //
  62. // IDC_RECEIVE_TEXT, IDH_NOHELP, // "&Receive Buffer:" (Static)
  63. // IDC_RECEIVE_SLIDER, IDH_DEVMGR_PORTSET_ADV_RECV, // "" (msctls_trackbar32)
  64. // IDC_RECEIVE_LOW, IDH_NOHELP, // "Low (%d)" (Static)
  65. // IDC_RECEIVE_HIGH, IDH_NOHELP, // "High (%d)" (Static)
  66. // IDC_RXVALUE, IDH_NOHELP,
  67. //
  68. // IDC_TRANSMIT_TEXT, IDH_NOHELP, // "&Transmit Buffer:" (Static)
  69. // IDC_TRANSMIT_SLIDER, IDH_DEVMGR_PORTSET_ADV_TRANS, // "" (msctls_trackbar32)
  70. // IDC_TRANSMIT_LOW, IDH_NOHELP, // "Low (%d)" (Static)
  71. // IDC_TRANSMIT_HIGH, IDH_NOHELP, // "High (%d)" (Static)
  72. // IDC_TXVALUE, IDH_NOHELP,
  73. //
  74. // IDC_POLL_DESC, IDH_NOHELP,
  75. // IDC_POLL_PERIOD, IDH_DEVMGR_PORTSET_ADV_DEVICES, // "" (ComboBox)
  76. //
  77. // PP_PORT_NUMBER, IDH_DEVMGR_PORTSET_ADV_NUMBER, // "" (ComboBox)
  78. // IDC_COMNUMTEXT, IDH_NOHELP, // "COM &Port Number:" (Static)
  79. //
  80. // IDC_RESTORE, IDH_DEVMGR_PORTSET_ADV_DEFAULTS,// "&Restore Defaults" (Button)
  81. // 0, 0
  82. //};
  83. const DWORD AdvanHelpIDs[] =
  84. {
  85. IDC_DESC_1, IDH_NOHELP,
  86. IDC_DESC_2, IDH_NOHELP,
  87. IDC_POLL_DESC, IDH_NOHELP,
  88. IDC_POLL_PERIOD, IDH_DEVMGR_PORTSET_ADV_DEVICES, // "" (ComboBox)
  89. PP_PORT_NUMBER, IDH_CYZCOINS_PORTSET_ADV_NUMBER, // "" (ComboBox)
  90. IDC_COMNUMTEXT, IDH_NOHELP, // "COM &Port Number:" (Static)
  91. IDC_RESTORE, IDH_CYZCOINS_PORTSET_ADV_DEFAULTS, // "&Restore Defaults" (Button)
  92. // IDC_PPP_AWARE, IDH_CYZCOINS_PORTSET_ADV_PPP_AWARE,// Optimization for RRAS (CheckBox)
  93. IDC_WRITE_COMPLETE, IDH_CYZCOINS_PORTSET_ADV_WRITE_COMPLETE, // Return Write status (CheckBox)
  94. 0, 0
  95. };
  96. #define Trackbar_SetPos(hwndTb, Redraw, Position)\
  97. (VOID) SendMessage(hwndTb, TBM_SETPOS, (WPARAM) Redraw, (LPARAM) Position)
  98. #define Trackbar_SetRange(hwndTb, Redraw, MinVal, MaxVal)\
  99. (VOID) SendMessage(hwndTb, TBM_SETRANGE, (WPARAM) Redraw, (LPARAM) MAKELONG(MinVal, MaxVal))
  100. #define Trackbar_SetTic(hwndTb, Tic)\
  101. (VOID) SendMessage(hwndTb, TBM_SETTIC, (WPARAM) 0, (LPARAM) Tic)
  102. #define Trackbar_GetPos(hwndTb)\
  103. (DWORD) SendMessage(hwndTb, TBM_GETPOS, (WPARAM) 0, (LPARAM) 0)
  104. BOOL
  105. Advanced_OnCommand(
  106. HWND ParentHwnd,
  107. int ControlId,
  108. HWND ControlHwnd,
  109. UINT NotifyCode
  110. );
  111. BOOL
  112. Advanced_OnContextMenu(
  113. HWND HwndControl,
  114. WORD Xpos,
  115. WORD Ypos
  116. );
  117. void
  118. Advanced_OnHelp(
  119. HWND ParentHwnd,
  120. LPHELPINFO HelpInfo
  121. );
  122. BOOL
  123. Advanced_OnInitDialog(
  124. HWND ParentHwnd,
  125. HWND FocusHwnd,
  126. LPARAM Lparam
  127. );
  128. /*++
  129. Routine Description: AdvancedPortsDlgProc
  130. The windows proc for the Advanced properties window
  131. Arguments:
  132. hDlg, uMessage, wParam, lParam: standard windows DlgProc parameters
  133. Return Value:
  134. BOOL: FALSE if the page could not be created
  135. --*/
  136. INT_PTR APIENTRY
  137. AdvancedPortsDlgProc(
  138. IN HWND hDlg,
  139. IN UINT uMessage,
  140. IN WPARAM wParam,
  141. IN LPARAM lParam
  142. )
  143. {
  144. switch(uMessage) {
  145. case WM_COMMAND:
  146. return Advanced_OnCommand(hDlg,
  147. (int) LOWORD(wParam),
  148. (HWND)lParam,
  149. (UINT) HIWORD(wParam));
  150. case WM_CONTEXTMENU:
  151. return Advanced_OnContextMenu((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
  152. case WM_HELP:
  153. Advanced_OnHelp(hDlg, (LPHELPINFO) lParam);
  154. break;
  155. case WM_HSCROLL:
  156. HandleTrackbarChange(hDlg, (HWND) lParam);
  157. return TRUE;
  158. case WM_INITDIALOG:
  159. return Advanced_OnInitDialog(hDlg, (HWND) wParam, lParam);
  160. }
  161. return FALSE;
  162. } /* AdvancedPortsDlgProc */
  163. BOOL
  164. Advanced_OnCommand(
  165. HWND ParentHwnd,
  166. int ControlId,
  167. HWND ControlHwnd,
  168. UINT NotifyCode
  169. )
  170. {
  171. PADVANCED_DATA advancedData =
  172. (PADVANCED_DATA) GetWindowLongPtr(ParentHwnd, DWLP_USER);
  173. switch(ControlId) {
  174. case IDC_FIFO:
  175. //
  176. // Disable or enable the sliders
  177. //
  178. EnableFifoControls(ParentHwnd, IsDlgButtonChecked(ParentHwnd, IDC_FIFO));
  179. return TRUE;
  180. case IDOK:
  181. SaveAdvancedSettings(ParentHwnd, advancedData);
  182. // fall through
  183. case IDCANCEL:
  184. EndDialog(ParentHwnd, ControlId);
  185. return TRUE;
  186. case IDC_RESTORE:
  187. RestoreAdvancedDefaultState(ParentHwnd, advancedData);
  188. return TRUE;
  189. }
  190. return FALSE;
  191. }
  192. BOOL
  193. Advanced_OnContextMenu(
  194. HWND HwndControl,
  195. WORD Xpos,
  196. WORD Ypos
  197. )
  198. {
  199. // WinHelp(HwndControl,
  200. // m_szCyzcoinsHelp,
  201. // HELP_CONTEXTMENU,
  202. // (ULONG_PTR) AdvanHelpIDs);
  203. HtmlHelp(HwndControl,
  204. m_szCyzcoinsHelp,
  205. HH_TP_HELP_CONTEXTMENU,
  206. (ULONG_PTR) AdvanHelpIDs);
  207. return FALSE;
  208. }
  209. void
  210. Advanced_OnHelp(
  211. HWND ParentHwnd,
  212. LPHELPINFO HelpInfo
  213. )
  214. {
  215. if (HelpInfo->iContextType == HELPINFO_WINDOW) {
  216. // WinHelp((HWND) HelpInfo->hItemHandle,
  217. // m_szCyzcoinsHelp,
  218. // HELP_WM_HELP,
  219. // (ULONG_PTR) AdvanHelpIDs);
  220. HtmlHelp((HWND) HelpInfo->hItemHandle,
  221. m_szCyzcoinsHelp,
  222. HH_TP_HELP_WM_HELP,
  223. (ULONG_PTR) AdvanHelpIDs);
  224. }
  225. }
  226. BOOL
  227. Advanced_OnInitDialog(
  228. HWND ParentHwnd,
  229. HWND FocusHwnd,
  230. LPARAM Lparam
  231. )
  232. {
  233. PADVANCED_DATA advancedData;
  234. TCHAR szFormat[200];
  235. TCHAR szBuffer[200];
  236. advancedData = (PADVANCED_DATA) Lparam;
  237. //
  238. // Initialize the dialog box parameters
  239. //
  240. FillAdvancedDlg(ParentHwnd, advancedData);
  241. SetWindowLongPtr(ParentHwnd, DWLP_USER, (ULONG_PTR) advancedData);
  242. //
  243. // Set up the dialog box with these initialized parameters
  244. //
  245. InitializeControls(ParentHwnd, advancedData);
  246. LoadString(g_hInst, IDS_ADVANCED_SETTINGS_FOR, szFormat, CharSizeOf(szFormat));
  247. wsprintf(szBuffer, szFormat, advancedData->szComName);
  248. SetWindowText(ParentHwnd, szBuffer);
  249. return TRUE;
  250. }
  251. BOOL InternalAdvancedDialog(
  252. IN HWND ParentHwnd,
  253. IN OUT PADVANCED_DATA AdvancedData
  254. )
  255. {
  256. AdvancedData->hComDB = HCOMDB_INVALID_HANDLE_VALUE;
  257. ComDBOpen(&AdvancedData->hComDB);
  258. DialogBoxParam(g_hInst,
  259. MAKEINTRESOURCE(DLG_PP_ADVPORTS),
  260. ParentHwnd,
  261. AdvancedPortsDlgProc,
  262. (DWORD_PTR) AdvancedData);
  263. ComDBClose(AdvancedData->hComDB);
  264. AdvancedData->hComDB = HCOMDB_INVALID_HANDLE_VALUE;
  265. return TRUE;
  266. }
  267. /*++
  268. Routine Description: DisplayAdvancedDialog
  269. Opens the devices instance and checks to see if it is valid. If so, then the advanced
  270. dialog is displayed. Otherwise a message is displayed to the user stating that the user
  271. does not have write access to this particular key.
  272. Arguments:
  273. ParentHwnd - Handle to the parent dialog (Port Settings Property Sheet)
  274. AdvancedData - hDeviceKey will be set with the device's key in the registry upon success,
  275. INVALID_HANDLE_VALUE upon error
  276. Return Value:
  277. None
  278. --*/
  279. BOOL DisplayAdvancedDialog(
  280. IN HWND ParentHwnd,
  281. IN OUT PADVANCED_DATA AdvancedData
  282. )
  283. {
  284. AdvancedData->hDeviceKey =
  285. SetupDiOpenDevRegKey(AdvancedData->DeviceInfoSet,
  286. AdvancedData->DeviceInfoData,
  287. DICS_FLAG_GLOBAL,
  288. 0,
  289. DIREG_DEV,
  290. KEY_ALL_ACCESS);
  291. if (AdvancedData->hDeviceKey == INVALID_HANDLE_VALUE) {
  292. MyMessageBox(ParentHwnd,
  293. IDS_NO_WRITE_PRVILEGE,
  294. IDS_NAME_PROPERTIES,
  295. MB_OK | MB_ICONINFORMATION);
  296. return FALSE;
  297. }
  298. else {
  299. return InternalAdvancedDialog(ParentHwnd, AdvancedData);
  300. }
  301. }
  302. /*++
  303. Routine Description: EnableFifoControls
  304. Enables/Disables all of the controls bounded by the rectangle with the Use Fifo
  305. checkbox.
  306. Arguments:
  307. hDlg - Handle to the dialog
  308. enabled - flag to either enable/disable the controls
  309. Return Value:
  310. None
  311. --*/
  312. void EnableFifoControls(IN HWND hDlg,
  313. IN BOOL enabled)
  314. {
  315. // The actual trackbar/slider
  316. EnableWindow(GetDlgItem(hDlg, IDC_RECEIVE_SLIDER), enabled);
  317. // "Low (xxx)" (Receive)
  318. EnableWindow(GetDlgItem(hDlg, IDC_RECEIVE_LOW), enabled);
  319. // "High (xxx)" (Receive)
  320. EnableWindow(GetDlgItem(hDlg, IDC_RECEIVE_HIGH), enabled);
  321. // "Receive Buffer: "
  322. EnableWindow(GetDlgItem(hDlg, IDC_RECEIVE_TEXT), enabled);
  323. // "(xxx)" (Actual value of trackbar, Receive)
  324. EnableWindow(GetDlgItem(hDlg, IDC_RXVALUE), enabled);
  325. // The actual trackbar/slider
  326. EnableWindow(GetDlgItem(hDlg, IDC_TRANSMIT_SLIDER), enabled);
  327. // "Low (xxx)" (Transmit)
  328. EnableWindow(GetDlgItem(hDlg, IDC_TRANSMIT_LOW), enabled);
  329. // "High (xxx)" (Transmit)
  330. EnableWindow(GetDlgItem(hDlg, IDC_TRANSMIT_HIGH), enabled);
  331. // "Transmit Buffer" (Transmit)
  332. EnableWindow(GetDlgItem(hDlg, IDC_TRANSMIT_TEXT), enabled);
  333. // "(xxx)" (Actual value of trackbar, Trasmist)
  334. EnableWindow(GetDlgItem(hDlg, IDC_TXVALUE), enabled);
  335. }
  336. /*++
  337. Routine Description: HandleTrackbarChange
  338. Whenever the user changes the trackbar thumb position, update the control
  339. to its right which displays its actual numeric value
  340. Arguments:
  341. hDlg - Handle to the parent dialog
  342. hTrackbar - Handle to the trackbar whose thumb has changed
  343. Return Value:
  344. None
  345. --*/
  346. void HandleTrackbarChange(IN HWND hDlg,
  347. IN HWND hTrackbar
  348. )
  349. {
  350. DWORD ctrlID;
  351. TCHAR szCurrentValue[10];
  352. ULONG position;
  353. position = Trackbar_GetPos(hTrackbar);
  354. if (GetDlgCtrlID(hTrackbar) == IDC_RECEIVE_SLIDER) {
  355. //
  356. // Rx we need to translate the tick position from index to value
  357. //
  358. wsprintf(szCurrentValue, TEXT("(%d)"), RxValues[position-1]);
  359. ctrlID = IDC_RXVALUE;
  360. }
  361. else {
  362. //
  363. // Tx is just a straight translation between value and index
  364. //
  365. wsprintf(szCurrentValue, TEXT("(%d)"), position);
  366. ctrlID = IDC_TXVALUE;
  367. }
  368. SetDlgItemText(hDlg, ctrlID, szCurrentValue);
  369. }
  370. DWORD
  371. RxValueToTrackbarPosition(IN OUT PDWORD RxValue
  372. )
  373. {
  374. switch (*RxValue) {
  375. case 1: return 1;
  376. case 4: return 2;
  377. case 8: return 3;
  378. case 14: return 4;
  379. }
  380. //
  381. // busted value
  382. //
  383. *RxValue = 14;
  384. return 4;
  385. }
  386. /*++
  387. Routine Description: SetTxTrackbarTicks
  388. Creates a tick at 1/4, half, and 3/4 across the span of the trackbar
  389. Arguments:
  390. hTrackbar - handle to the trackbar that will receive the ticks
  391. minVal, maxVal - Range on the trackbar
  392. Return Value:
  393. None
  394. --*/
  395. void
  396. SetTxTrackbarTics(
  397. IN HWND TrackbarHwnd
  398. )
  399. {
  400. Trackbar_SetTic(TrackbarHwnd, 6);
  401. Trackbar_SetTic(TrackbarHwnd, 11);
  402. }
  403. /*++
  404. Routine Description: SetLabelText
  405. Sets the label's to the string identified by resID concated with the passed
  406. in value and closing paren.
  407. The final string is [resID string][value])
  408. Arguments:
  409. hLabel - handle to the control whose text is going to change
  410. resID - resource ID for the beginning of the string that will become the
  411. label's text
  412. value - number to be concated into the string
  413. Return Value:
  414. None
  415. --*/
  416. void
  417. SetLabelText(
  418. IN HWND LabelHwnd,
  419. IN DWORD ResId,
  420. IN ULONG Value
  421. )
  422. {
  423. TCHAR szTemp[258], txt[258];
  424. if (LoadString(g_hInst, ResId, szTemp, CharSizeOf(szTemp))) {
  425. lstrcpy(txt, szTemp);
  426. wsprintf(szTemp, _T("%d)"), Value);
  427. lstrcat(txt, szTemp);
  428. }
  429. else {
  430. lstrcpy(txt, _T("Low"));
  431. }
  432. SetWindowText(LabelHwnd, txt);
  433. }
  434. /*++
  435. Routine Description: InitializeControls
  436. Initializes all of the controls that represent Fifo
  437. Arguments:
  438. ParentHwnd - handle to the dialog
  439. AdvancedData - Contains all of the initial values
  440. Return Value:
  441. None
  442. --*/
  443. void InitializeControls(
  444. IN HWND ParentHwnd,
  445. IN PADVANCED_DATA AdvancedData
  446. )
  447. {
  448. TCHAR szCurrentValue[40];
  449. HWND hwnd;
  450. int i, periodIdx;
  451. //---------------------------------------------------------
  452. // ATTENTION: (Fanny)
  453. // For now disable FIFO buffers selections. This feature
  454. // will be enabled when we add support to this in the driver.
  455. #define CD1400_RXFIFO_MIN 1
  456. #define CD1400_RXFIFO_MAX 12
  457. #define CD1400_TXFIFO_MIN 1
  458. #define CD1400_TXFIFO_MAX 12
  459. SetLabelText(GetDlgItem(ParentHwnd, IDC_RECEIVE_LOW),IDS_LOW,
  460. CD1400_RXFIFO_MIN);
  461. SetLabelText(GetDlgItem(ParentHwnd, IDC_RECEIVE_HIGH),IDS_HIGH,
  462. CD1400_RXFIFO_MAX);
  463. SetLabelText(GetDlgItem(ParentHwnd, IDC_TRANSMIT_LOW),IDS_LOW,
  464. CD1400_TXFIFO_MIN);
  465. SetLabelText(GetDlgItem(ParentHwnd, IDC_TRANSMIT_HIGH),IDS_HIGH,
  466. CD1400_TXFIFO_MAX);
  467. AdvancedData->UseFifoBuffersControl = FALSE;
  468. AdvancedData->UseRxFIFOControl = FALSE;
  469. AdvancedData->UseTxFIFOControl = FALSE;
  470. EnableWindow(GetDlgItem(ParentHwnd, IDC_DESC_1), FALSE);
  471. EnableWindow(GetDlgItem(ParentHwnd, IDC_DESC_2), FALSE);
  472. // END ATTENTION
  473. //---------------------------------------------------------
  474. //
  475. // Set up the Fifo buffers checkbox
  476. //
  477. if (!AdvancedData->UseFifoBuffersControl) {
  478. //
  479. // Something went wrong with the Fifo buffers control. Disable
  480. // the checkbox
  481. //
  482. CheckDlgButton(ParentHwnd, IDC_FIFO, BST_UNCHECKED);
  483. EnableWindow(GetDlgItem(ParentHwnd, IDC_FIFO), FALSE);
  484. EnableFifoControls(ParentHwnd, FALSE);
  485. }
  486. else {
  487. EnableWindow(GetDlgItem(ParentHwnd, IDC_FIFO), TRUE);
  488. if (!AdvancedData->UseFifoBuffers) {
  489. EnableFifoControls(ParentHwnd, FALSE);
  490. CheckDlgButton(ParentHwnd, IDC_FIFO, BST_UNCHECKED);
  491. }
  492. else {
  493. EnableFifoControls(ParentHwnd, TRUE);
  494. CheckDlgButton(ParentHwnd, IDC_FIFO, BST_CHECKED);
  495. }
  496. }
  497. //
  498. // Set up the sliders
  499. //
  500. if (!AdvancedData->UseRxFIFOControl ||
  501. !AdvancedData->UseTxFIFOControl) {
  502. //
  503. // Something went wrong with the sliders.
  504. // Disable them
  505. //
  506. CheckDlgButton(ParentHwnd, IDC_FIFO, BST_UNCHECKED);
  507. EnableWindow(GetDlgItem(ParentHwnd, IDC_FIFO), FALSE);
  508. EnableFifoControls(ParentHwnd, FALSE);
  509. }
  510. else {
  511. //
  512. // Set up Rx Slider
  513. //
  514. hwnd = GetDlgItem(ParentHwnd, IDC_RECEIVE_SLIDER);
  515. Trackbar_SetRange(hwnd, TRUE, RX_MIN, 4);
  516. Trackbar_SetPos(hwnd,
  517. TRUE,
  518. RxValueToTrackbarPosition(&AdvancedData->RxFIFO));
  519. SetLabelText(GetDlgItem(ParentHwnd, IDC_RECEIVE_LOW),
  520. IDS_LOW,
  521. RX_MIN);
  522. SetLabelText(GetDlgItem(ParentHwnd, IDC_RECEIVE_HIGH),
  523. IDS_HIGH,
  524. AdvancedData->FifoRxMax);
  525. wsprintf(szCurrentValue, TEXT("(%d)"), AdvancedData->RxFIFO);
  526. SetDlgItemText(ParentHwnd, IDC_RXVALUE, szCurrentValue);
  527. //
  528. // Set up the Tx slider
  529. //
  530. hwnd = GetDlgItem(ParentHwnd, IDC_TRANSMIT_SLIDER);
  531. Trackbar_SetRange(hwnd, TRUE, TX_MIN, AdvancedData->FifoTxMax);
  532. Trackbar_SetPos(hwnd, TRUE, AdvancedData->TxFIFO);
  533. SetTxTrackbarTics(hwnd);
  534. SetLabelText(GetDlgItem(ParentHwnd, IDC_TRANSMIT_LOW),
  535. IDS_LOW,
  536. TX_MIN);
  537. SetLabelText(GetDlgItem(ParentHwnd, IDC_TRANSMIT_HIGH),
  538. IDS_HIGH,
  539. AdvancedData->FifoTxMax);
  540. wsprintf(szCurrentValue, TEXT("(%d)"), AdvancedData->TxFIFO);
  541. SetDlgItemText(ParentHwnd, IDC_TXVALUE, szCurrentValue);
  542. }
  543. FillPortNameCb(ParentHwnd, AdvancedData);
  544. //
  545. // Display the "Enable Optimization For RRAS" check box
  546. //
  547. // EnableWindow(GetDlgItem(ParentHwnd, IDC_PPP_AWARE), TRUE);
  548. // if (AdvancedData->PPPAware) {
  549. // CheckDlgButton(ParentHwnd, IDC_PPP_AWARE, BST_CHECKED);
  550. // } else {
  551. // CheckDlgButton(ParentHwnd, IDC_PPP_AWARE, BST_UNCHECKED);
  552. // }
  553. //
  554. // Display the "Return Write status only after firmware buffer empty" check box
  555. //
  556. EnableWindow(GetDlgItem(ParentHwnd, IDC_WRITE_COMPLETE), TRUE);
  557. if (AdvancedData->WriteComplete) {
  558. CheckDlgButton(ParentHwnd, IDC_WRITE_COMPLETE, BST_CHECKED);
  559. } else {
  560. CheckDlgButton(ParentHwnd, IDC_WRITE_COMPLETE, BST_UNCHECKED);
  561. }
  562. if (!AdvancedData->HidePolling) {
  563. //
  564. // Add the descriptions for each polling period and select the current
  565. // setting
  566. //
  567. hwnd = GetDlgItem(ParentHwnd, IDC_POLL_PERIOD);
  568. periodIdx = NUM_POLLING_PERIODS;
  569. for (i = 0; i < NUM_POLLING_PERIODS; i++) {
  570. ComboBox_AddString(hwnd, PeriodDescription[i]);
  571. if (PollingPeriods[i] == AdvancedData->PollingPeriod) {
  572. periodIdx = i;
  573. }
  574. }
  575. if (periodIdx == NUM_POLLING_PERIODS) {
  576. wsprintf(szCurrentValue,
  577. PeriodDescription[NUM_POLLING_PERIODS],
  578. AdvancedData->PollingPeriod / SECONDS_CONVERSION_FACTOR);
  579. ComboBox_AddString(hwnd, szCurrentValue);
  580. }
  581. ComboBox_SetCurSel(hwnd, periodIdx);
  582. }
  583. else {
  584. ShowWindow(GetDlgItem(ParentHwnd, IDC_POLL_PERIOD), SW_HIDE);
  585. ShowWindow(GetDlgItem(ParentHwnd, IDC_POLL_DESC), SW_HIDE);
  586. }
  587. } /* InitializeControls */
  588. /*++
  589. Routine Description: RestoreAdvancedDefaultState
  590. Restores all values and UI to their default state, specifically:
  591. o All Fifo related child controls are enabled
  592. o The Rx trackbar is set to its max value
  593. o The Tx trackbar is set to its max value
  594. o The number of the comport is reset to its original value
  595. Return Value:
  596. None
  597. --*/
  598. void RestoreAdvancedDefaultState(
  599. IN HWND ParentHwnd,
  600. IN PADVANCED_DATA AdvancedData
  601. )
  602. {
  603. USHORT ushIndex;
  604. TCHAR szCurrentValue[10];
  605. int i;
  606. //-------------------------------------------------------------------------
  607. // ATTENTION: For now, don't show anything related to FIFO buffers (Fanny)
  608. #if 0
  609. //-------------------------------------------------------------------------
  610. //
  611. // Set up the Fifo buffers checkbox
  612. //
  613. EnableWindow(GetDlgItem(ParentHwnd, IDC_FIFO), TRUE);
  614. EnableFifoControls(ParentHwnd, TRUE);
  615. CheckDlgButton(ParentHwnd, IDC_FIFO, BST_CHECKED);
  616. //
  617. // Set up the sliders and the static control that show their numberic value
  618. //
  619. Trackbar_SetPos(GetDlgItem(ParentHwnd, IDC_RECEIVE_SLIDER),
  620. TRUE,
  621. RxValueToTrackbarPosition(&AdvancedData->FifoRxMax));
  622. wsprintf(szCurrentValue, TEXT("(%d)"), AdvancedData->FifoRxMax);
  623. SetDlgItemText(ParentHwnd, IDC_RXVALUE, szCurrentValue);
  624. Trackbar_SetPos(GetDlgItem(ParentHwnd, IDC_TRANSMIT_SLIDER), TRUE, AdvancedData->FifoTxMax);
  625. wsprintf(szCurrentValue, TEXT("(%d)"), AdvancedData->FifoTxMax);
  626. SetDlgItemText(ParentHwnd, IDC_TXVALUE, szCurrentValue);
  627. //-------------------------------------------------------------------------
  628. // END ATTENTION
  629. #endif
  630. //-------------------------------------------------------------------------
  631. //
  632. // Set the COM name to whatever it is currently set to in the registry
  633. //
  634. ushIndex =
  635. (USHORT) ComboBox_FindString(GetDlgItem(ParentHwnd, PP_PORT_NUMBER),
  636. -1,
  637. AdvancedData->szComName);
  638. ushIndex = (ushIndex == CB_ERR) ? 0 : ushIndex;
  639. // Set Enable Optimization For RRAS
  640. // EnableWindow(GetDlgItem(ParentHwnd, IDC_PPP_AWARE), TRUE);
  641. // CheckDlgButton(ParentHwnd, IDC_PPP_AWARE, BST_CHECKED);
  642. // Clear Return Write status only after firmware buffer empty
  643. EnableWindow(GetDlgItem(ParentHwnd, IDC_WRITE_COMPLETE), TRUE);
  644. CheckDlgButton(ParentHwnd, IDC_WRITE_COMPLETE, BST_UNCHECKED);
  645. ComboBox_SetCurSel(GetDlgItem(ParentHwnd, PP_PORT_NUMBER), ushIndex);
  646. ComboBox_SetCurSel(GetDlgItem(ParentHwnd, IDC_POLL_PERIOD), POLL_PERIOD_DEFAULT_IDX);
  647. } /* RestoreAdvancedDefaultStates */
  648. /*++
  649. Routine Description: FillPortNameCb
  650. fill in the Port Name combo box selection with a list
  651. of possible un-used portnames
  652. Arguments:
  653. poppOurPropParams: where to save the data to
  654. hDlg: address of the window
  655. Return Value:
  656. ULONG: returns error messages
  657. --*/
  658. ULONG
  659. FillPortNameCb(
  660. HWND ParentHwnd,
  661. PADVANCED_DATA AdvancedData
  662. )
  663. {
  664. BYTE portUsage[MAX_COM_PORT/8];
  665. DWORD tmp, portsReported = 0;
  666. int i, j, nEntries;
  667. int nCurPortNum;
  668. TCHAR szCom[40];
  669. TCHAR szInUse[40];
  670. char mask, *current;
  671. HWND portHwnd;
  672. portHwnd = GetDlgItem(ParentHwnd, PP_PORT_NUMBER);
  673. //
  674. // Check if our ComName is blank. If it is, disable the com port selector
  675. //
  676. if (_tcscmp(AdvancedData->szComName, TEXT("")) == 0) {
  677. EnableWindow(portHwnd, FALSE);
  678. EnableWindow(GetDlgItem(ParentHwnd, IDC_COMNUMTEXT), FALSE);
  679. return 0;
  680. }
  681. //
  682. // assumes szComPort filled in...
  683. //
  684. nCurPortNum = myatoi(&AdvancedData->szComName[3]);
  685. if (!LoadString(g_hInst, IDS_IN_USE, szInUse, CharSizeOf(szInUse))) {
  686. wcscpy(szInUse, _T(" (in use)"));
  687. }
  688. //
  689. // first tally up which ports NOT to offer in list box
  690. //
  691. ZeroMemory(portUsage, MAX_COM_PORT/8);
  692. if (AdvancedData->hComDB != HCOMDB_INVALID_HANDLE_VALUE) {
  693. ComDBGetCurrentPortUsage(AdvancedData->hComDB,
  694. portUsage,
  695. MAX_COM_PORT / 8,
  696. CDB_REPORT_BITS,
  697. &portsReported);
  698. }
  699. //
  700. // tag the current port as not in use so it shows up in the CB
  701. //
  702. current = portUsage + (nCurPortNum-1) / 8;
  703. if ((i = nCurPortNum % 8))
  704. *current &= ~(1 << (i-1));
  705. else
  706. *current &= ~(0x80);
  707. current = portUsage;
  708. mask = 0x1;
  709. for(nEntries = j = 0, i = MIN_COM-1; i < MAX_COM_PORT; i++) {
  710. wsprintf(szCom, TEXT("COM%d"), i+1);
  711. if (*current & mask) {
  712. wcscat(szCom, szInUse);
  713. }
  714. if (mask == (char) 0x80) {
  715. mask = 0x01;
  716. current++;
  717. }
  718. else {
  719. mask <<= 1;
  720. }
  721. ComboBox_AddString(portHwnd, szCom);
  722. }
  723. ComboBox_SetCurSel(portHwnd, nCurPortNum-1);
  724. return 0;
  725. } /* FillPortNamesCb */
  726. /*++
  727. Routine Description: FillAdvancedDlg
  728. fill in the advanced dialog window
  729. Arguments:
  730. poppOurPropParams: the data to fill in
  731. ParentHwnd: address of the window
  732. Return Value:
  733. ULONG: returns error messages
  734. --*/
  735. ULONG
  736. FillAdvancedDlg(
  737. IN HWND ParentHwnd,
  738. IN PADVANCED_DATA AdvancedData
  739. )
  740. {
  741. PSP_DEVINFO_DATA DeviceInfoData = AdvancedData->DeviceInfoData;
  742. HKEY hDeviceKey;
  743. DWORD dwSize, dwData, dwFifo, dwError = ERROR_SUCCESS;
  744. //
  745. // Open the device key for the source device instance
  746. //
  747. hDeviceKey = AdvancedData->hDeviceKey;
  748. //
  749. // Get COM Name
  750. //
  751. dwSize = sizeof(AdvancedData->szComName);
  752. dwError = RegQueryValueEx(hDeviceKey,
  753. m_szPortName,
  754. NULL,
  755. NULL,
  756. (PBYTE)AdvancedData->szComName,
  757. &dwSize);
  758. if (dwError != ERROR_SUCCESS) {
  759. wsprintf(AdvancedData->szComName, TEXT("COMX"));
  760. }
  761. #if 0
  762. //
  763. // Get ForceFifoEnable information
  764. //
  765. AdvancedData->UseFifoBuffersControl = TRUE;
  766. dwSize = sizeof(dwFifo);
  767. dwError = RegQueryValueEx(hDeviceKey,
  768. m_szFIFO,
  769. NULL,
  770. NULL,
  771. (LPBYTE)(&dwFifo),
  772. &dwSize);
  773. if (dwError == ERROR_SUCCESS) {
  774. //
  775. // Save this initial value
  776. //
  777. AdvancedData->UseFifoBuffersControl = TRUE;
  778. if (dwFifo == 0) {
  779. AdvancedData->UseFifoBuffers = FALSE;
  780. }
  781. else {
  782. AdvancedData->UseFifoBuffers = TRUE;
  783. }
  784. }
  785. else {
  786. //
  787. // value does not exist. Create our own
  788. //
  789. dwData = 1;
  790. dwSize = sizeof(dwSize);
  791. dwError = RegSetValueEx(hDeviceKey,
  792. m_szFIFO,
  793. 0,
  794. REG_DWORD,
  795. (CONST BYTE *)(&dwData),
  796. dwSize);
  797. if (dwError == ERROR_SUCCESS) {
  798. AdvancedData->UseFifoBuffers = TRUE;
  799. }
  800. else {
  801. AdvancedData->UseFifoBuffers = FALSE;
  802. AdvancedData->UseFifoBuffersControl = FALSE;
  803. }
  804. }
  805. //
  806. // Get FifoRxMax information
  807. //
  808. dwSize = sizeof(dwFifo);
  809. dwError = RegQueryValueEx(hDeviceKey,
  810. m_szFifoRxMax,
  811. NULL,
  812. NULL,
  813. (LPBYTE)(&dwFifo),
  814. &dwFifo);
  815. if (dwError == ERROR_SUCCESS) {
  816. //
  817. // Save this initial value
  818. //
  819. AdvancedData->FifoRxMax = dwFifo;
  820. if (AdvancedData->FifoRxMax > RX_MAX) {
  821. AdvancedData->FifoRxMax = RX_MAX;
  822. }
  823. }
  824. else {
  825. //
  826. // value does not exist. Create our own
  827. //
  828. AdvancedData->FifoRxMax = RX_MAX;
  829. }
  830. //
  831. // Get RxFIFO information
  832. //
  833. dwSize = sizeof(dwFifo);
  834. dwError = RegQueryValueEx(hDeviceKey,
  835. m_szFifoTxMax,
  836. NULL,
  837. NULL,
  838. (LPBYTE)(&dwFifo),
  839. &dwSize);
  840. if (dwError == ERROR_SUCCESS) {
  841. //
  842. // Save this initial value
  843. //
  844. AdvancedData->FifoTxMax = dwFifo;
  845. if (AdvancedData->FifoTxMax > TX_MAX) {
  846. AdvancedData->FifoTxMax = TX_MAX;
  847. }
  848. }
  849. else {
  850. //
  851. // value does not exist. Create our own
  852. //
  853. AdvancedData->FifoTxMax = TX_MAX;
  854. }
  855. //
  856. // Get RxFIFO information
  857. //
  858. AdvancedData->UseRxFIFOControl = TRUE;
  859. dwSize = sizeof(dwFifo);
  860. dwError = RegQueryValueEx(hDeviceKey,
  861. m_szRxFIFO,
  862. NULL,
  863. NULL,
  864. (LPBYTE)(&dwFifo),
  865. &dwSize);
  866. if (dwError == ERROR_SUCCESS) {
  867. //
  868. // Save this initial value
  869. //
  870. AdvancedData->RxFIFO = dwFifo;
  871. if (AdvancedData->RxFIFO > RX_MAX) {
  872. goto SetRxFIFO;
  873. }
  874. }
  875. else {
  876. SetRxFIFO:
  877. //
  878. // value does not exist. Create our own
  879. //
  880. dwData = AdvancedData->FifoRxMax;
  881. dwSize = sizeof(dwData);
  882. dwError = RegSetValueEx(hDeviceKey,
  883. m_szRxFIFO,
  884. 0,
  885. REG_DWORD,
  886. (CONST BYTE *)(&dwData),
  887. dwSize);
  888. if (dwError == ERROR_SUCCESS) {
  889. AdvancedData->RxFIFO = AdvancedData->FifoRxMax;
  890. }
  891. else {
  892. AdvancedData->RxFIFO = 0;
  893. AdvancedData->UseRxFIFOControl = FALSE;
  894. }
  895. }
  896. //
  897. // Get TxFIFO information
  898. //
  899. AdvancedData->UseTxFIFOControl = TRUE;
  900. dwSize = sizeof(dwFifo);
  901. dwError = RegQueryValueEx(hDeviceKey,
  902. m_szTxFIFO,
  903. NULL,
  904. NULL,
  905. (LPBYTE)(&dwFifo),
  906. &dwSize);
  907. if (dwError == ERROR_SUCCESS) {
  908. //
  909. // Save this initial value
  910. //
  911. AdvancedData->TxFIFO = dwFifo;
  912. if (AdvancedData->TxFIFO > TX_MAX) {
  913. goto SetTxFIFO;
  914. }
  915. }
  916. else {
  917. SetTxFIFO:
  918. //
  919. // value does not exist. Create our own
  920. //
  921. dwData = AdvancedData->FifoTxMax;
  922. dwSize = sizeof(dwData);
  923. dwError = RegSetValueEx(hDeviceKey,
  924. m_szTxFIFO,
  925. 0,
  926. REG_DWORD,
  927. (LPBYTE)(&dwData),
  928. dwSize);
  929. if (dwError == ERROR_SUCCESS) {
  930. AdvancedData->TxFIFO = AdvancedData->FifoTxMax;
  931. }
  932. else {
  933. AdvancedData->TxFIFO = 0;
  934. AdvancedData->UseTxFIFOControl = FALSE;
  935. }
  936. }
  937. #endif
  938. //
  939. // Get PPP Aware flag
  940. //
  941. // AdvancedData->PPPAware = TRUE;
  942. //
  943. // dwSize = sizeof(dwData);
  944. // dwError = RegQueryValueEx(hDeviceKey,
  945. // m_szPPPAware,
  946. // NULL,
  947. // NULL,
  948. // (LPBYTE)(&dwData),
  949. // &dwSize);
  950. // if (dwError == ERROR_SUCCESS) {
  951. // AdvancedData->PPPAware = dwData;
  952. // } else {
  953. // //
  954. // // value does not exist. Create our own
  955. // //
  956. // dwData = AdvancedData->PPPAware;
  957. // dwSize = sizeof(dwData);
  958. // dwError = RegSetValueEx(hDeviceKey,
  959. // m_szPPPAware,
  960. // 0,
  961. // REG_DWORD,
  962. // (LPBYTE)(&dwData),
  963. // dwSize);
  964. // }
  965. //
  966. // Get Write Complete information
  967. //
  968. AdvancedData->WriteComplete = FALSE;
  969. dwSize = sizeof(dwData);
  970. dwError = RegQueryValueEx(hDeviceKey,
  971. m_szWriteComplete,
  972. NULL,
  973. NULL,
  974. (LPBYTE)(&dwData),
  975. &dwSize);
  976. if (dwError == ERROR_SUCCESS) {
  977. AdvancedData->WriteComplete = dwData;
  978. } else {
  979. //
  980. // value does not exist. Create our own
  981. //
  982. dwData = AdvancedData->WriteComplete;
  983. dwSize = sizeof(dwData);
  984. dwError = RegSetValueEx(hDeviceKey,
  985. m_szWriteComplete,
  986. 0,
  987. REG_DWORD,
  988. (LPBYTE)(&dwData),
  989. dwSize);
  990. }
  991. //
  992. // Get Polling Period information
  993. //
  994. AdvancedData->PollingPeriod = PollingPeriods[POLL_PERIOD_DEFAULT_IDX];
  995. dwSize = sizeof(dwFifo);
  996. dwError = RegQueryValueEx(hDeviceKey,
  997. m_szPollingPeriod,
  998. NULL,
  999. NULL,
  1000. (LPBYTE)(&dwFifo),
  1001. &dwSize);
  1002. if (dwError == ERROR_SUCCESS) {
  1003. //
  1004. // Save this initial value
  1005. //
  1006. AdvancedData->PollingPeriod = dwFifo;
  1007. }
  1008. else {
  1009. //
  1010. // value does not exist. Create our own
  1011. //
  1012. dwData = AdvancedData->PollingPeriod;
  1013. dwSize = sizeof(dwData);
  1014. dwError = RegSetValueEx(hDeviceKey,
  1015. m_szPollingPeriod,
  1016. 0,
  1017. REG_DWORD,
  1018. (LPBYTE)(&dwData),
  1019. dwSize);
  1020. }
  1021. RegCloseKey(hDeviceKey);
  1022. if (ERROR_SUCCESS != dwError) {
  1023. return dwError;
  1024. }
  1025. else {
  1026. return ERROR_SUCCESS;
  1027. }
  1028. } /* FillAdvancedDlg*/
  1029. void
  1030. ChangeParentTitle(
  1031. IN HWND Hwnd,
  1032. IN LPCTSTR OldComName,
  1033. IN LPCTSTR NewComName
  1034. )
  1035. {
  1036. INT textLength, offset, newNameLen, oldNameLen;
  1037. PTCHAR oldTitle = NULL, newTitle = NULL;
  1038. PTCHAR oldLocation;
  1039. textLength = GetWindowTextLength(Hwnd);
  1040. if (textLength == 0) {
  1041. return;
  1042. }
  1043. //
  1044. // Account for null char and unicode
  1045. //
  1046. textLength++;
  1047. oldTitle = (PTCHAR) LocalAlloc(LPTR, textLength * sizeof(TCHAR));
  1048. if (!oldTitle) {
  1049. return;
  1050. }
  1051. if (!GetWindowText(Hwnd, oldTitle, textLength)) {
  1052. goto exit;
  1053. }
  1054. oldLocation = wcsstr(oldTitle, OldComName);
  1055. if (!oldLocation) {
  1056. goto exit;
  1057. }
  1058. newNameLen = lstrlen(NewComName);
  1059. oldNameLen = lstrlen(OldComName);
  1060. offset = newNameLen - oldNameLen;
  1061. if (offset > 0) {
  1062. textLength += offset;
  1063. }
  1064. newTitle = (PTCHAR) LocalAlloc(LPTR, textLength * sizeof(TCHAR));
  1065. if (!newTitle) {
  1066. goto exit;
  1067. }
  1068. //
  1069. // Find the OldComName in the title and do the following
  1070. // 1) up to that location in the string
  1071. // 2) copy the new name
  1072. // 3) copy the remainder of the string after OldComName
  1073. //
  1074. offset = (INT)(oldLocation - oldTitle);
  1075. CopyMemory(newTitle, oldTitle, offset * sizeof(TCHAR)); // 1
  1076. CopyMemory(newTitle + offset, NewComName, newNameLen * sizeof(TCHAR)); // 2
  1077. lstrcpy(newTitle + offset + newNameLen, oldLocation + oldNameLen); // 3
  1078. SetWindowText(Hwnd, newTitle);
  1079. exit:
  1080. if (oldTitle) {
  1081. LocalFree(oldTitle);
  1082. }
  1083. if (newTitle) {
  1084. LocalFree(newTitle);
  1085. }
  1086. }
  1087. void
  1088. MigratePortSettings(
  1089. LPCTSTR OldComName,
  1090. LPCTSTR NewComName
  1091. )
  1092. {
  1093. TCHAR settings[BUFFER_SIZE];
  1094. TCHAR szNew[20], szOld[20];
  1095. lstrcpy(szOld, OldComName);
  1096. wcscat(szOld, m_szColon);
  1097. lstrcpy(szNew, NewComName);
  1098. wcscat(szNew, m_szColon);
  1099. settings[0] = TEXT('\0');
  1100. GetProfileString(m_szPorts,
  1101. szOld,
  1102. TEXT(""),
  1103. settings,
  1104. sizeof(settings) / sizeof(TCHAR) );
  1105. //
  1106. // Insert the new key based on the old one
  1107. //
  1108. if (settings[0] == TEXT('\0')) {
  1109. WriteProfileString(m_szPorts, szNew, m_szDefParams);
  1110. }
  1111. else {
  1112. WriteProfileString(m_szPorts, szNew, settings);
  1113. }
  1114. //
  1115. // Notify everybody of the changes and blow away the old key
  1116. //
  1117. SendWinIniChange((LPTSTR)m_szPorts);
  1118. WriteProfileString(m_szPorts, szOld, NULL);
  1119. }
  1120. void
  1121. EnactComNameChanges(
  1122. IN HWND ParentHwnd,
  1123. IN PADVANCED_DATA AdvancedData,
  1124. IN HKEY hDeviceKey,
  1125. IN UINT NewComNum)
  1126. {
  1127. DWORD dwNewComNameLen;
  1128. TCHAR buffer[BUFFER_SIZE];
  1129. TCHAR szFriendlyNameFormat[LINE_LEN];
  1130. TCHAR szDeviceDesc[LINE_LEN];
  1131. PTCHAR szNewComName;
  1132. UINT i;
  1133. UINT curComNum;
  1134. BOOLEAN updateMapping = TRUE;
  1135. SP_DEVINSTALL_PARAMS spDevInstall;
  1136. curComNum = myatoi(AdvancedData->szComName + wcslen(m_szCOM));
  1137. if (AdvancedData->hComDB != HCOMDB_INVALID_HANDLE_VALUE) {
  1138. BYTE portUsage[MAX_COM_PORT/8];
  1139. DWORD portsReported = 0;
  1140. char mask;
  1141. //
  1142. // Check to see if the desired new COM number has been claimed in the
  1143. // com name database. If so, ask the user if they are *really* sure
  1144. //
  1145. ComDBGetCurrentPortUsage(AdvancedData->hComDB,
  1146. portUsage,
  1147. MAX_COM_PORT / 8,
  1148. CDB_REPORT_BITS,
  1149. &portsReported);
  1150. if (NewComNum > portsReported) {
  1151. DWORD newsize;
  1152. if (NewComNum > COMDB_MAX_PORTS_ARBITRATED) {
  1153. MyMessageBox(ParentHwnd, IDS_PORT_RENAME_ERROR, IDS_NAME_PROPERTIES,
  1154. MB_ICONERROR);
  1155. return;
  1156. }
  1157. newsize = NewComNum;
  1158. if (NewComNum % 1024){
  1159. newsize = NewComNum/1024;
  1160. newsize++;
  1161. newsize = newsize*1024;
  1162. }
  1163. if (newsize > COMDB_MAX_PORTS_ARBITRATED) {
  1164. newsize = COMDB_MAX_PORTS_ARBITRATED;
  1165. }
  1166. if (newsize > portsReported) {
  1167. if (ComDBResizeDatabase(AdvancedData->hComDB, newsize) != ERROR_SUCCESS){
  1168. MyMessageBox(ParentHwnd, IDS_PORT_RENAME_ERROR, IDS_NAME_PROPERTIES,
  1169. MB_ICONERROR);
  1170. return;
  1171. }
  1172. }
  1173. // We are assuming that NewComNum is <= MAX_COM_PORT.
  1174. ComDBGetCurrentPortUsage(AdvancedData->hComDB,
  1175. portUsage,
  1176. MAX_COM_PORT / 8,
  1177. CDB_REPORT_BITS,
  1178. &portsReported);
  1179. }
  1180. if ((i = NewComNum % 8))
  1181. mask = 1 << (i-1);
  1182. else
  1183. mask = (char) 0x80;
  1184. if ((portUsage[(NewComNum-1)/8] & mask) &&
  1185. MyMessageBox(ParentHwnd, IDS_PORT_IN_USE, IDS_NAME_PROPERTIES,
  1186. MB_YESNO | MB_ICONINFORMATION) == IDNO) {
  1187. //
  1188. // Port has been previously claimed and user doesn't want to override
  1189. //
  1190. return;
  1191. }
  1192. }
  1193. if (!QueryDosDevice(AdvancedData->szComName, buffer, BUFFER_SIZE-1)) {
  1194. //
  1195. // The old com name does not exist in the mapping. Basically, the symbolic
  1196. // link from COMX => \Device\SerialY has been broken. Just change the
  1197. // value in the registry and the friendly name for the device; don't
  1198. // change the dos symbolic name b/c one does not exist
  1199. //
  1200. updateMapping = FALSE;
  1201. }
  1202. else {
  1203. TCHAR szComFileName[20]; // more than enough for "\\.\COMXxxx"
  1204. HANDLE hCom;
  1205. lstrcpy(szComFileName, L"\\\\.\\");
  1206. lstrcat(szComFileName, AdvancedData->szComName);
  1207. //
  1208. // Make sure that the port has not been opened by another application
  1209. //
  1210. hCom = CreateFile(szComFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING,
  1211. FILE_ATTRIBUTE_NORMAL, NULL);
  1212. //
  1213. // If the file handle is invalid, then the com port is open, warn the user
  1214. //
  1215. if (hCom == INVALID_HANDLE_VALUE &&
  1216. MyMessageBox(ParentHwnd, IDS_PORT_OPEN, IDS_NAME_PROPERTIES,
  1217. MB_YESNO | MB_ICONERROR) == IDNO) {
  1218. return;
  1219. }
  1220. if (hCom != INVALID_HANDLE_VALUE) {
  1221. CloseHandle(hCom);
  1222. }
  1223. }
  1224. szNewComName = AdvancedData->szNewComName;
  1225. wsprintf(szNewComName, _T("COM%d"), NewComNum);
  1226. dwNewComNameLen = ByteCountOf(wcslen(szNewComName) + 1);
  1227. //
  1228. // Change the name in the symbolic namespace.
  1229. // First try to get what device the old com name mapped to
  1230. // (ie something like \Device\Serial0). Then remove the mapping. If
  1231. // the user isn't an admin, then this will fail and the dialog will popup.
  1232. // Finally, map the new name to the old device retrieved from the
  1233. // QueryDosDevice
  1234. //
  1235. if (updateMapping) {
  1236. BOOL removed;
  1237. HKEY hSerialMap;
  1238. if (!QueryDosDevice(AdvancedData->szComName, buffer, BUFFER_SIZE-1)) {
  1239. //
  1240. // This shouldn't happen because the previous QueryDosDevice call
  1241. // succeeded
  1242. //
  1243. MyMessageBox(ParentHwnd, IDS_PORT_RENAME_ERROR, IDS_NAME_PROPERTIES,
  1244. MB_ICONERROR);
  1245. return;
  1246. }
  1247. //
  1248. // If this fails, then the following define will just replace the current
  1249. // mapping.
  1250. //
  1251. removed = DefineDosDevice(DDD_REMOVE_DEFINITION, AdvancedData->szComName, NULL);
  1252. if (!DefineDosDevice(DDD_RAW_TARGET_PATH, szNewComName, buffer)) {
  1253. //
  1254. // error, first fix up the remove definition and restore the old
  1255. // mapping
  1256. //
  1257. if (removed) {
  1258. DefineDosDevice(DDD_RAW_TARGET_PATH, AdvancedData->szComName, buffer);
  1259. }
  1260. MyMessageBox(ParentHwnd, IDS_PORT_RENAME_ERROR, IDS_NAME_PROPERTIES,
  1261. MB_ICONERROR);
  1262. return;
  1263. }
  1264. //
  1265. // Set the \\HARDWARE\DEVICEMAP\SERIALCOMM field
  1266. //
  1267. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1268. m_szRegSerialMap,
  1269. 0,
  1270. KEY_ALL_ACCESS,
  1271. &hSerialMap) == ERROR_SUCCESS) {
  1272. TCHAR szSerial[BUFFER_SIZE];
  1273. DWORD dwSerialSize, dwEnum, dwType, dwComSize;
  1274. TCHAR szCom[BUFFER_SIZE];
  1275. i = 0;
  1276. do {
  1277. dwSerialSize = CharSizeOf(szSerial);
  1278. dwComSize = sizeof(szCom);
  1279. dwEnum = RegEnumValue(hSerialMap,
  1280. i++,
  1281. szSerial,
  1282. &dwSerialSize,
  1283. NULL,
  1284. &dwType,
  1285. (LPBYTE)szCom,
  1286. &dwComSize);
  1287. if (dwEnum == ERROR_SUCCESS) {
  1288. if(dwType != REG_SZ)
  1289. continue;
  1290. if (wcscmp(szCom, AdvancedData->szComName) == 0) {
  1291. RegSetValueEx(hSerialMap,
  1292. szSerial,
  1293. 0,
  1294. REG_SZ,
  1295. (PBYTE) szNewComName,
  1296. dwNewComNameLen);
  1297. break;
  1298. }
  1299. }
  1300. } while (dwEnum == ERROR_SUCCESS);
  1301. }
  1302. RegCloseKey(hSerialMap);
  1303. }
  1304. //
  1305. // Update the com db
  1306. //
  1307. if (AdvancedData->hComDB != HCOMDB_INVALID_HANDLE_VALUE) {
  1308. ComDBReleasePort(AdvancedData->hComDB, (DWORD) curComNum);
  1309. ComDBClaimPort(AdvancedData->hComDB, (DWORD) NewComNum, TRUE, NULL);
  1310. }
  1311. //
  1312. // Set the friendly name in the form of DeviceDesc (COM#)
  1313. //
  1314. if (ReplaceFriendlyName(AdvancedData->DeviceInfoSet,
  1315. AdvancedData->DeviceInfoData,
  1316. szNewComName) == FALSE) {
  1317. // ReplaceFriendlyName failed. Use original code.
  1318. if (LoadString(g_hInst,
  1319. IDS_FRIENDLY_FORMAT,
  1320. szFriendlyNameFormat,
  1321. CharSizeOf(szFriendlyNameFormat)) &&
  1322. SetupDiGetDeviceRegistryProperty(AdvancedData->DeviceInfoSet,
  1323. AdvancedData->DeviceInfoData,
  1324. SPDRP_DEVICEDESC,
  1325. NULL,
  1326. (PBYTE) szDeviceDesc,
  1327. sizeof(szDeviceDesc),
  1328. NULL)) {
  1329. wsprintf(buffer, szFriendlyNameFormat, szDeviceDesc, szNewComName);
  1330. }
  1331. else {
  1332. //
  1333. // Use the COM port name straight out
  1334. //
  1335. lstrcpy(buffer, szNewComName);
  1336. }
  1337. SetupDiSetDeviceRegistryProperty(AdvancedData->DeviceInfoSet,
  1338. AdvancedData->DeviceInfoData,
  1339. SPDRP_FRIENDLYNAME,
  1340. (PBYTE) buffer,
  1341. ByteCountOf(wcslen(buffer)+1));
  1342. }
  1343. //
  1344. // Set the parent dialog's title to reflect the change in the com port's name
  1345. //
  1346. ChangeParentTitle(GetParent(ParentHwnd), AdvancedData->szComName, szNewComName);
  1347. MigratePortSettings(AdvancedData->szComName, szNewComName);
  1348. //
  1349. // Update the PortName value in the devnode
  1350. //
  1351. RegSetValueEx(hDeviceKey,
  1352. m_szPortName,
  1353. 0,
  1354. REG_SZ,
  1355. (PBYTE)szNewComName,
  1356. dwNewComNameLen);
  1357. //
  1358. // Now broadcast this change to the device manager
  1359. //
  1360. ZeroMemory(&spDevInstall, sizeof(SP_DEVINSTALL_PARAMS));
  1361. spDevInstall.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
  1362. if (SetupDiGetDeviceInstallParams(AdvancedData->DeviceInfoSet,
  1363. AdvancedData->DeviceInfoData,
  1364. &spDevInstall)) {
  1365. spDevInstall.Flags |= DI_PROPERTIES_CHANGE;
  1366. SetupDiSetDeviceInstallParams(AdvancedData->DeviceInfoSet,
  1367. AdvancedData->DeviceInfoData,
  1368. &spDevInstall);
  1369. }
  1370. }
  1371. /*++
  1372. Routine Description: SaveAdvancedSettings
  1373. saves the advanced box settings back to the registry, if any were
  1374. changed
  1375. Arguments:
  1376. AdvancedData: holds the current settings and the location of of
  1377. the device in the registry
  1378. ParentHwnd: address of the window
  1379. Return Value:
  1380. ULONG: returns error messages
  1381. --*/
  1382. ULONG
  1383. SaveAdvancedSettings(
  1384. IN HWND ParentHwnd,
  1385. IN PADVANCED_DATA AdvancedData
  1386. )
  1387. {
  1388. HKEY hDeviceKey;
  1389. DWORD dwSize, dwData;
  1390. UINT i = CB_ERR, curComNum, newComNum = CB_ERR;
  1391. //UINT uiDlgButtonChecked;
  1392. UINT uiWriteCompleteChecked; //uiPPPAwareChecked,
  1393. DWORD dwPollingPeriod; // dwRxPosition, dwTxPosition;
  1394. BOOLEAN needRestart = FALSE;
  1395. HCURSOR hCursor;
  1396. SP_DEVINSTALL_PARAMS spDevInstall;
  1397. SP_PROPCHANGE_PARAMS PropChangeParams = {sizeof(SP_CLASSINSTALL_HEADER)};
  1398. //DbgOut(TEXT("SaveAdvancedSettings\n"));
  1399. //
  1400. // Grab all of the new settings
  1401. //
  1402. // uiPPPAwareChecked = IsDlgButtonChecked(ParentHwnd, IDC_PPP_AWARE);
  1403. uiWriteCompleteChecked = IsDlgButtonChecked(ParentHwnd, IDC_WRITE_COMPLETE);
  1404. //uiDlgButtonChecked = IsDlgButtonChecked(ParentHwnd, IDC_FIFO);
  1405. //#if DBG
  1406. //{
  1407. // TCHAR buf[500];
  1408. // wsprintf(buf, TEXT("uiPPPAwareChecked %d\n"),uiPPPAwareChecked);
  1409. // DbgOut(buf);
  1410. // wsprintf(buf, TEXT("AdvancedData->PPPAware %d\n"),AdvancedData->PPPAware);
  1411. // DbgOut(buf);
  1412. //}
  1413. //#endif
  1414. //dwTxPosition = Trackbar_GetPos(GetDlgItem(ParentHwnd, IDC_TRANSMIT_SLIDER));
  1415. //dwRxPosition = Trackbar_GetPos(GetDlgItem(ParentHwnd, IDC_RECEIVE_SLIDER));
  1416. //
  1417. // Index is actually into the array of values
  1418. //
  1419. //dwRxPosition = RxValues[dwRxPosition-1];
  1420. curComNum = myatoi(AdvancedData->szComName + wcslen(m_szCOM));
  1421. newComNum = ComboBox_GetCurSel(GetDlgItem(ParentHwnd, PP_PORT_NUMBER));
  1422. if (newComNum == CB_ERR) {
  1423. newComNum = curComNum;
  1424. }
  1425. else {
  1426. newComNum++;
  1427. }
  1428. i = ComboBox_GetCurSel(GetDlgItem(ParentHwnd, IDC_POLL_PERIOD));
  1429. if (i == CB_ERR || i >= NUM_POLLING_PERIODS) {
  1430. dwPollingPeriod = AdvancedData->PollingPeriod;
  1431. }
  1432. else {
  1433. dwPollingPeriod = PollingPeriods[i];
  1434. }
  1435. //
  1436. // See if they changed anything
  1437. //
  1438. if (//((AdvancedData->UseFifoBuffers && uiDlgButtonChecked == BST_CHECKED) ||
  1439. // (!AdvancedData->UseFifoBuffers && uiDlgButtonChecked == BST_UNCHECKED)) &&
  1440. //AdvancedData->RxFIFO == dwRxPosition &&
  1441. //AdvancedData->TxFIFO == dwTxPosition &&
  1442. //((AdvancedData->PPPAware && uiPPPAwareChecked == BST_CHECKED) ||
  1443. // (!AdvancedData->PPPAware && uiPPPAwareChecked == BST_UNCHECKED)) &&
  1444. ((AdvancedData->WriteComplete && uiWriteCompleteChecked == BST_CHECKED) ||
  1445. (!AdvancedData->WriteComplete && uiWriteCompleteChecked == BST_UNCHECKED)) &&
  1446. AdvancedData->PollingPeriod == dwPollingPeriod &&
  1447. newComNum == curComNum) {
  1448. //
  1449. // They didn't change anything. Just exit.
  1450. //
  1451. return ERROR_SUCCESS;
  1452. }
  1453. //
  1454. // Open the device key for the source device instance
  1455. //
  1456. hDeviceKey = SetupDiOpenDevRegKey(AdvancedData->DeviceInfoSet,
  1457. AdvancedData->DeviceInfoData,
  1458. DICS_FLAG_GLOBAL,
  1459. 0,
  1460. DIREG_DEV,
  1461. KEY_ALL_ACCESS);
  1462. if (INVALID_HANDLE_VALUE == hDeviceKey) {
  1463. //
  1464. // Not much we can do without a valid key, exit gracefully
  1465. //
  1466. return ERROR_SUCCESS;
  1467. }
  1468. //
  1469. // Check to see if the user changed the COM port name
  1470. //
  1471. if (newComNum != curComNum) {
  1472. EnactComNameChanges(ParentHwnd,
  1473. AdvancedData,
  1474. hDeviceKey,
  1475. newComNum);
  1476. }
  1477. // if ((AdvancedData->PPPAware && uiPPPAwareChecked == BST_UNCHECKED) ||
  1478. // (!AdvancedData->PPPAware && uiPPPAwareChecked == BST_CHECKED)) {
  1479. // //
  1480. // // They changed the Enable Optimization For RRAS checkbox.
  1481. // //
  1482. // dwData = (uiPPPAwareChecked == BST_CHECKED) ? 1 : 0;
  1483. // dwSize = sizeof(dwData);
  1484. // RegSetValueEx(hDeviceKey,
  1485. // m_szPPPAware,
  1486. // 0,
  1487. // REG_DWORD,
  1488. // (CONST BYTE *)(&dwData),
  1489. // dwSize);
  1490. // needRestart = TRUE;
  1491. // //Out(TEXT("needRestart = TRUE.\n"));
  1492. // }
  1493. if ((AdvancedData->WriteComplete && uiWriteCompleteChecked == BST_UNCHECKED) ||
  1494. (!AdvancedData->WriteComplete && uiWriteCompleteChecked == BST_CHECKED)) {
  1495. //
  1496. // They changed the Return Write status only after firmware buffer empty checkbox
  1497. //
  1498. dwData = (uiWriteCompleteChecked == BST_CHECKED) ? 1 : 0;
  1499. dwSize = sizeof(dwData);
  1500. RegSetValueEx(hDeviceKey,
  1501. m_szWriteComplete,
  1502. 0,
  1503. REG_DWORD,
  1504. (CONST BYTE *)(&dwData),
  1505. dwSize);
  1506. needRestart = TRUE;
  1507. }
  1508. // if ((AdvancedData->UseFifoBuffers && uiDlgButtonChecked == BST_UNCHECKED) ||
  1509. // (!AdvancedData->UseFifoBuffers && uiDlgButtonChecked == BST_CHECKED)) {
  1510. // //
  1511. // // They changed the Use Fifo checkbox.
  1512. // //
  1513. // dwData = (uiDlgButtonChecked == BST_CHECKED) ? 1 : 0;
  1514. // dwSize = sizeof(dwData);
  1515. // RegSetValueEx(hDeviceKey,
  1516. // m_szFIFO,
  1517. // 0,
  1518. // REG_DWORD,
  1519. // (CONST BYTE *)(&dwData),
  1520. // dwSize);
  1521. // }
  1522. //
  1523. // if (AdvancedData->RxFIFO != dwRxPosition) {
  1524. // //
  1525. // // They changed the RxFIFO setting
  1526. // //
  1527. // dwData = dwRxPosition;
  1528. // dwSize = sizeof(dwData);
  1529. // RegSetValueEx(hDeviceKey,
  1530. // m_szRxFIFO,
  1531. // 0,
  1532. // REG_DWORD,
  1533. // (CONST BYTE *)(&dwData),
  1534. // dwSize);
  1535. // }
  1536. //
  1537. // if (AdvancedData->TxFIFO != dwTxPosition) {
  1538. // //
  1539. // // They changed the TxFIFO setting
  1540. // //
  1541. // dwData = dwTxPosition;
  1542. // dwSize = sizeof(dwData);
  1543. // RegSetValueEx(hDeviceKey,
  1544. // m_szTxFIFO,
  1545. // 0,
  1546. // REG_DWORD,
  1547. // (CONST BYTE *)(&dwData),
  1548. // dwSize);
  1549. // }
  1550. if (AdvancedData->PollingPeriod != dwPollingPeriod) {
  1551. //
  1552. // They changed the polling period
  1553. //
  1554. dwData = dwPollingPeriod;
  1555. dwSize = sizeof(dwData);
  1556. RegSetValueEx(hDeviceKey,
  1557. m_szPollingPeriod,
  1558. 0,
  1559. REG_DWORD,
  1560. (CONST BYTE *)(&dwData),
  1561. dwSize);
  1562. //
  1563. // Don't really care if this fails, nothing else we can do
  1564. //
  1565. CM_Reenumerate_DevNode(AdvancedData->DeviceInfoData->DevInst,
  1566. CM_REENUMERATE_NORMAL);
  1567. }
  1568. RegCloseKey(hDeviceKey);
  1569. if (needRestart) {
  1570. //Out(TEXT("Re-starting.\n"));
  1571. //
  1572. // This may take a while :^(
  1573. //
  1574. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  1575. //
  1576. // Set the PropChangeParams structure.
  1577. //
  1578. PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
  1579. PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
  1580. PropChangeParams.Scope = DICS_FLAG_GLOBAL;
  1581. PropChangeParams.StateChange = DICS_PROPCHANGE ;
  1582. if (!SetupDiSetClassInstallParams(AdvancedData->DeviceInfoSet,
  1583. AdvancedData->DeviceInfoData,
  1584. (SP_CLASSINSTALL_HEADER *)&PropChangeParams,
  1585. sizeof(PropChangeParams)))
  1586. {
  1587. DbgOut(TEXT("SetupDiSetClassInstallParams failed.\n"));
  1588. }
  1589. } else {
  1590. SetupDiSetClassInstallParams(AdvancedData->DeviceInfoSet,
  1591. AdvancedData->DeviceInfoData,
  1592. NULL,
  1593. 0);
  1594. }
  1595. SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,
  1596. AdvancedData->DeviceInfoSet,
  1597. AdvancedData->DeviceInfoData);
  1598. return ERROR_SUCCESS;
  1599. } /* SaveAdvancedSettings*/
  1600. /*++
  1601. Routine Description:
  1602. Prototype to allow serial port vendors to override the advanced dialog
  1603. represented by the COM port specified by DeviceInfoSet and DeviceInfoData.
  1604. To override the advanced page, place a value named EnumAdvancedDialog under
  1605. the same key in which you would put your EnumPropPages32 value. The format
  1606. of the value is exactly the same as Enum...32 as well.
  1607. Arguments:
  1608. ParentHwnd - the parent window of the window to be displayed
  1609. HidePollingUI - If TRUE, hide all UI that deals with polling.
  1610. DeviceInfoSet, DeviceInfoData - SetupDi structures representing the COM port
  1611. Reserved - Unused
  1612. Return Value:
  1613. TRUE if the user pressed OK, FALSE if Cancel was pressed
  1614. --*/
  1615. BOOL
  1616. CyzportAdvancedDialog(
  1617. IN HWND ParentHwnd,
  1618. IN BOOL HidePollingUI,
  1619. IN HDEVINFO DeviceInfoSet,
  1620. IN PSP_DEVINFO_DATA DeviceInfoData,
  1621. IN PVOID Reserved
  1622. )
  1623. {
  1624. PADVANCED_DATA pAdvancedData = NULL;
  1625. // DbgOut(TEXT("CyzportAdvancedDialog\n"));
  1626. pAdvancedData = (PADVANCED_DATA) LocalAlloc(LPTR, sizeof(ADVANCED_DATA));
  1627. //**************************************************************
  1628. // TEST Debugger
  1629. // DebugBreak();
  1630. //**************************************************************
  1631. if (pAdvancedData == NULL) {
  1632. ErrMemDlg(ParentHwnd);
  1633. return FALSE;
  1634. }
  1635. //***************** FOR DEBUG *********************
  1636. //
  1637. //HidePollingUI = FALSE;
  1638. //*************************************************
  1639. pAdvancedData->HidePolling = HidePollingUI;
  1640. pAdvancedData->DeviceInfoSet = DeviceInfoSet;
  1641. pAdvancedData->DeviceInfoData = DeviceInfoData;
  1642. DisplayAdvancedDialog(ParentHwnd, pAdvancedData);
  1643. if (pAdvancedData != NULL) {
  1644. LocalFree(pAdvancedData);
  1645. }
  1646. return TRUE;
  1647. }