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
, 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 ************************************/
191 CommDlgProc(HWND hDlg
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
193 LPDIALOG_INFO lpDlgInfo
= NULL
;
202 RECT rc
, rcDlg
, rcOwner
;
206 lpDlgInfo
= (LPDIALOG_INFO
)lParam
;
207 SetWindowLongPtrW(hDlg
, DWLP_USER
, (LONG_PTR
)lpDlgInfo
);
210 if(LoadStringW(hDllInstance
, IDS_TITLE
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
212 SetWindowTextW(hDlg
, wstr
);
215 /* FIXME - this won't work correctly systems with multiple monitors! */
216 if(!(hOwner
= GetParent(hDlg
)))
217 hOwner
= GetDesktopWindow();
219 /* Position dialog in the center of owner window */
220 GetWindowRect(hOwner
, &rcOwner
);
221 GetWindowRect(hDlg
, &rcDlg
);
222 CopyRect(&rc
, &rcOwner
);
223 OffsetRect(&rcDlg
, -rcDlg
.left
, -rcDlg
.top
);
224 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
225 OffsetRect(&rc
, -rcDlg
.right
, -rcDlg
.bottom
);
226 SetWindowPos(hDlg
, HWND_TOP
,
227 rcOwner
.left
+ (rc
.right
/ 2),
228 rcOwner
.top
+ (rc
.bottom
/ 2),
231 /* Initialize baud rate combo */
232 if(!(hBox
= GetDlgItem(hDlg
, IDC_BAUDRATE
)))
233 EndDialog(hDlg
, ERROR_CANCELLED
);
235 for(i
= 0; Bauds
[i
]; i
++)
237 wsprintf(wstr
, L
"%d", Bauds
[i
]);
238 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
239 if(Bauds
[i
] == lpDlgInfo
->lpCC
->dcb
.BaudRate
)
240 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
243 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
244 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_BAUD_INDEX
, 0);
246 /* Initialize byte size combo */
247 if(!(hBox
= GetDlgItem(hDlg
, IDC_BYTESIZE
)))
248 EndDialog(hDlg
, ERROR_CANCELLED
);
250 for(i
= 0; ByteSizes
[i
]; i
++)
252 wsprintf(wstr
, L
"%d", Bauds
[i
]);
253 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
254 if(ByteSizes
[i
] == lpDlgInfo
->lpCC
->dcb
.ByteSize
)
255 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
258 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
259 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_BYTESIZE_INDEX
, 0);
261 /* Initialize parity combo */
262 if(!(hBox
= GetDlgItem(hDlg
, IDC_PARITY
)))
263 EndDialog(hDlg
, ERROR_CANCELLED
);
265 for(i
= 0; Parities
[i
].StrId
; i
++)
267 if(LoadStringW(hDllInstance
, Parities
[i
].StrId
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
269 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
270 if(Parities
[i
].Parity
== lpDlgInfo
->lpCC
->dcb
.Parity
)
271 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
275 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
276 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_PARITY_INDEX
, 0);
278 /* Initialize stop bits combo */
279 if(!(hBox
= GetDlgItem(hDlg
, IDC_STOPBITS
)))
280 EndDialog(hDlg
, ERROR_CANCELLED
);
282 for(i
= 0; StopBits
[i
].StrId
; i
++)
284 if(LoadStringW(hDllInstance
, StopBits
[i
].StrId
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
286 SendMessageW(hBox
, CB_INSERTSTRING
, (WPARAM
)i
, (LPARAM
)wstr
);
287 if(StopBits
[i
].StopBit
== lpDlgInfo
->lpCC
->dcb
.StopBits
)
288 SendMessageW(hBox
, CB_SETCURSEL
, (WPARAM
)i
, 0);
292 if(SendMessageW(hBox
, CB_GETCURSEL
, 0, 0)==CB_ERR
)
293 SendMessageW(hBox
, CB_SETCURSEL
, DEFAULT_STOPBITS_INDEX
, 0);
295 /* Initialize flow control combo */
296 if(!(hBox
= GetDlgItem(hDlg
, IDC_FLOW
)))
297 EndDialog(hDlg
, ERROR_CANCELLED
);
299 if(LoadStringW(hDllInstance
, IDS_FC_NO
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
301 SendMessageW(hBox
, CB_INSERTSTRING
, 0, (LPARAM
)wstr
);
302 SendMessageW(hBox
, CB_SETCURSEL
, 0, 0);
303 lpDlgInfo
->InitialFlowIndex
= 0;
307 if(LoadStringW(hDllInstance
, IDS_FC_CTSRTS
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
309 SendMessageW(hBox
, CB_INSERTSTRING
, 1, (LPARAM
)wstr
);
310 if(lpDlgInfo
->lpCC
->dcb
.fRtsControl
== RTS_CONTROL_HANDSHAKE
311 || lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
!= FALSE
)
313 SendMessageW(hBox
, CB_SETCURSEL
, 1, 0);
314 lpDlgInfo
->InitialFlowIndex
= 1;
318 if(LoadStringW(hDllInstance
, IDS_FC_XONXOFF
, wstr
, sizeof(wstr
) / sizeof(wstr
[0])))
320 SendMessageW(hBox
, CB_INSERTSTRING
, 2, (LPARAM
)wstr
);
321 if(lpDlgInfo
->lpCC
->dcb
.fOutX
|| lpDlgInfo
->lpCC
->dcb
.fInX
)
323 SendMessageW(hBox
, CB_SETCURSEL
, 2, 0);
324 lpDlgInfo
->InitialFlowIndex
= 2;
329 SetFocus(GetDlgItem(hDlg
, IDC_OKBTN
));
332 } /* WM_INITDIALOG */
339 EndDialog(hDlg
, ERROR_CANCELLED
);
343 EndDialog(hDlg
, ERROR_SUCCESS
);
351 EndDialog(hDlg
, ERROR_CANCELLED
);
362 VOID
OkButton(HWND hDlg
)
364 LPDIALOG_INFO lpDlgInfo
;
367 lpDlgInfo
= (LPDIALOG_INFO
) GetWindowLongPtrW(hDlg
, DWLP_USER
);
370 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_BAUDRATE
), CB_GETCURSEL
, 0, 0);
371 lpDlgInfo
->lpCC
->dcb
.BaudRate
= Bauds
[Index
];
374 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_BYTESIZE
), CB_GETCURSEL
, 0, 0);
375 lpDlgInfo
->lpCC
->dcb
.ByteSize
= ByteSizes
[Index
];
378 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_PARITY
), CB_GETCURSEL
, 0, 0);
379 lpDlgInfo
->lpCC
->dcb
.Parity
= Parities
[Index
].Parity
;
382 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_STOPBITS
), CB_GETCURSEL
, 0, 0);
383 lpDlgInfo
->lpCC
->dcb
.StopBits
= StopBits
[Index
].StopBit
;
386 Index
= SendMessageW(GetDlgItem(hDlg
, IDC_FLOW
), CB_GETCURSEL
, 0, 0);
387 if(lpDlgInfo
->InitialFlowIndex
!= Index
)
392 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
393 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_DISABLE
;
394 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= FALSE
;
395 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
396 lpDlgInfo
->lpCC
->dcb
.fOutX
= FALSE
;
397 lpDlgInfo
->lpCC
->dcb
.fInX
= FALSE
;
399 case 1: /* CTS/RTS */
400 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
401 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_HANDSHAKE
;
402 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= TRUE
;
403 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
404 lpDlgInfo
->lpCC
->dcb
.fOutX
= FALSE
;
405 lpDlgInfo
->lpCC
->dcb
.fInX
= FALSE
;
407 case 2: /* XON/XOFF */
408 lpDlgInfo
->lpCC
->dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
409 lpDlgInfo
->lpCC
->dcb
.fRtsControl
= RTS_CONTROL_DISABLE
;
410 lpDlgInfo
->lpCC
->dcb
.fOutxCtsFlow
= FALSE
;
411 lpDlgInfo
->lpCC
->dcb
.fOutxDsrFlow
= FALSE
;
412 lpDlgInfo
->lpCC
->dcb
.fOutX
= TRUE
;
413 lpDlgInfo
->lpCC
->dcb
.fInX
= TRUE
;