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.

1776 lines
50 KiB

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