ReactOS 0.4.15-dev-8207-gd73a838
serialui.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS SerialUI DLL
4 * FILE: serialui.c
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)
8 * REVISIONS:
9 * ST (05/04/2005) Created. Implemented drvCommConfigDialog.
10 */
11
12#include "serialui.h"
13
15
16/************************************
17 *
18 * DATA
19 *
20 ************************************/
21
22const DWORD Bauds[] = {
23 CBR_110,
24 CBR_300,
25 CBR_600,
38 0
39};
40
41const BYTE ByteSizes[] = {
42 5,
43 6,
44 7,
45 8,
46 0
47};
48
49
56 { 0, 0 }
57};
58
63 { 0, 0 }
64};
65
66
67/************************************
68 *
69 * DLLMAIN
70 *
71 ************************************/
72
73BOOL
78{
80 {
82 }
84 {
86 }
87
88 return TRUE;
89}
90
91
92/************************************
93 *
94 * EXPORTS
95 *
96 ************************************/
97
98/*
99 * @implemented
100 */
102 HWND hWnd,
103 LPCOMMCONFIG lpCommConfig)
104{
105 DIALOG_INFO DialogInfo;
106
107 if(!lpszDevice || !lpCommConfig)
108 {
110 }
111
112 DialogInfo.lpszDevice = lpszDevice;
113 DialogInfo.lpCC = lpCommConfig;
114
116 hWnd, CommDlgProc, (LPARAM)&DialogInfo);
117}
118
119/*
120 * @implemented
121 */
123 HWND hWnd,
124 LPCOMMCONFIG lpCommConfig)
125{
126 BOOL result;
127 UINT len;
128 WCHAR *wstr;
129
130 len = MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, NULL, 0);
131 if((wstr = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
132 {
133 MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, wstr, len);
134 result = drvCommConfigDialogW(wstr, hWnd, lpCommConfig);
135 HeapFree(GetProcessHeap(), 0, wstr);
136 return result;
137 }
138 else
140}
141
142/*
143 * @unimplemented
144 */
146 LPCOMMCONFIG lpCommConfig,
148{
150}
151
152/*
153 * @unimplemented
154 */
156 LPCOMMCONFIG lpCommConfig,
158{
160}
161
162/*
163 * @unimplemented
164 */
166 LPCOMMCONFIG lpCommConfig,
168{
170}
171
172/*
173 * @unimplemented
174 */
176 LPCOMMCONFIG lpCommConfig,
178{
180}
181
182
183/************************************
184 *
185 * INTERNALS
186 *
187 ************************************/
188
192{
193 LPDIALOG_INFO lpDlgInfo = NULL;
194 HWND hBox;
195
196 switch (Msg)
197 {
198
199 case WM_INITDIALOG:
200 {
201 WCHAR wstr[255];
202 RECT rc, rcDlg, rcOwner;
203 HWND hOwner;
204 INT i;
205
206 lpDlgInfo = (LPDIALOG_INFO)lParam;
207 SetWindowLongPtrW(hDlg, DWLP_USER, (LONG_PTR)lpDlgInfo);
208
209 /* Set title */
210 if(LoadStringW(hDllInstance, IDS_TITLE, wstr, sizeof(wstr) / sizeof(wstr[0])))
211 {
212 SetWindowTextW(hDlg, wstr);
213 }
214
215 /* FIXME - this won't work correctly systems with multiple monitors! */
216 if(!(hOwner = GetParent(hDlg)))
217 hOwner = GetDesktopWindow();
218
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);
227 rcOwner.left + (rc.right / 2),
228 rcOwner.top + (rc.bottom / 2),
229 0, 0, SWP_NOSIZE);
230
231 /* Initialize baud rate combo */
232 if(!(hBox = GetDlgItem(hDlg, IDC_BAUDRATE)))
234
235 for(i = 0; Bauds[i]; i++)
236 {
237 wsprintf(wstr, L"%d", Bauds[i]);
239 if(Bauds[i] == lpDlgInfo->lpCC->dcb.BaudRate)
240 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0);
241 }
242
243 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0) == CB_ERR)
245
246 /* Initialize byte size combo */
247 if(!(hBox = GetDlgItem(hDlg, IDC_BYTESIZE)))
249
250 for(i = 0; ByteSizes[i]; i++)
251 {
252 wsprintf(wstr, L"%d", Bauds[i]);
254 if(ByteSizes[i] == lpDlgInfo->lpCC->dcb.ByteSize)
255 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0);
256 }
257
258 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0) == CB_ERR)
260
261 /* Initialize parity combo */
262 if(!(hBox = GetDlgItem(hDlg, IDC_PARITY)))
264
265 for(i = 0; Parities[i].StrId; i++)
266 {
267 if(LoadStringW(hDllInstance, Parities[i].StrId, wstr, sizeof(wstr) / sizeof(wstr[0])))
268 {
270 if(Parities[i].Parity == lpDlgInfo->lpCC->dcb.Parity)
271 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0);
272 }
273 }
274
275 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0)==CB_ERR)
277
278 /* Initialize stop bits combo */
279 if(!(hBox = GetDlgItem(hDlg, IDC_STOPBITS)))
281
282 for(i = 0; StopBits[i].StrId; i++)
283 {
284 if(LoadStringW(hDllInstance, StopBits[i].StrId, wstr, sizeof(wstr) / sizeof(wstr[0])))
285 {
287 if(StopBits[i].StopBit == lpDlgInfo->lpCC->dcb.StopBits)
288 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0);
289 }
290 }
291
292 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0)==CB_ERR)
294
295 /* Initialize flow control combo */
296 if(!(hBox = GetDlgItem(hDlg, IDC_FLOW)))
298
299 if(LoadStringW(hDllInstance, IDS_FC_NO, wstr, sizeof(wstr) / sizeof(wstr[0])))
300 {
301 SendMessageW(hBox, CB_INSERTSTRING, 0, (LPARAM)wstr);
302 SendMessageW(hBox, CB_SETCURSEL, 0, 0);
303 lpDlgInfo->InitialFlowIndex = 0;
304 }
305
306
307 if(LoadStringW(hDllInstance, IDS_FC_CTSRTS, wstr, sizeof(wstr) / sizeof(wstr[0])))
308 {
309 SendMessageW(hBox, CB_INSERTSTRING, 1, (LPARAM)wstr);
310 if(lpDlgInfo->lpCC->dcb.fRtsControl == RTS_CONTROL_HANDSHAKE
311 || lpDlgInfo->lpCC->dcb.fOutxCtsFlow != FALSE)
312 {
313 SendMessageW(hBox, CB_SETCURSEL, 1, 0);
314 lpDlgInfo->InitialFlowIndex = 1;
315 }
316 }
317
318 if(LoadStringW(hDllInstance, IDS_FC_XONXOFF, wstr, sizeof(wstr) / sizeof(wstr[0])))
319 {
320 SendMessageW(hBox, CB_INSERTSTRING, 2, (LPARAM)wstr);
321 if(lpDlgInfo->lpCC->dcb.fOutX || lpDlgInfo->lpCC->dcb.fInX)
322 {
323 SendMessageW(hBox, CB_SETCURSEL, 2, 0);
324 lpDlgInfo->InitialFlowIndex = 2;
325 }
326 }
327
328 /* Set focus */
330
331 return FALSE;
332 } /* WM_INITDIALOG */
333
334 case WM_COMMAND:
335 {
336 switch(wParam)
337 {
338 case IDC_CANCELBTN:
340 break;
341 case IDC_OKBTN:
342 OkButton(hDlg);
344 break;
345 }
346 return TRUE;
347 } /* WM_COMMAND */
348
349 case WM_CLOSE:
350 {
352 return TRUE;
353 } /* WM_CLOSE */
354
355 default:
356 return FALSE;
357 }
358
359}
360
361
363{
364 LPDIALOG_INFO lpDlgInfo;
365 UINT Index;
366
367 lpDlgInfo = (LPDIALOG_INFO) GetWindowLongPtrW(hDlg, DWLP_USER);
368
369 /* Baud rate */
371 lpDlgInfo->lpCC->dcb.BaudRate = Bauds[Index];
372
373 /* Byte size */
375 lpDlgInfo->lpCC->dcb.ByteSize = ByteSizes[Index];
376
377 /* Parity */
379 lpDlgInfo->lpCC->dcb.Parity = Parities[Index].Parity;
380
381 /* Stop bits */
383 lpDlgInfo->lpCC->dcb.StopBits = StopBits[Index].StopBit;
384
385 /* Flow Control */
387 if(lpDlgInfo->InitialFlowIndex != Index)
388 {
389 switch(Index)
390 {
391 case 0: /* NO */
394 lpDlgInfo->lpCC->dcb.fOutxCtsFlow = FALSE;
395 lpDlgInfo->lpCC->dcb.fOutxDsrFlow = FALSE;
396 lpDlgInfo->lpCC->dcb.fOutX = FALSE;
397 lpDlgInfo->lpCC->dcb.fInX = FALSE;
398 break;
399 case 1: /* CTS/RTS */
402 lpDlgInfo->lpCC->dcb.fOutxCtsFlow = TRUE;
403 lpDlgInfo->lpCC->dcb.fOutxDsrFlow = FALSE;
404 lpDlgInfo->lpCC->dcb.fOutX = FALSE;
405 lpDlgInfo->lpCC->dcb.fInX = FALSE;
406 break;
407 case 2: /* XON/XOFF */
410 lpDlgInfo->lpCC->dcb.fOutxCtsFlow = FALSE;
411 lpDlgInfo->lpCC->dcb.fOutxDsrFlow = FALSE;
412 lpDlgInfo->lpCC->dcb.fOutX = TRUE;
413 lpDlgInfo->lpCC->dcb.fInX = TRUE;
414 break;
415 }
416 }
417}
#define IDS_TITLE
Definition: resource.h:30
HWND hWnd
Definition: settings.c:17
DWORD dwReason
Definition: misc.cpp:154
#define UNIMPLEMENTED
Definition: debug.h:118
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
struct @1643 Msg[]
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define DLL_THREAD_ATTACH
Definition: compat.h:132
#define MultiByteToWideChar
Definition: compat.h:110
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DEFAULT_PARITY_INDEX
Definition: serial.c:29
#define IDS_EVENPARITY
Definition: resource.h:3
#define IDC_BAUDRATE
Definition: resource.h:29
#define IDS_TWOSTOPBITS
Definition: resource.h:11
#define IDD_COMMDLG
Definition: resource.h:19
#define IDC_BYTESIZE
Definition: resource.h:30
#define IDC_CANCELBTN
Definition: resource.h:22
#define IDS_FC_XONXOFF
Definition: resource.h:15
#define IDS_SPACEPARITY
Definition: resource.h:7
#define IDC_OKBTN
Definition: resource.h:21
#define IDS_FC_CTSRTS
Definition: resource.h:14
#define IDS_MARKPARITY
Definition: resource.h:4
#define IDC_STOPBITS
Definition: resource.h:32
#define IDS_FC_NO
Definition: resource.h:13
#define IDC_FLOW
Definition: resource.h:33
#define IDS_ONESTOPBIT
Definition: resource.h:9
#define IDS_ONE5STOPBITS
Definition: resource.h:10
#define IDS_ODDPARITY
Definition: resource.h:6
#define IDC_PARITY
Definition: resource.h:31
#define IDS_NOPARITY
Definition: resource.h:5
r reserved
Definition: btrfs.c:3006
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static DWORD LPSTR PDWORD lpdwSize
Definition: process.c:72
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
const STOPBIT_INFO StopBits[]
Definition: serialui.c:59
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID reserved)
Definition: serialui.c:75
VOID OkButton(HWND hDlg)
Definition: serialui.c:362
DWORD WINAPI drvGetDefaultCommConfigA(LPCSTR lpszDevice, LPCOMMCONFIG lpCommConfig, LPDWORD lpdwSize)
Definition: serialui.c:175
DWORD WINAPI drvSetDefaultCommConfigA(LPCSTR lpszDevice, LPCOMMCONFIG lpCommConfig, DWORD dwSize)
Definition: serialui.c:155
DWORD WINAPI drvSetDefaultCommConfigW(LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, DWORD dwSize)
Definition: serialui.c:145
const DWORD Bauds[]
Definition: serialui.c:22
DWORD WINAPI drvGetDefaultCommConfigW(LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, LPDWORD lpdwSize)
Definition: serialui.c:165
DWORD WINAPI drvCommConfigDialogW(LPCWSTR lpszDevice, HWND hWnd, LPCOMMCONFIG lpCommConfig)
Definition: serialui.c:101
const PARITY_INFO Parities[]
Definition: serialui.c:50
INT_PTR CALLBACK CommDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: serialui.c:191
const BYTE ByteSizes[]
Definition: serialui.c:41
DWORD WINAPI drvCommConfigDialogA(LPCSTR lpszDevice, HWND hWnd, LPCOMMCONFIG lpCommConfig)
Definition: serialui.c:122
static HINSTANCE hDllInstance
Definition: serialui.c:14
struct _DIALOG_INFO * LPDIALOG_INFO
#define DEFAULT_BYTESIZE_INDEX
Definition: serialui.h:24
#define DEFAULT_STOPBITS_INDEX
Definition: serialui.h:26
#define DEFAULT_BAUD_INDEX
Definition: serialui.h:23
DWORD fOutxCtsFlow
Definition: winbase.h:650
BYTE Parity
Definition: winbase.h:666
DWORD fRtsControl
Definition: winbase.h:659
DWORD fOutxDsrFlow
Definition: winbase.h:651
DWORD BaudRate
Definition: winbase.h:647
DWORD fDtrControl
Definition: winbase.h:652
DWORD fInX
Definition: winbase.h:656
BYTE ByteSize
Definition: winbase.h:665
DWORD fOutX
Definition: winbase.h:655
BYTE StopBits
Definition: winbase.h:667
LPCOMMCONFIG lpCC
Definition: serialui.h:32
UINT InitialFlowIndex
Definition: serialui.h:31
LPCWSTR lpszDevice
Definition: serialui.h:30
UINT StrId
Definition: serialui.h:38
BYTE Parity
Definition: serialui.h:37
UINT StrId
Definition: serialui.h:44
BYTE StopBit
Definition: serialui.h:43
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
int32_t INT_PTR
Definition: typedefs.h:64
uint32_t * LPDWORD
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
_In_ WDFCOLLECTION _In_ ULONG Index
#define CBR_56000
Definition: winbase.h:471
#define MARKPARITY
Definition: winbase.h:456
#define CBR_300
Definition: winbase.h:462
#define CBR_57600
Definition: winbase.h:472
#define CBR_115200
Definition: winbase.h:473
#define CBR_2400
Definition: winbase.h:465
#define TWOSTOPBITS
Definition: winbase.h:460
#define ONESTOPBIT
Definition: winbase.h:458
#define RTS_CONTROL_HANDSHAKE
Definition: winbase.h:538
#define EVENPARITY
Definition: winbase.h:455
#define DTR_CONTROL_DISABLE
Definition: winbase.h:533
#define ODDPARITY
Definition: winbase.h:454
#define CBR_600
Definition: winbase.h:463
#define CBR_128000
Definition: winbase.h:474
#define ONE5STOPBITS
Definition: winbase.h:459
#define RTS_CONTROL_DISABLE
Definition: winbase.h:536
#define CBR_1200
Definition: winbase.h:464
#define CBR_14400
Definition: winbase.h:468
#define SPACEPARITY
Definition: winbase.h:457
#define CBR_19200
Definition: winbase.h:469
#define NOPARITY
Definition: winbase.h:453
#define CBR_256000
Definition: winbase.h:475
#define CBR_4800
Definition: winbase.h:466
#define CBR_38400
Definition: winbase.h:470
#define CBR_9600
Definition: winbase.h:467
#define CBR_110
Definition: winbase.h:461
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define ERROR_CANCELLED
Definition: winerror.h:726
BOOL WINAPI CopyRect(_Out_ LPRECT, _In_ LPCRECT)
#define WM_CLOSE
Definition: winuser.h:1621
#define DWLP_USER
Definition: winuser.h:872
#define GetWindowLongPtrW
Definition: winuser.h:4829
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define WM_COMMAND
Definition: winuser.h:1740
#define CB_ERR
Definition: winuser.h:2435
#define CB_SETCURSEL
Definition: winuser.h:1961
#define SWP_NOSIZE
Definition: winuser.h:1245
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:656
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define HWND_TOP
Definition: winuser.h:1207
HWND WINAPI SetFocus(_In_opt_ HWND)
#define wsprintf
Definition: winuser.h:5874
HWND WINAPI GetParent(_In_ HWND)
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define CB_INSERTSTRING
Definition: winuser.h:1957
#define CB_GETCURSEL
Definition: winuser.h:1943
#define SetWindowLongPtrW
Definition: winuser.h:5355
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193