Source code of Windows XP (NT5)
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.

109 lines
3.1 KiB

  1. /*******************************************************************
  2. *
  3. * DESCRIPTION: Serial Keys Dialog handler
  4. *
  5. * HISTORY:
  6. *
  7. *******************************************************************/
  8. #include "Access.h"
  9. #define NUMPORTS 8
  10. #define NUMRATES 6
  11. INT_PTR WINAPI SerialKeyDlg (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  12. int i;
  13. UINT uBaud;
  14. UINT uBaudRates[] = { 300, 1200, 2400, 4800, 9600, 19200 };
  15. TCHAR szBuf[256];
  16. BOOL fProcessed = TRUE;
  17. switch (uMsg) {
  18. case WM_INITDIALOG:
  19. LoadString(g_hinst, IDS_COMPORT, szBuf, ARRAY_SIZE(szBuf));
  20. for (i=1; i <= 4; i++) {
  21. TCHAR szBuf2[256];
  22. // Make a correct port name and add it to the list box.
  23. wsprintf(szBuf2, __TEXT("%s%d"), szBuf, i);
  24. ComboBox_AddString(GetDlgItem(hwnd, IDC_SK_PORT), szBuf2);
  25. }
  26. // Select the current com port.
  27. if (g_serk.lpszActivePort[0] != '\0') {
  28. int cport;
  29. // For now we assume that the format of the string is
  30. // com[digit]. So comport[3] = the com port number
  31. // Set all invalid ports to 'COM1'
  32. cport = g_serk.lpszActivePort[3] - '1';
  33. if (cport < 0) cport = 0;
  34. if (cport > 4) cport = 0;
  35. // Set the active port.
  36. ComboBox_SetCurSel(GetDlgItem(hwnd, IDC_SK_PORT), cport);
  37. } else {
  38. // Else default to COM1.
  39. ComboBox_SetCurSel(GetDlgItem(hwnd, IDC_SK_PORT), 0);
  40. lstrcpy(g_serk.lpszActivePort, __TEXT("COM1"));
  41. }
  42. // Fill in the BAUD RATE options
  43. uBaud = 1; // Default baud rate.
  44. for (i = 0; i < NUMRATES; i++) {
  45. TCHAR szBuf[256];
  46. wsprintf(szBuf, __TEXT("%d"), uBaudRates[i]);
  47. ComboBox_AddString(GetDlgItem(hwnd, IDC_SK_BAUD), szBuf);
  48. if (g_serk.iBaudRate == uBaudRates[i]) uBaud = i;
  49. }
  50. ComboBox_SetCurSel(GetDlgItem(hwnd, IDC_SK_BAUD), uBaud);
  51. break;
  52. case WM_HELP: // F1
  53. WinHelp(((LPHELPINFO) lParam)->hItemHandle, __TEXT("access.hlp"), HELP_WM_HELP, (DWORD_PTR) (LPSTR) g_aIds);
  54. break;
  55. case WM_CONTEXTMENU: // right mouse click
  56. WinHelp((HWND) wParam, __TEXT("access.hlp"), HELP_CONTEXTMENU, (DWORD_PTR) (LPSTR) g_aIds);
  57. break;
  58. case WM_COMMAND:
  59. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  60. // Watch for combobox changes.
  61. case IDC_SK_BAUD:
  62. switch (HIWORD(wParam)) {
  63. case CBN_CLOSEUP:
  64. case CBN_SELCHANGE:
  65. i = ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_SK_BAUD));
  66. g_serk.iBaudRate = uBaudRates[i];
  67. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM) hwnd, 0);
  68. break;
  69. }
  70. break;
  71. case IDC_SK_PORT:
  72. switch (HIWORD(wParam)) {
  73. case CBN_SELCHANGE:
  74. i = 1 + ComboBox_GetCurSel(GetDlgItem(hwnd, IDC_SK_PORT));
  75. wsprintf(g_serk.lpszActivePort, __TEXT("COM%d"), i);
  76. EnableWindow(GetDlgItem(hwnd, IDC_SK_BAUD), TRUE);
  77. break;
  78. }
  79. break;
  80. case IDOK: case IDCANCEL:
  81. EndDialog(hwnd, GET_WM_COMMAND_ID(wParam, lParam));
  82. break;
  83. }
  84. break;
  85. default:
  86. fProcessed = FALSE; break;
  87. }
  88. return(fProcessed);
  89. }
  90. ///////////////////////////////// End of File /////////////////////////////////