2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS SerialUI DLL
5 * PUROPSE: A dialog box to cunfigure COM port.
6 * Functions to set(and get too) default configuration.
7 * PROGRAMMERS: Saveliy Tretiakov (saveliyt@mail.ru)
9 * ST (05/04/2005) Created. Implemented drvCommConfigDialog.
14 static HINSTANCE hDllInstance
;
16 /************************************
20 ************************************/
35 { CBR_14400
, "14400" },
36 { CBR_19200
, "19200" },
37 { CBR_38400
, "38400" },
38 { CBR_56000
, "56000" },
39 { CBR_57600
, "57600" },
40 { CBR_115200
, "115200" },
41 { CBR_128000
, "128000" },
42 { CBR_256000
, "256000" },
65 { EVENPARITY
, IDS_EVENPARITY
},
66 { MARKPARITY
, IDS_MARKPARITY
},
67 { NOPARITY
, IDS_NOPARITY
},
68 { ODDPARITY
, IDS_ODDPARITY
},
69 { SPACEPARITY
, IDS_SPACEPARITY
},
79 { ONESTOPBIT
, IDS_ONESTOPBIT
},
80 { ONE5STOPBITS
, IDS_ONE5STOPBITS
},
81 { TWOSTOPBITS
, IDS_TWOSTOPBITS
},
86 /************************************
90 ************************************/
94 DllMain(HINSTANCE hInstance
,
98 if(dwReason
==DLL_PROCESS_ATTACH
)
100 hDllInstance
= hInstance
;
102 else if(dwReason
==DLL_THREAD_ATTACH
)
104 DisableThreadLibraryCalls(hInstance
);
111 /************************************
115 ************************************/
120 BOOL WINAPI
drvCommConfigDialogW(LPCWSTR lpszDevice
,
122 LPCOMMCONFIG lpCommConfig
)
124 DIALOG_INFO DialogInfo
;
126 if(!lpszDevice
|| !lpCommConfig
)
131 DialogInfo
.lpszDevice
= lpszDevice
;
132 DialogInfo
.lpCC
= lpCommConfig
;
134 return DialogBoxParamW(hDllInstance
, MAKEINTRESOURCEW(IDD_COMMDLG
),
135 hWnd
, (DLGPROC
)CommDlgProc
, (LPARAM
)&DialogInfo
);
141 BOOL WINAPI
drvCommConfigDialogA(LPCSTR lpszDevice
,
143 LPCOMMCONFIG lpCommConfig
)
149 len
= MultiByteToWideChar(CP_ACP
, 0, lpszDevice
, -1, NULL
, 0);
150 if((wstr
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
152 MultiByteToWideChar(CP_ACP
, 0, lpszDevice
, -1, wstr
, len
);
153 result
= drvCommConfigDialogW(wstr
, hWnd
, lpCommConfig
);
154 HeapFree(GetProcessHeap(), 0, wstr
);
164 BOOL WINAPI
drvSetDefaultCommConfigW(LPCWSTR lpszDevice
,
165 LPCOMMCONFIG lpCommConfig
,
174 BOOL WINAPI
drvSetDefaultCommConfigA(LPCSTR lpszDevice
,
175 LPCOMMCONFIG lpCommConfig
,
184 BOOL WINAPI
drvGetDefaultCommConfigW(LPCWSTR lpszDevice
,
185 LPCOMMCONFIG lpCommConfig
,
194 BOOL WINAPI
drvGetDefaultCommConfigA(LPCSTR lpszDevice
,
195 LPCOMMCONFIG lpCommConfig
,
202 /************************************
206 ************************************/
208 LRESULT
CommDlgProc(HWND hDlg
,
213 LPDIALOG_INFO lpDlgInfo
= NULL
;
221 WCHAR wstr
[255], *format
;
223 RECT rc
, rcDlg
, rcOwner
;
227 lpDlgInfo
= (LPDIALOG_INFO
)lParam
;
228 SetWindowLong(hDlg
, DWL_USER
, (LONG
)lpDlgInfo
);
231 LoadStringA(hDllInstance
, IDS_TITLE
, str
, 254);
232 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
233 if((format
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
235 MultiByteToWideChar(CP_ACP
, 0, str
, -1, format
, len
);
236 wnsprintfW(wstr
, 254, format
, lpDlgInfo
->lpszDevice
);
237 HeapFree(GetProcessHeap(), 0, format
);
238 SetWindowTextW(hDlg
, wstr
);
241 if(!(hOwner
= GetParent(hDlg
)))
242 hOwner
= GetDesktopWindow();
244 /* Position dialog in the center of owner window */
245 GetWindowRect(hOwner
, &rcOwner
);
246 GetWindowRect(hDlg
, &rcDlg
);
247 CopyRect(&rc
, &rcOwner
);
248 OffsetRect(&rcDlg
, -rcDlg
.left
, -rcDlg
.top
);
249 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
250 OffsetRect(&rc
, -rcDlg
.right
, -rcDlg
.bottom
);
251 SetWindowPos(hDlg
, HWND_TOP
,
252 rcOwner
.left
+ (rc
.right
/ 2),
253 rcOwner
.top
+ (rc
.bottom
/ 2),
256 /* Initialize baud rate combo */
257 if(!(hBox
= GetDlgItem(hDlg
, IDC_BAUDRATE
)))
260 for(i
= 0; Bauds
[i
].Str
; i
++)
262 SendMessageA(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)Bauds
[i
].Str
);
263 if(Bauds
[i
].Baud
== lpDlgInfo
->lpCC
->dcb
.BaudRate
)
264 SendMessageA(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
267 if(SendMessage(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
268 SendMessageA(hBox
, CB_SETCURSEL
, DEFAULT_BAUD_INDEX
, 0);
270 /* Initialize byte size combo */
271 if(!(hBox
= GetDlgItem(hDlg
, IDC_BYTESIZE
)))
274 for(i
= 0; ByteSizes
[i
].Str
; i
++)
276 SendMessageA(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)ByteSizes
[i
].Str
);
277 if(ByteSizes
[i
].ByteSize
== lpDlgInfo
->lpCC
->dcb
.ByteSize
)
278 SendMessageA(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
281 if(SendMessage(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
282 SendMessageA(hBox
, CB_SETCURSEL
, DEFAULT_BYTESIZE_INDEX
, 0);
284 /* Initialize parity combo */
285 if(!(hBox
= GetDlgItem(hDlg
, IDC_PARITY
)))
288 for(i
= 0; Paritys
[i
].StrId
; i
++)
290 if(LoadStringA(hDllInstance
, Paritys
[i
].StrId
, str
, 254))
292 SendMessageA(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)str
);
293 if(Paritys
[i
].Parity
== lpDlgInfo
->lpCC
->dcb
.Parity
)
294 SendMessageA(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
298 if(SendMessage(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
299 SendMessageA(hBox
, CB_SETCURSEL
, DEFAULT_PARITY_INDEX
, 0);
301 /* Initialize stop bits combo */
302 if(!(hBox
= GetDlgItem(hDlg
, IDC_STOPBITS
)))
305 for(i
= 0; StopBits
[i
].StrId
; i
++)
307 if(LoadStringA(hDllInstance
,StopBits
[i
].StrId
, str
, 254))
309 SendMessageA(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)str
);
310 if(StopBits
[i
].StopBit
== lpDlgInfo
->lpCC
->dcb
.StopBits
)
311 SendMessageA(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
315 if(SendMessage(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
316 SendMessageA(hBox
, CB_SETCURSEL
, DEFAULT_STOPBITS_INDEX
, 0);
318 /* Initialize flow control combo */
319 if(!(hBox
= GetDlgItem(hDlg
, IDC_FLOW
)))
322 if(LoadStringA(hDllInstance
,IDS_FC_NO
, str
, 254))
324 SendMessageA(hBox
, CB_INSERTSTRING
, 0, (LPARAM
)str
);
325 SendMessageA(hBox
, CB_SETCURSEL
, 0, 0);
326 lpDlgInfo
->InitialFlowIndex
= 0;
330 if(LoadStringA(hDllInstance
,IDS_FC_CTSRTS
, str
, 254))
332 SendMessageA(hBox
, CB_INSERTSTRING
, 1, (LPARAM
)str
);
333 if(lpDlgInfo
->lpCC
->dcb
.fRtsControl
== RTS_CONTROL_HANDSHAKE
334 || lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
== TRUE
)
336 SendMessageA(hBox
, CB_SETCURSEL
, 1, 0);
337 lpDlgInfo
->InitialFlowIndex
= 1;
341 if(LoadStringA(hDllInstance
,IDS_FC_XONXOFF
, str
, 254))
343 SendMessageA(hBox
, CB_INSERTSTRING
, 2, (LPARAM
)str
);
344 if(lpDlgInfo
->lpCC
->dcb
.fOutX
|| lpDlgInfo
->lpCC
->dcb
.fInX
)
346 SendMessageA(hBox
, CB_SETCURSEL
, 2, 0);
347 lpDlgInfo
->InitialFlowIndex
= 2;
352 SetFocus(GetDlgItem(hDlg
, IDC_OKBTN
));
355 } /* WM_INITDIALOG */
362 EndDialog(hDlg
, FALSE
);
366 EndDialog(hDlg
, TRUE
);
374 EndDialog(hDlg
, FALSE
);
385 VOID
OkButton(HWND hDlg
)
387 LPDIALOG_INFO lpDlgInfo
;
390 lpDlgInfo
= (LPDIALOG_INFO
) GetWindowLong(hDlg
, DWL_USER
);
393 Index
= SendMessage(GetDlgItem(hDlg
, IDC_BAUDRATE
), CB_GETCURSEL
, 0, 0);
394 lpDlgInfo
->lpCC
->dcb
.BaudRate
= Bauds
[Index
].Baud
;
397 Index
= SendMessage(GetDlgItem(hDlg
, IDC_BYTESIZE
), CB_GETCURSEL
, 0, 0);
398 lpDlgInfo
->lpCC
->dcb
.ByteSize
= ByteSizes
[Index
].ByteSize
;
401 Index
= SendMessage(GetDlgItem(hDlg
, IDC_PARITY
), CB_GETCURSEL
, 0, 0);
402 lpDlgInfo
->lpCC
->dcb
.Parity
= Paritys
[Index
].Parity
;
405 Index
= SendMessage(GetDlgItem(hDlg
, IDC_STOPBITS
), CB_GETCURSEL
, 0, 0);
406 lpDlgInfo
->lpCC
->dcb
.StopBits
= StopBits
[Index
].StopBit
;
409 Index
= SendMessage(GetDlgItem(hDlg
, IDC_FLOW
), CB_GETCURSEL
, 0, 0);
410 if(lpDlgInfo
->InitialFlowIndex
!= Index
)
415 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
416 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_DISABLE
;
417 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= FALSE
;
418 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
419 lpDlgInfo
->lpCC
->dcb
.fOutX
= FALSE
;
420 lpDlgInfo
->lpCC
->dcb
.fInX
= FALSE
;
422 case 1: /* CTS/RTS */
423 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
424 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_HANDSHAKE
;
425 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= TRUE
;
426 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
427 lpDlgInfo
->lpCC
->dcb
.fOutX
= FALSE
;
428 lpDlgInfo
->lpCC
->dcb
.fInX
= FALSE
;
430 case 2: /* XON/XOFF */
431 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
432 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_DISABLE
;
433 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= FALSE
;
434 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
435 lpDlgInfo
->lpCC
->dcb
.fOutX
= TRUE
;
436 lpDlgInfo
->lpCC
->dcb
.fInX
= TRUE
;