2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS SerialUI DLL
5 * PUROPSE: A dialog box to configure 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 ************************************/
22 const DWORD Bauds
[] = {
41 const BYTE ByteSizes
[] = {
50 const PARITY_INFO Parities
[] = {
51 { EVENPARITY
, IDS_EVENPARITY
},
52 { MARKPARITY
, IDS_MARKPARITY
},
53 { NOPARITY
, IDS_NOPARITY
},
54 { ODDPARITY
, IDS_ODDPARITY
},
55 { SPACEPARITY
, IDS_SPACEPARITY
},
59 const STOPBIT_INFO StopBits
[] = {
60 { ONESTOPBIT
, IDS_ONESTOPBIT
},
61 { ONE5STOPBITS
, IDS_ONE5STOPBITS
},
62 { TWOSTOPBITS
, IDS_TWOSTOPBITS
},
67 /************************************
71 ************************************/
75 DllMain(HINSTANCE hInstance
,
79 if(dwReason
==DLL_PROCESS_ATTACH
)
81 hDllInstance
= hInstance
;
83 else if(dwReason
==DLL_THREAD_ATTACH
)
85 DisableThreadLibraryCalls(hInstance
);
92 /************************************
96 ************************************/
101 DWORD WINAPI
drvCommConfigDialogW(LPCWSTR lpszDevice
,
103 LPCOMMCONFIG lpCommConfig
)
105 DIALOG_INFO DialogInfo
;
107 if(!lpszDevice
|| !lpCommConfig
)
109 return ERROR_INVALID_PARAMETER
;
112 DialogInfo
.lpszDevice
= lpszDevice
;
113 DialogInfo
.lpCC
= lpCommConfig
;
115 return DialogBoxParamW(hDllInstance
, MAKEINTRESOURCEW(IDD_COMMDLG
),
116 hWnd
, (DLGPROC
)CommDlgProc
, (LPARAM
)&DialogInfo
);
122 DWORD WINAPI
drvCommConfigDialogA(LPCSTR lpszDevice
,
124 LPCOMMCONFIG lpCommConfig
)
130 len
= MultiByteToWideChar(CP_ACP
, 0, lpszDevice
, -1, NULL
, 0);
131 if((wstr
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
133 MultiByteToWideChar(CP_ACP
, 0, lpszDevice
, -1, wstr
, len
);
134 result
= drvCommConfigDialogW(wstr
, hWnd
, lpCommConfig
);
135 HeapFree(GetProcessHeap(), 0, wstr
);
139 return ERROR_NOT_ENOUGH_MEMORY
;
145 DWORD WINAPI
drvSetDefaultCommConfigW(LPCWSTR lpszDevice
,
146 LPCOMMCONFIG lpCommConfig
,
155 DWORD WINAPI
drvSetDefaultCommConfigA(LPCSTR lpszDevice
,
156 LPCOMMCONFIG lpCommConfig
,
165 DWORD WINAPI
drvGetDefaultCommConfigW(LPCWSTR lpszDevice
,
166 LPCOMMCONFIG lpCommConfig
,
175 DWORD WINAPI
drvGetDefaultCommConfigA(LPCSTR lpszDevice
,
176 LPCOMMCONFIG lpCommConfig
,
183 /************************************
187 ************************************/
189 LRESULT
CommDlgProc(HWND hDlg
,
194 LPDIALOG_INFO lpDlgInfo
= NULL
;
203 RECT rc
, rcDlg
, rcOwner
;
207 lpDlgInfo
= (LPDIALOG_INFO
)lParam
;
208 SetWindowLongPtrW(hDlg
, DWL_USER
, (LONG_PTR
)lpDlgInfo
);
211 if(LoadStringW(hDllInstance
, IDS_TITLE
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
213 SetWindowTextW(hDlg
, wstr
);
216 /* FIXME - this won't work correctly systems with multiple monitors! */
217 if(!(hOwner
= GetParent(hDlg
)))
218 hOwner
= GetDesktopWindow();
220 /* Position dialog in the center of owner window */
221 GetWindowRect(hOwner
, &rcOwner
);
222 GetWindowRect(hDlg
, &rcDlg
);
223 CopyRect(&rc
, &rcOwner
);
224 OffsetRect(&rcDlg
, -rcDlg
.left
, -rcDlg
.top
);
225 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
226 OffsetRect(&rc
, -rcDlg
.right
, -rcDlg
.bottom
);
227 SetWindowPos(hDlg
, HWND_TOP
,
228 rcOwner
.left
+ (rc
.right
/ 2),
229 rcOwner
.top
+ (rc
.bottom
/ 2),
232 /* Initialize baud rate combo */
233 if(!(hBox
= GetDlgItem(hDlg
, IDC_BAUDRATE
)))
234 EndDialog(hDlg
, ERROR_CANCELLED
);
236 for(i
= 0; Bauds
[i
]; i
++)
238 wsprintf(wstr
, L
"%d", Bauds
[i
]);
239 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
240 if(Bauds
[i
] == lpDlgInfo
->lpCC
->dcb
.BaudRate
)
241 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
244 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
245 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_BAUD_INDEX
, 0);
247 /* Initialize byte size combo */
248 if(!(hBox
= GetDlgItem(hDlg
, IDC_BYTESIZE
)))
249 EndDialog(hDlg
, ERROR_CANCELLED
);
251 for(i
= 0; ByteSizes
[i
]; i
++)
253 wsprintf(wstr
, L
"%d", Bauds
[i
]);
254 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
255 if(ByteSizes
[i
] == lpDlgInfo
->lpCC
->dcb
.ByteSize
)
256 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
259 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
260 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_BYTESIZE_INDEX
, 0);
262 /* Initialize parity combo */
263 if(!(hBox
= GetDlgItem(hDlg
, IDC_PARITY
)))
264 EndDialog(hDlg
, ERROR_CANCELLED
);
266 for(i
= 0; Parities
[i
].StrId
; i
++)
268 if(LoadStringW(hDllInstance
, Parities
[i
].StrId
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
270 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
271 if(Parities
[i
].Parity
== lpDlgInfo
->lpCC
->dcb
.Parity
)
272 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
276 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
277 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_PARITY_INDEX
, 0);
279 /* Initialize stop bits combo */
280 if(!(hBox
= GetDlgItem(hDlg
, IDC_STOPBITS
)))
281 EndDialog(hDlg
, ERROR_CANCELLED
);
283 for(i
= 0; StopBits
[i
].StrId
; i
++)
285 if(LoadStringW(hDllInstance
, StopBits
[i
].StrId
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
287 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
288 if(StopBits
[i
].StopBit
== lpDlgInfo
->lpCC
->dcb
.StopBits
)
289 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
293 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
294 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_STOPBITS_INDEX
, 0);
296 /* Initialize flow control combo */
297 if(!(hBox
= GetDlgItem(hDlg
, IDC_FLOW
)))
298 EndDialog(hDlg
, ERROR_CANCELLED
);
300 if(LoadStringW(hDllInstance
, IDS_FC_NO
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
302 SendMessageW(hBox
, CB_INSERTSTRING
, 0, (LPARAM
)wstr
);
303 SendMessageW(hBox
, CB_SETCURSEL
, 0, 0);
304 lpDlgInfo
->InitialFlowIndex
= 0;
308 if(LoadStringW(hDllInstance
, IDS_FC_CTSRTS
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
310 SendMessageW(hBox
, CB_INSERTSTRING
, 1, (LPARAM
)wstr
);
311 if(lpDlgInfo
->lpCC
->dcb
.fRtsControl
== RTS_CONTROL_HANDSHAKE
312 || lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
== TRUE
)
314 SendMessageW(hBox
, CB_SETCURSEL
, 1, 0);
315 lpDlgInfo
->InitialFlowIndex
= 1;
319 if(LoadStringW(hDllInstance
, IDS_FC_XONXOFF
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
321 SendMessageW(hBox
, CB_INSERTSTRING
, 2, (LPARAM
)wstr
);
322 if(lpDlgInfo
->lpCC
->dcb
.fOutX
|| lpDlgInfo
->lpCC
->dcb
.fInX
)
324 SendMessageW(hBox
, CB_SETCURSEL
, 2, 0);
325 lpDlgInfo
->InitialFlowIndex
= 2;
330 SetFocus(GetDlgItem(hDlg
, IDC_OKBTN
));
333 } /* WM_INITDIALOG */
340 EndDialog(hDlg
, ERROR_CANCELLED
);
344 EndDialog(hDlg
, ERROR_SUCCESS
);
352 EndDialog(hDlg
, ERROR_CANCELLED
);
363 VOID
OkButton(HWND hDlg
)
365 LPDIALOG_INFO lpDlgInfo
;
368 lpDlgInfo
= (LPDIALOG_INFO
) GetWindowLongPtrW(hDlg
, DWL_USER
);
371 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_BAUDRATE
), CB_GETCURSEL
, 0, 0);
372 lpDlgInfo
->lpCC
->dcb
.BaudRate
= Bauds
[Index
];
375 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_BYTESIZE
), CB_GETCURSEL
, 0, 0);
376 lpDlgInfo
->lpCC
->dcb
.ByteSize
= ByteSizes
[Index
];
379 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_PARITY
), CB_GETCURSEL
, 0, 0);
380 lpDlgInfo
->lpCC
->dcb
.Parity
= Parities
[Index
].Parity
;
383 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_STOPBITS
), CB_GETCURSEL
, 0, 0);
384 lpDlgInfo
->lpCC
->dcb
.StopBits
= StopBits
[Index
].StopBit
;
387 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_FLOW
), CB_GETCURSEL
, 0, 0);
388 if(lpDlgInfo
->InitialFlowIndex
!= Index
)
393 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
394 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_DISABLE
;
395 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= FALSE
;
396 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
397 lpDlgInfo
->lpCC
->dcb
.fOutX
= FALSE
;
398 lpDlgInfo
->lpCC
->dcb
.fInX
= FALSE
;
400 case 1: /* CTS/RTS */
401 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
402 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_HANDSHAKE
;
403 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= TRUE
;
404 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
405 lpDlgInfo
->lpCC
->dcb
.fOutX
= FALSE
;
406 lpDlgInfo
->lpCC
->dcb
.fInX
= FALSE
;
408 case 2: /* XON/XOFF */
409 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
410 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_DISABLE
;
411 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= FALSE
;
412 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
413 lpDlgInfo
->lpCC
->dcb
.fOutX
= TRUE
;
414 lpDlgInfo
->lpCC
->dcb
.fInX
= TRUE
;