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.

933 lines
29 KiB

  1. /*-------------------------------------------------------------------
  2. | portprop.c - Port Properties Sheet.
  3. |--------------------------------------------------------------------*/
  4. #include "precomp.h"
  5. #define D_Level 0x10
  6. static void set_field(HWND hDlg, WORD id);
  7. static void get_field(HWND hDlg, WORD id);
  8. //static int PaintIcon(HWND hWnd);
  9. #define MAX_PORTPROP_SHEETS 3
  10. #define QUERYSIB_CLONE_PORT_PROPS 1
  11. #define CLONEOPT_ALL 1 // clone to all ports
  12. #define CLONEOPT_DEVICE 2 // clone to all ports on selected device
  13. #define CLONEOPT_SELECT 3 // clone to selected ports (lParam = *list)
  14. int FillPortPropSheets(PROPSHEETPAGE *psp, LPARAM our_params);
  15. BOOL WINAPI PortPropSheet(
  16. IN HWND hDlg,
  17. IN UINT uMessage,
  18. IN WPARAM wParam,
  19. IN LPARAM lParam);
  20. BOOL WINAPI PortProp485Sheet(
  21. IN HWND hDlg,
  22. IN UINT uMessage,
  23. IN WPARAM wParam,
  24. IN LPARAM lParam);
  25. BOOL WINAPI PortPropModemSheet(
  26. IN HWND hDlg,
  27. IN UINT uMessage,
  28. IN WPARAM wParam,
  29. IN LPARAM lParam);
  30. static int our_port_index = 0;
  31. static int our_device_index = 0;
  32. static int num_active_portprop_sheets = 1; // always at least one
  33. /*------------------------------------------------------------------------
  34. | FillPortPropSheets - Setup pages for driver level property sheets.
  35. |------------------------------------------------------------------------*/
  36. int FillPortPropSheets(PROPSHEETPAGE *psp, LPARAM our_params)
  37. {
  38. INT pi;
  39. static TCHAR portsetstr[40], rs485str[40], modemstr[40];
  40. memset(psp, 0, sizeof(*psp) * MAX_PORTPROP_SHEETS);
  41. pi = 0;
  42. //----- main prop device sheet.
  43. psp[pi].dwSize = sizeof(PROPSHEETPAGE);
  44. //psp[pi].dwFlags = PSP_USEICONID | PSP_USETITLE;
  45. psp[pi].dwFlags = PSP_USETITLE | PSP_HASHELP;
  46. psp[pi].hInstance = glob_hinst;
  47. psp[pi].pszTemplate = MAKEINTRESOURCE(IDD_PORT_OPTIONS);
  48. psp[pi].pfnDlgProc = PortPropSheet;
  49. load_str( glob_hinst, (TITLESTR+4), portsetstr, CharSizeOf(portsetstr) );
  50. psp[pi].pszTitle = portsetstr;
  51. psp[pi].lParam = (LPARAM)our_params;
  52. psp[pi].pfnCallback = NULL;
  53. ++pi;
  54. num_active_portprop_sheets = 1;
  55. //----- rs-485 prop device sheet.
  56. if (((strstr(wi->dev[glob_info->device_selected].ModelName, "485")) &&
  57. (our_port_index < 2)) ||
  58. (wi->GlobalRS485 == 1))
  59. {
  60. psp[pi].dwSize = sizeof(PROPSHEETPAGE);
  61. //psp[pi].dwFlags = PSP_USEICONID | PSP_USETITLE;
  62. psp[pi].dwFlags = PSP_USETITLE | PSP_HASHELP;
  63. psp[pi].hInstance = glob_hinst;
  64. psp[pi].pszTemplate = MAKEINTRESOURCE(IDD_PORT_485_OPTIONS);
  65. psp[pi].pfnDlgProc = PortProp485Sheet;
  66. load_str( glob_hinst, (TITLESTR+5), rs485str, CharSizeOf(rs485str) );
  67. psp[pi].pszTitle = rs485str;
  68. psp[pi].lParam = (LPARAM)our_params;
  69. psp[pi].pfnCallback = NULL;
  70. ++pi;
  71. ++num_active_portprop_sheets;
  72. }
  73. //----- modem prop device sheet.
  74. if (wi->dev[glob_info->device_selected].ModemDevice)
  75. {
  76. psp[pi].dwSize = sizeof(PROPSHEETPAGE);
  77. //psp[pi].dwFlags = PSP_USEICONID | PSP_USETITLE;
  78. psp[pi].dwFlags = PSP_USETITLE | PSP_HASHELP;
  79. psp[pi].hInstance = glob_hinst;
  80. psp[pi].pszTemplate = MAKEINTRESOURCE(IDD_PORT_MODEM_OPTIONS);
  81. psp[pi].pfnDlgProc = PortPropModemSheet;
  82. load_str( glob_hinst, (TITLESTR+6), modemstr, CharSizeOf(modemstr) );
  83. psp[pi].pszTitle = modemstr;
  84. psp[pi].lParam = (LPARAM)our_params;
  85. psp[pi].pfnCallback = NULL;
  86. ++pi;
  87. ++num_active_portprop_sheets;
  88. }
  89. return 0;
  90. }
  91. /*------------------------------------------------------------------------
  92. | DoPortPropPages - Main driver level property sheet for NT4.0
  93. |------------------------------------------------------------------------*/
  94. int DoPortPropPages(HWND hwndOwner, int device, int port)
  95. {
  96. PROPSHEETPAGE psp[MAX_PORTPROP_SHEETS];
  97. PROPSHEETHEADER psh;
  98. OUR_INFO *our_params;
  99. INT stat;
  100. Port_Config *pc;
  101. char title[40];
  102. wi->ChangesMade = 1; // indicate changes made, as send_to_driver
  103. // does not calculate this yet
  104. our_port_index = port;
  105. our_device_index = device;
  106. pc = &wi->dev[our_device_index].ports[our_port_index];
  107. strcpy(title, pc->Name);
  108. strcat(title, RcStr(MSGSTR+29));
  109. our_params = glob_info; // temporary kludge, unless we don't need re-entrantancy
  110. //Fill out the PROPSHEETPAGE data structure for the Client Area Shape
  111. //sheet
  112. FillPortPropSheets(&psp[0], (LPARAM)our_params);
  113. //Fill out the PROPSHEETHEADER
  114. memset(&psh, 0, sizeof(PROPSHEETHEADER));
  115. psh.dwSize = sizeof(PROPSHEETHEADER);
  116. //psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE;
  117. psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  118. psh.hwndParent = hwndOwner;
  119. psh.hInstance = glob_hinst;
  120. psh.pszIcon = "";
  121. psh.pszCaption = (LPSTR) title; //"Port Properties";
  122. //psh.nPages = NUM_PORTPROP_SHEETS;
  123. psh.nPages = num_active_portprop_sheets;
  124. psh.ppsp = (LPCPROPSHEETPAGE) &psp;
  125. //And finally display the dialog with the property sheets.
  126. stat = PropertySheet(&psh);
  127. return 0;
  128. }
  129. /*----------------------------------------------------------
  130. context_menu -
  131. |------------------------------------------------------------*/
  132. static void context_menu(void)
  133. {
  134. HMENU hpop_menu;
  135. POINT scr_pt;
  136. int stat;
  137. scr_pt.x = 200;
  138. scr_pt.y = 200;
  139. hpop_menu = CreatePopupMenu();
  140. if (hpop_menu == NULL)
  141. {
  142. mess(&wi->ip, "Error from CreatePopMenu");
  143. return;
  144. }
  145. //AppendMenu(hpop_menu, 0, 0x10, "Run Peer tracer");
  146. AppendMenu(hpop_menu, 0, 0x11, "Run Wcom Test Terminal");
  147. GetCursorPos(&scr_pt);
  148. stat = TrackPopupMenuEx(hpop_menu,
  149. TPM_NONOTIFY | TPM_RETURNCMD, /* flags */
  150. scr_pt.x, scr_pt.y, /* x,y */
  151. //0, /* 0 reserved */
  152. glob_hwnd,
  153. NULL);
  154. GetSystemDirectory(gtmpstr,144);
  155. strcat(gtmpstr, "\\");
  156. strcat(gtmpstr, OurAppDir);
  157. SetCurrentDirectory(gtmpstr);
  158. if (stat == 0x11)
  159. {
  160. strcat(gtmpstr, "\\wcom32.exe \\\\.\\");
  161. strcat(gtmpstr, wi->dev[our_device_index].ports[our_port_index].Name);
  162. }
  163. WinExec(gtmpstr, SW_RESTORE);
  164. DestroyMenu(hpop_menu);
  165. }
  166. /*----------------------------------------------------------
  167. PortPropSheet - Dlg window procedure for add on Advanced sheet.
  168. |-------------------------------------------------------------*/
  169. BOOL WINAPI PortPropSheet(
  170. IN HWND hDlg,
  171. IN UINT uMessage,
  172. IN WPARAM wParam,
  173. IN LPARAM lParam)
  174. {
  175. OUR_INFO * OurProps = (OUR_INFO *)GetWindowLong(hDlg, DWL_USER);
  176. WORD uCmd;
  177. switch(uMessage)
  178. {
  179. case WM_INITDIALOG :
  180. OurProps = (OUR_INFO *)((LPPROPSHEETPAGE)lParam)->lParam;
  181. SetWindowLong(hDlg, DWL_USER, (LONG)OurProps);
  182. // save in case of cancel
  183. //memcpy(&org_pc, &wi->dev[our_device_index].ports[our_port_index],
  184. // sizeof(org_pc));
  185. set_field(hDlg, IDC_PORT_LOCKBAUD );
  186. set_field(hDlg, IDC_PORT_WAIT_ON_CLOSE);
  187. set_field(hDlg, IDC_PORT_WONTX );
  188. set_field(hDlg, IDC_MAP_CDTODSR );
  189. set_field(hDlg, IDC_MAP_2TO1 );
  190. set_field(hDlg, IDC_RING_EMULATE );
  191. // Return TRUE to set focus to first control
  192. return TRUE; // No need for us to set the focus.
  193. case PSM_QUERYSIBLINGS :
  194. {
  195. switch (HIWORD(wParam))
  196. {
  197. case QUERYSIB_CLONE_PORT_PROPS :
  198. {
  199. // low word of wParam is which ports to clone to...
  200. // currently we only support "all", but this is the place to add
  201. // other specific handling.
  202. int devnum;
  203. int portnum;
  204. Port_Config *srcport, *destport;
  205. #ifdef DEBUG
  206. char debugstr[80];
  207. #endif
  208. // make sure we have current values before cloning
  209. get_field(hDlg, IDC_PORT_LOCKBAUD );
  210. get_field(hDlg, IDC_PORT_WAIT_ON_CLOSE);
  211. get_field(hDlg, IDC_PORT_WONTX );
  212. get_field(hDlg, IDC_MAP_CDTODSR );
  213. get_field(hDlg, IDC_MAP_2TO1 );
  214. get_field(hDlg, IDC_RING_EMULATE );
  215. srcport = &wi->dev[our_device_index].ports[our_port_index];
  216. switch (LOWORD(wParam))
  217. {
  218. case CLONEOPT_ALL:
  219. {
  220. // apply the options on this page to all other ports
  221. for (devnum = 0; devnum < wi->NumDevices; devnum++)
  222. {
  223. for (portnum = 0; portnum < wi->dev[devnum].NumPorts; portnum++)
  224. {
  225. destport = &wi->dev[devnum].ports[portnum];
  226. // is it target different than the source?
  227. if (destport != srcport)
  228. {
  229. // yep, so apply the source's options to the target
  230. DbgPrintf(D_Level,
  231. (TEXT("cloning general options from port %s to port %s\n"),
  232. srcport->Name, destport->Name));
  233. destport->LockBaud = srcport->LockBaud;
  234. destport->TxCloseTime = srcport->TxCloseTime;
  235. destport->WaitOnTx = srcport->WaitOnTx;
  236. destport->MapCdToDsr = srcport->MapCdToDsr;
  237. destport->Map2StopsTo1 = srcport->Map2StopsTo1;
  238. destport->RingEmulate = srcport->RingEmulate;
  239. }
  240. }
  241. }
  242. break;
  243. }
  244. case CLONEOPT_DEVICE:
  245. {
  246. // apply the options on this page to all other ports on same device
  247. /* not yet implemented */
  248. break;
  249. }
  250. case CLONEOPT_SELECT:
  251. {
  252. // apply the options on this page to the list of selected ports
  253. // lParam is a pointer to a list of ports.
  254. /* not yet implemented */
  255. break;
  256. }
  257. default:
  258. // unknown clone option -- skip it
  259. break;
  260. }
  261. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  262. return TRUE;
  263. break;
  264. }
  265. default :
  266. return FALSE;
  267. }
  268. }
  269. case WM_COMMAND :
  270. #ifdef WIN32
  271. uCmd = HIWORD(wParam);
  272. #else
  273. uCmd = HIWORD(lParam);
  274. #endif
  275. switch (LOWORD(wParam))
  276. {
  277. case IDB_DEF: // actually the defaults button
  278. {
  279. Port_Config *pc;
  280. pc= &wi->dev[our_device_index].ports[our_port_index];
  281. //pc->options = 0;
  282. pc->RingEmulate = 0;
  283. pc->MapCdToDsr = 0;
  284. pc->WaitOnTx = 0;
  285. pc->Map2StopsTo1 = 0;
  286. pc->LockBaud = 0;
  287. pc->TxCloseTime = 0;
  288. // should we be doing this? they are on another page(kpb)
  289. pc->RS485Override = 0;
  290. pc->RS485Low = 0;
  291. set_field(hDlg, IDC_PORT_LOCKBAUD );
  292. set_field(hDlg, IDC_PORT_WAIT_ON_CLOSE);
  293. set_field(hDlg, IDC_PORT_WONTX );
  294. set_field(hDlg, IDC_MAP_CDTODSR );
  295. set_field(hDlg, IDC_MAP_2TO1 );
  296. set_field(hDlg, IDC_RING_EMULATE );
  297. }
  298. break;
  299. }
  300. return FALSE;
  301. case WM_PAINT:
  302. #if 0
  303. PaintIcon(hDlg);
  304. #endif
  305. return FALSE;
  306. case WM_HELP: // question mark thing
  307. our_context_help(lParam);
  308. return FALSE;
  309. case WM_CONTEXTMENU: // right-click
  310. context_menu();
  311. break;
  312. case WM_NOTIFY :
  313. switch (((NMHDR *)lParam)->code)
  314. {
  315. case PSN_HELP :
  316. our_help(&wi->ip, IDD_PORT_OPTIONS);
  317. break;
  318. case PSN_APPLY :
  319. get_field(hDlg, IDC_PORT_LOCKBAUD );
  320. get_field(hDlg, IDC_PORT_WAIT_ON_CLOSE);
  321. get_field(hDlg, IDC_PORT_WONTX );
  322. get_field(hDlg, IDC_MAP_CDTODSR );
  323. get_field(hDlg, IDC_MAP_2TO1 );
  324. get_field(hDlg, IDC_RING_EMULATE );
  325. if (IsDlgButtonChecked(hDlg, IDC_CLONE))
  326. {
  327. PropSheet_QuerySiblings(GetParent(hDlg),
  328. (WPARAM)((QUERYSIB_CLONE_PORT_PROPS << 16) + CLONEOPT_ALL),
  329. 0);
  330. }
  331. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  332. return TRUE;
  333. default :
  334. return FALSE;
  335. }
  336. break;
  337. default :
  338. // return FALSE;
  339. break;
  340. }
  341. return FALSE;
  342. }
  343. /*----------------------------------------------------------
  344. PortProp485Sheet -
  345. |-------------------------------------------------------------*/
  346. BOOL WINAPI PortProp485Sheet(
  347. IN HWND hDlg,
  348. IN UINT uMessage,
  349. IN WPARAM wParam,
  350. IN LPARAM lParam)
  351. {
  352. OUR_INFO * OurProps = (OUR_INFO *)GetWindowLong(hDlg, DWL_USER);
  353. WORD uCmd;
  354. switch(uMessage)
  355. {
  356. case WM_INITDIALOG :
  357. OurProps = (OUR_INFO *)((LPPROPSHEETPAGE)lParam)->lParam;
  358. SetWindowLong(hDlg, DWL_USER, (LONG)OurProps);
  359. // save in case of cancel
  360. //memcpy(&org_pc, &wi->dev[our_device_index].ports[our_port_index],
  361. // sizeof(org_pc));
  362. set_field(hDlg, IDC_PORT_RS485_TLOW );
  363. set_field(hDlg, IDC_PORT_RS485_LOCK );
  364. // Return TRUE to set focus to first control
  365. return TRUE; // No need for us to set the focus.
  366. case PSM_QUERYSIBLINGS :
  367. {
  368. switch (HIWORD(wParam))
  369. {
  370. case QUERYSIB_CLONE_PORT_PROPS :
  371. {
  372. // low word of wParam is which ports to clone to...
  373. // currently we only support "all", but this is the place to add
  374. // other specific handling.
  375. int devnum;
  376. int portnum;
  377. Port_Config *srcport, *destport;
  378. #ifdef DEBUG
  379. char debugstr[80];
  380. #endif
  381. // make sure we have current values before cloning
  382. get_field(hDlg, IDC_PORT_RS485_TLOW );
  383. get_field(hDlg, IDC_PORT_RS485_LOCK );
  384. srcport = &wi->dev[our_device_index].ports[our_port_index];
  385. switch (LOWORD(wParam))
  386. {
  387. case CLONEOPT_ALL:
  388. {
  389. int maxport;
  390. // apply the options on this page to all other ports
  391. for (devnum = 0; devnum < wi->NumDevices; devnum++)
  392. {
  393. if ((strstr(wi->dev[devnum].ModelName, "485")) ||
  394. (wi->GlobalRS485 == 1))
  395. {
  396. // we're only going to apply RS485 settings to other
  397. // 485 boards (unless the global RS485 flag is on)
  398. if (wi->GlobalRS485 == 1)
  399. maxport = wi->dev[devnum].NumPorts;
  400. else
  401. maxport = 2;
  402. for (portnum = 0; portnum < maxport; portnum++)
  403. {
  404. destport = &wi->dev[devnum].ports[portnum];
  405. // is it target different than the source?
  406. if (destport != srcport)
  407. {
  408. // yep, so apply the source's options to the target
  409. DbgPrintf(D_Level,
  410. (TEXT("cloning rs-485 options from port %s to port %s\n"),
  411. srcport->Name, destport->Name));
  412. destport->RS485Low = srcport->RS485Low;
  413. destport->RS485Override = srcport->RS485Override;
  414. }
  415. }
  416. }
  417. }
  418. break;
  419. }
  420. case CLONEOPT_DEVICE:
  421. {
  422. // apply the options on this page to all other ports on same device
  423. /* not yet implemented */
  424. break;
  425. }
  426. case CLONEOPT_SELECT:
  427. {
  428. // apply the options on this page to the list of selected ports
  429. // lParam is a pointer to a list of ports.
  430. /* not yet implemented */
  431. break;
  432. }
  433. default:
  434. // unknown clone option -- skip it
  435. break;
  436. }
  437. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  438. return TRUE;
  439. break;
  440. }
  441. default :
  442. return FALSE;
  443. }
  444. }
  445. case WM_COMMAND :
  446. #ifdef WIN32
  447. uCmd = HIWORD(wParam);
  448. #else
  449. uCmd = HIWORD(lParam);
  450. #endif
  451. switch (LOWORD(wParam))
  452. {
  453. case IDB_DEF: // actually the defaults button
  454. {
  455. Port_Config *pc;
  456. pc= &wi->dev[our_device_index].ports[our_port_index];
  457. // pc->options = 0;
  458. pc->RS485Override = 0;
  459. pc->RS485Low = 0;
  460. set_field(hDlg, IDC_PORT_RS485_TLOW );
  461. set_field(hDlg, IDC_PORT_RS485_LOCK );
  462. }
  463. break;
  464. }
  465. return FALSE;
  466. case WM_PAINT:
  467. #if 0
  468. PaintIcon(hDlg);
  469. #endif
  470. return FALSE;
  471. case WM_HELP: // question mark thing
  472. our_context_help(lParam);
  473. return FALSE;
  474. case WM_NOTIFY :
  475. switch (((NMHDR *)lParam)->code)
  476. {
  477. case PSN_HELP :
  478. our_help(&wi->ip, IDD_PORT_485_OPTIONS);
  479. break;
  480. case PSN_APPLY :
  481. get_field(hDlg, IDC_PORT_RS485_TLOW );
  482. get_field(hDlg, IDC_PORT_RS485_LOCK );
  483. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  484. return TRUE;
  485. default :
  486. return FALSE;
  487. }
  488. default :
  489. return FALSE;
  490. }
  491. }
  492. /*----------------------------------------------------------
  493. request_modem_reset -
  494. |-------------------------------------------------------------*/
  495. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  496. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  497. )
  498. #define METHOD_BUFFERED 0
  499. #define FILE_ANY_ACCESS 0
  500. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  501. #define IOCTL_RCKT_SET_MODEM_RESET \
  502. CTL_CODE(FILE_DEVICE_SERIAL_PORT, 0x80d,METHOD_BUFFERED,FILE_ANY_ACCESS)
  503. #define IOCTL_RCKT_CLEAR_MODEM_RESET \
  504. CTL_CODE(FILE_DEVICE_SERIAL_PORT, 0x80e,METHOD_BUFFERED,FILE_ANY_ACCESS)
  505. #define IOCTL_RCKT_SEND_MODEM_ROW \
  506. CTL_CODE(FILE_DEVICE_SERIAL_PORT, 0x80f,METHOD_BUFFERED,FILE_ANY_ACCESS)
  507. void request_modem_reset(int device_index, int port_index)
  508. {
  509. HANDLE hDriver; // file handle to driver device
  510. Port_Config *pc; // config information about the port to reset
  511. ULONG retBytes;
  512. // attempt to open communications with the driver
  513. hDriver = CreateFile(szDriverDevice, GENERIC_READ | GENERIC_WRITE,
  514. FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  515. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  516. if (hDriver != INVALID_HANDLE_VALUE)
  517. {
  518. // double-check that it is a modem device!
  519. if (wi->dev[device_index].ModemDevice)
  520. {
  521. pc = &wi->dev[device_index].ports[port_index];
  522. // send the ioctl to put the modem into the reset state
  523. DeviceIoControl(hDriver, IOCTL_RCKT_SET_MODEM_RESET,
  524. pc->Name, sizeof(pc->Name),
  525. pc->Name, sizeof(pc->Name),
  526. &retBytes, 0);
  527. // delay briefly before pulling modem out of reset state
  528. Sleep(45);
  529. // send the ioctl to pull the modem out of reset state
  530. DeviceIoControl(hDriver, IOCTL_RCKT_CLEAR_MODEM_RESET,
  531. pc->Name, sizeof(pc->Name),
  532. pc->Name, sizeof(pc->Name),
  533. &retBytes, 0);
  534. Sleep(65);
  535. // if country code is North America or invalid, we're done
  536. // if country code is default or invalid, we're done
  537. if (
  538. (wi->ModemCountry)
  539. &&
  540. ( (wi->dev[device_index].ModemDevice == TYPE_RM_VS2000)
  541. &&
  542. (wi->ModemCountry != RowInfo[0].RowCountryCode))
  543. ||
  544. ( (wi->dev[device_index].ModemDevice == TYPE_RM_i)
  545. &&
  546. (wi->ModemCountry != CTRRowInfo[0].RowCountryCode))
  547. ) {
  548. // wait for the modem to stablize before sending country code command
  549. // (about 4 seconds!)
  550. Sleep(4000);
  551. // send the ioctl to configure the country code
  552. DeviceIoControl(hDriver, IOCTL_RCKT_SEND_MODEM_ROW,
  553. pc->Name, sizeof(pc->Name),
  554. pc->Name, sizeof(pc->Name),
  555. &retBytes, 0);
  556. }
  557. }
  558. // close communications with the driver
  559. CloseHandle(hDriver);
  560. }
  561. }
  562. /*----------------------------------------------------------
  563. PortPropModemSheet -
  564. |-------------------------------------------------------------*/
  565. BOOL WINAPI PortPropModemSheet(
  566. IN HWND hDlg,
  567. IN UINT uMessage,
  568. IN WPARAM wParam,
  569. IN LPARAM lParam)
  570. {
  571. OUR_INFO * OurProps = (OUR_INFO *)GetWindowLong(hDlg, DWL_USER);
  572. WORD uCmd;
  573. switch(uMessage)
  574. {
  575. case WM_INITDIALOG :
  576. OurProps = (OUR_INFO *)((LPPROPSHEETPAGE)lParam)->lParam;
  577. SetWindowLong(hDlg, DWL_USER, (LONG)OurProps);
  578. // save in case of cancel
  579. //memcpy(&org_pc, &wi->dev[our_device_index].ports[our_port_index],
  580. // sizeof(org_pc));
  581. if (wi->dev[our_device_index].ModemDevice)
  582. {
  583. // parent device for this port provides modems, enable reset button
  584. EnableWindow(GetDlgItem(hDlg, IDB_RESET), 1);
  585. }
  586. else
  587. {
  588. // parent device for this port has no modems, disable the reset button
  589. EnableWindow(GetDlgItem(hDlg, IDB_RESET), 0);
  590. }
  591. // Return TRUE to set focus to first control
  592. return TRUE; // No need for us to set the focus.
  593. case WM_COMMAND :
  594. #ifdef WIN32
  595. uCmd = HIWORD(wParam);
  596. #else
  597. uCmd = HIWORD(lParam);
  598. #endif
  599. switch (LOWORD(wParam))
  600. {
  601. case IDB_RESET:
  602. request_modem_reset(our_device_index, our_port_index);
  603. break;
  604. }
  605. return FALSE;
  606. case WM_PAINT:
  607. #if 0
  608. PaintIcon(hDlg);
  609. #endif
  610. return FALSE;
  611. case WM_HELP: // question mark thing
  612. our_context_help(lParam);
  613. return FALSE;
  614. case WM_NOTIFY :
  615. switch (((NMHDR *)lParam)->code)
  616. {
  617. case PSN_HELP :
  618. our_help(&wi->ip, IDD_PORT_MODEM_OPTIONS);
  619. break;
  620. case PSN_APPLY :
  621. SetWindowLong(hDlg, DWL_MSGRESULT, PSNRET_NOERROR);
  622. return TRUE;
  623. default :
  624. return FALSE;
  625. }
  626. default :
  627. return FALSE;
  628. }
  629. }
  630. /*-------------------------------------------------------------------
  631. | get_field - Run when a selection is changed.
  632. |--------------------------------------------------------------------*/
  633. static void get_field(HWND hDlg, WORD id)
  634. {
  635. char tmpstr[60];
  636. int i;
  637. Port_Config *pc;
  638. // HWND hwnd;
  639. pc= &wi->dev[our_device_index].ports[our_port_index];
  640. switch (id)
  641. {
  642. case IDC_PORT_LOCKBAUD:
  643. GetDlgItemText(hDlg, id, tmpstr, 58);
  644. pc->LockBaud = getint(tmpstr, &i);
  645. break;
  646. case IDC_PORT_WAIT_ON_CLOSE:
  647. GetDlgItemText(hDlg, id, tmpstr, 58);
  648. pc->TxCloseTime = getint(tmpstr, &i);
  649. break;
  650. case IDC_PORT_WONTX:
  651. if (IsDlgButtonChecked(hDlg, IDC_PORT_WONTX))
  652. pc->WaitOnTx = 1;
  653. else pc->WaitOnTx = 0;
  654. break;
  655. case IDC_PORT_RS485_TLOW:
  656. if (IsDlgButtonChecked(hDlg, IDC_PORT_RS485_TLOW))
  657. pc->RS485Low = 1;
  658. else pc->RS485Low = 0;
  659. break;
  660. case IDC_PORT_RS485_LOCK:
  661. if (IsDlgButtonChecked(hDlg, IDC_PORT_RS485_LOCK))
  662. pc->RS485Override = 1;
  663. else pc->RS485Override = 0;
  664. break;
  665. case IDC_MAP_CDTODSR:
  666. if (IsDlgButtonChecked(hDlg, IDC_MAP_CDTODSR))
  667. pc->MapCdToDsr = 1;
  668. else pc->MapCdToDsr = 0;
  669. break;
  670. case IDC_MAP_2TO1:
  671. if (IsDlgButtonChecked(hDlg, IDC_MAP_2TO1))
  672. pc->Map2StopsTo1 = 1;
  673. else pc->Map2StopsTo1 = 0;
  674. break;
  675. case IDC_RING_EMULATE :
  676. if (IsDlgButtonChecked(hDlg, IDC_RING_EMULATE))
  677. pc->RingEmulate = 1;
  678. else pc->RingEmulate = 0;
  679. break;
  680. }
  681. }
  682. /*----------------------------------------------------------
  683. set_field -
  684. |------------------------------------------------------------*/
  685. static void set_field(HWND hDlg, WORD id)
  686. {
  687. HWND hwnd;
  688. char tmpstr[60];
  689. Port_Config *pc;
  690. if (our_device_index >= wi->NumDevices)
  691. our_device_index = 0;
  692. pc = &wi->dev[our_device_index].ports[our_port_index];
  693. //------------------ fill in name selection
  694. //SetDlgItemText(hDlg, IDC_, pc->Name);
  695. switch(id)
  696. {
  697. case IDC_PORT_LOCKBAUD:
  698. //------------------ fill in baud override selection
  699. hwnd = GetDlgItem(hDlg, IDC_PORT_LOCKBAUD);
  700. SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  701. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) RcStr(MSGSTR+22));
  702. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "57600");
  703. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "115200");
  704. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "230400");
  705. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "460800");
  706. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) "921600");
  707. wsprintf(tmpstr, "%d", pc->LockBaud);
  708. if (pc->LockBaud == 0)
  709. strcpy(tmpstr,RcStr(MSGSTR+22));
  710. SetDlgItemText(hDlg, IDC_PORT_LOCKBAUD, tmpstr);
  711. break;
  712. case IDC_PORT_RS485_LOCK:
  713. //------------------ fill in "rs485 override?" option
  714. SendDlgItemMessage(hDlg, IDC_PORT_RS485_LOCK, BM_SETCHECK,
  715. pc->RS485Override, 0);
  716. break;
  717. case IDC_MAP_CDTODSR:
  718. //------------------ fill in "map CD to DSR?" option
  719. SendDlgItemMessage(hDlg, IDC_MAP_CDTODSR, BM_SETCHECK,
  720. pc->MapCdToDsr, 0);
  721. break;
  722. case IDC_MAP_2TO1:
  723. //------------------ fill in "map 2 to 1 stops?" option
  724. SendDlgItemMessage(hDlg, IDC_MAP_2TO1, BM_SETCHECK,
  725. pc->Map2StopsTo1, 0);
  726. break;
  727. case IDC_PORT_RS485_TLOW:
  728. //------------------ fill in "rs485 toggle low?" option
  729. SendDlgItemMessage(hDlg, IDC_PORT_RS485_TLOW, BM_SETCHECK,
  730. pc->RS485Low, 0);
  731. break;
  732. case IDC_PORT_WONTX:
  733. //------------------ fill in "wait on tx?" option
  734. SendDlgItemMessage(hDlg, IDC_PORT_WONTX, BM_SETCHECK,
  735. pc->WaitOnTx, 0);
  736. break;
  737. case IDC_PORT_WAIT_ON_CLOSE:
  738. //------------------ fill in wait on tx close option
  739. hwnd = GetDlgItem(hDlg, IDC_PORT_WAIT_ON_CLOSE);
  740. SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  741. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) RcStr(MSGSTR+23));
  742. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) RcStr(MSGSTR+24));
  743. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) RcStr(MSGSTR+25));
  744. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) RcStr(MSGSTR+26));
  745. SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(char far *) RcStr(MSGSTR+27));
  746. // no, need some better way to default this to 1 or 2 seconds
  747. //if (pc->TxCloseTime == 0)
  748. // strcpy(tmpstr, "1 sec"); // 0 means to the driver same as 6-seconds
  749. wsprintf(tmpstr, "%d %s", pc->TxCloseTime, RcStr(MSGSTR+28));
  750. SetDlgItemText(hDlg, IDC_PORT_WAIT_ON_CLOSE, tmpstr);
  751. break;
  752. case IDC_RING_EMULATE:
  753. SendDlgItemMessage(hDlg, IDC_RING_EMULATE, BM_SETCHECK,
  754. pc->RingEmulate, 0);
  755. break;
  756. }
  757. }
  758. #if 0
  759. /*---------------------------------------------------------------------------
  760. PaintIcon - Paints the Icon in the property sheet.
  761. |---------------------------------------------------------------------------*/
  762. static int PaintIcon(HWND hWnd)
  763. {
  764. // int status;
  765. HBITMAP hBitMap;
  766. HGDIOBJ hGdiObj;
  767. HDC hDC, hMemDC ;
  768. PAINTSTRUCT ps ;
  769. RECT spot, main; // left, top, right, bottom
  770. static int cnt = 0;
  771. GetWindowRect(GetDlgItem(hWnd, IDB_DEF), &spot);
  772. GetWindowRect(hWnd, &main);
  773. #ifdef COMMENT_OUT
  774. rect = &right;
  775. mess("hlp r:%d l:%d b:%d t:%d",
  776. rect->right, rect->left, rect->bottom, rect->top);
  777. #endif
  778. spot.left -= main.left;
  779. spot.top -= main.top;
  780. spot.left += 5;
  781. spot.top += 20; // spacing
  782. // load bitmap and display it
  783. hDC = BeginPaint( hWnd, &ps ) ;
  784. if (NULL != (hMemDC = CreateCompatibleDC( hDC )))
  785. {
  786. hBitMap = LoadBitmap(glob_hinst,
  787. MAKEINTRESOURCE(BMP_SMALL_LOGO));
  788. hGdiObj = SelectObject(hMemDC, hBitMap);
  789. BitBlt( hDC, spot.left, spot.top, 100, 100, hMemDC, 0, 0, SRCCOPY ) ;
  790. //StretchBlt( hDC, 5, 5, 600,100, hMemDC, 0, 0, 446, 85, SRCCOPY ) ;
  791. DeleteObject( SelectObject( hMemDC, hGdiObj ) ) ;
  792. DeleteDC( hMemDC ) ;
  793. }
  794. EndPaint( hWnd, &ps ) ;
  795. return 0;
  796. }
  797. #endif