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.

222 lines
6.4 KiB

  1. /****************************************************************************
  2. *
  3. * pioncnfg.c
  4. *
  5. * Copyright (c) 1991-1993 Microsoft Corporation. All Rights Reserved
  6. *
  7. ***************************************************************************/
  8. #include <windows.h>
  9. #include <windowsx.h>
  10. #include <mmsystem.h>
  11. #include <mmddk.h>
  12. #include "mcipionr.h"
  13. #include "pioncnfg.h"
  14. #define MAX_INI_LENGTH 128 /* maximum .ini file line length */
  15. #ifdef WIN32
  16. #define SZCODE TCHAR
  17. #else
  18. #define SZCODE char _based(_segname("_CODE"))
  19. #endif /* WIN32 */
  20. static UINT nPort; /* which com port we're using */
  21. static UINT nRate; /* which baud rate we're using */
  22. static SZCODE szIniFile[] = TEXT("system.ini"); /* configuration information file */
  23. static SZCODE szNull[] = TEXT("");
  24. static SZCODE szCommIniFormat[] = TEXT("com%1d,%d");
  25. /****************************************************************************
  26. * @doc INTERNAL
  27. *
  28. * @api BOOL | GetDriverName | Returns the file name of the driver
  29. * This is the name of the ini section where the driver stores
  30. * its parameters
  31. *
  32. * @parm LPDRVCONFIGINFO | lpdci | Config information from the DRV_CONFIGURE
  33. * message.
  34. *
  35. * @parm LPTSTR | lpstrDriver | Where to put the driver file name - must
  36. * have room for at least MAX_INI_LENGTH characters
  37. *
  38. * @rdesc TRUE if we found some name
  39. ***************************************************************************/
  40. static BOOL PASCAL NEAR GetDriverName(LPDRVCONFIGINFO lpdci, LPTSTR lpstrDriver)
  41. {
  42. if (GetPrivateProfileString( lpdci->lpszDCISectionName,
  43. lpdci->lpszDCIAliasName,
  44. TEXT(""),
  45. lpstrDriver,
  46. MAX_INI_LENGTH,
  47. szIniFile))
  48. {
  49. /* We have got the name of the driver
  50. * Just in case the user has added the command parameter to the
  51. * end of the name we had better make sure there is only one token
  52. * on the line.
  53. */
  54. int i;
  55. for ( i = 0; i < MAX_PATH && lpstrDriver[i] != TEXT('\0'); i++) {
  56. if (lpstrDriver[i] == TEXT(' ')) {
  57. lpstrDriver[i] = TEXT('\0');
  58. break;
  59. }
  60. }
  61. return TRUE;
  62. }
  63. return FALSE;
  64. }
  65. /****************************************************************************
  66. * @doc INTERNAL
  67. *
  68. * @api UINT | GetCmdParam | Returns the currently selected comport and
  69. * baud rate from the user profile
  70. *
  71. * @parm LPDRVCONFIGINFO | lpdci | Config information from the DRV_CONFIGURE
  72. * message.
  73. *
  74. * @rdesc Returns comport number.
  75. ***************************************************************************/
  76. static void PASCAL NEAR GetCmdParam(LPDRVCONFIGINFO lpdci, PUINT pPort,
  77. PUINT pRate)
  78. {
  79. TCHAR aszDriver[MAX_INI_LENGTH];
  80. TCHAR sz[MAX_INI_LENGTH];
  81. *pPort = 0; /* Default is com1 */
  82. *pRate = DEFAULT_BAUD_RATE;
  83. if (!GetDriverName(lpdci, aszDriver)) {
  84. return;
  85. }
  86. if (GetProfileString(
  87. aszDriver, lpdci->lpszDCIAliasName, szNull, sz,
  88. MAX_INI_LENGTH)) {
  89. pionGetComportAndRate(sz, pPort, pRate);
  90. }
  91. }
  92. /****************************************************************************
  93. * @doc INTERNAL
  94. *
  95. * @api void | PutCmdParam | Sets the current comport in system.ini.
  96. *
  97. * @parm LPDRVCONFIGINFO | lpdci | Config information from the DRV_CONFIGURE
  98. * message.
  99. *
  100. * @parm UINT | nPort | Comport to set.
  101. *
  102. * @rdesc Returns comport number.
  103. ***************************************************************************/
  104. static void PASCAL NEAR PutCmdParam(LPDRVCONFIGINFO lpdci, UINT nPort, UINT nRate)
  105. {
  106. TCHAR aszDriver[MAX_INI_LENGTH];
  107. TCHAR sz[MAX_INI_LENGTH];
  108. if (!GetDriverName(lpdci, aszDriver)) {
  109. return;
  110. }
  111. wsprintf(sz, szCommIniFormat, nPort + 1, nRate);
  112. WriteProfileString(
  113. aszDriver,
  114. lpdci->lpszDCIAliasName,
  115. sz);
  116. }
  117. /****************************************************************************
  118. * @doc INTERNAL
  119. *
  120. * @func BOOL | ConfigDlgProc | Dialog proc for the configuration dialog box.
  121. *
  122. * @parm HWND | hDlg | Handle to the configuration dialog box.
  123. *
  124. * @parm UINT | msg | Message sent to the dialog box.
  125. *
  126. * @parm WPARAM | wParam | Message dependent parameter.
  127. *
  128. * @parm LPARAM | lParam | Message dependent parameter.
  129. *
  130. * @rdesc Returns DRV_OK if the user clicks on "OK" and DRV_CANCEL if the
  131. * user clicks on "Cancel".
  132. ***************************************************************************/
  133. BOOL FAR PASCAL _LOADDS ConfigDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  134. {
  135. static LPDRVCONFIGINFO lpdci;
  136. switch (msg) {
  137. case WM_INITDIALOG:
  138. lpdci = (LPDRVCONFIGINFO)lParam;
  139. GetCmdParam(lpdci, &nPort, &nRate);
  140. CheckRadioButton(hDlg, P_COM1, P_COM4, P_COM1 + nPort);
  141. CheckRadioButton(hDlg, R_4800, R_9600,
  142. nRate == 4800 ? R_4800 : R_9600);
  143. break;
  144. case WM_COMMAND:
  145. switch ((WORD)wParam) {
  146. case IDOK:
  147. PutCmdParam(lpdci, nPort, nRate);
  148. EndDialog(hDlg, DRVCNF_OK);
  149. break;
  150. case IDCANCEL:
  151. EndDialog(hDlg, DRVCNF_CANCEL);
  152. break;
  153. case P_COM1:
  154. case P_COM2:
  155. case P_COM3:
  156. case P_COM4:
  157. nPort = wParam - P_COM1;
  158. break;
  159. case R_4800:
  160. nRate = 4800;
  161. break;
  162. case R_9600:
  163. nRate = 9600;
  164. break;
  165. default:
  166. break;
  167. }
  168. break;
  169. default:
  170. return FALSE;
  171. break;
  172. }
  173. return TRUE;
  174. }
  175. /****************************************************************************
  176. * @doc INTERNAL
  177. *
  178. * @func int | pionConfig | This puts up the configuration dialog box.
  179. *
  180. * @parm HWND | hwndParent | Parent window.
  181. *
  182. * @parm LPDRVCONFIGINFO | lpInfo | Config information from the DRV_CONFIGURE
  183. * message.
  184. *
  185. * @rdesc Returns whatever was returned from the dialog box procedure.
  186. ***************************************************************************/
  187. int PASCAL FAR pionConfig(HWND hwndParent, LPDRVCONFIGINFO lpInfo)
  188. {
  189. return DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_PIONCNFG), hwndParent, ConfigDlgProc,
  190. (DWORD)lpInfo);
  191. }