Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenserialui.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS SerialUI DLL 00004 * FILE: serialui.c 00005 * PUROPSE: A dialog box to configure COM port. 00006 * Functions to set (and get too) default configuration. 00007 * PROGRAMMERS: Saveliy Tretiakov (saveliyt@mail.ru) 00008 * REVISIONS: 00009 * ST (05/04/2005) Created. Implemented drvCommConfigDialog. 00010 */ 00011 00012 #include <serialui.h> 00013 00014 static HINSTANCE hDllInstance; 00015 00016 /************************************ 00017 * 00018 * DATA 00019 * 00020 ************************************/ 00021 00022 const DWORD Bauds[] = { 00023 CBR_110, 00024 CBR_300, 00025 CBR_600, 00026 CBR_1200, 00027 CBR_2400, 00028 CBR_4800, 00029 CBR_9600, 00030 CBR_14400, 00031 CBR_19200, 00032 CBR_38400, 00033 CBR_56000, 00034 CBR_57600, 00035 CBR_115200, 00036 CBR_128000, 00037 CBR_256000, 00038 0 00039 }; 00040 00041 const BYTE ByteSizes[] = { 00042 5, 00043 6, 00044 7, 00045 8, 00046 0 00047 }; 00048 00049 00050 const PARITY_INFO Parities[] = { 00051 { EVENPARITY, IDS_EVENPARITY }, 00052 { MARKPARITY, IDS_MARKPARITY }, 00053 { NOPARITY, IDS_NOPARITY }, 00054 { ODDPARITY, IDS_ODDPARITY }, 00055 { SPACEPARITY, IDS_SPACEPARITY }, 00056 { 0, 0 } 00057 }; 00058 00059 const STOPBIT_INFO StopBits[] = { 00060 { ONESTOPBIT, IDS_ONESTOPBIT }, 00061 { ONE5STOPBITS, IDS_ONE5STOPBITS }, 00062 { TWOSTOPBITS, IDS_TWOSTOPBITS }, 00063 { 0, 0 } 00064 }; 00065 00066 00067 /************************************ 00068 * 00069 * DLLMAIN 00070 * 00071 ************************************/ 00072 00073 BOOL 00074 WINAPI 00075 DllMain(HINSTANCE hInstance, 00076 DWORD dwReason, 00077 LPVOID reserved) 00078 { 00079 if(dwReason==DLL_PROCESS_ATTACH) 00080 { 00081 hDllInstance = hInstance; 00082 } 00083 else if(dwReason==DLL_THREAD_ATTACH) 00084 { 00085 DisableThreadLibraryCalls(hInstance); 00086 } 00087 00088 return TRUE; 00089 } 00090 00091 00092 /************************************ 00093 * 00094 * EXPORTS 00095 * 00096 ************************************/ 00097 00098 /* 00099 * @implemented 00100 */ 00101 DWORD WINAPI drvCommConfigDialogW(LPCWSTR lpszDevice, 00102 HWND hWnd, 00103 LPCOMMCONFIG lpCommConfig) 00104 { 00105 DIALOG_INFO DialogInfo; 00106 00107 if(!lpszDevice || !lpCommConfig) 00108 { 00109 return ERROR_INVALID_PARAMETER; 00110 } 00111 00112 DialogInfo.lpszDevice = lpszDevice; 00113 DialogInfo.lpCC = lpCommConfig; 00114 00115 return DialogBoxParamW(hDllInstance, MAKEINTRESOURCEW(IDD_COMMDLG), 00116 hWnd, (DLGPROC)CommDlgProc, (LPARAM)&DialogInfo); 00117 } 00118 00119 /* 00120 * @implemented 00121 */ 00122 DWORD WINAPI drvCommConfigDialogA(LPCSTR lpszDevice, 00123 HWND hWnd, 00124 LPCOMMCONFIG lpCommConfig) 00125 { 00126 BOOL result; 00127 UINT len; 00128 WCHAR *wstr; 00129 00130 len = MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, NULL, 0); 00131 if((wstr = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)))) 00132 { 00133 MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, wstr, len); 00134 result = drvCommConfigDialogW(wstr, hWnd, lpCommConfig); 00135 HeapFree(GetProcessHeap(), 0, wstr); 00136 return result; 00137 } 00138 else 00139 return ERROR_NOT_ENOUGH_MEMORY; 00140 } 00141 00142 /* 00143 * @unimplemented 00144 */ 00145 DWORD WINAPI drvSetDefaultCommConfigW(LPCWSTR lpszDevice, 00146 LPCOMMCONFIG lpCommConfig, 00147 DWORD dwSize) 00148 { 00149 UNIMPLEMENTED 00150 } 00151 00152 /* 00153 * @unimplemented 00154 */ 00155 DWORD WINAPI drvSetDefaultCommConfigA(LPCSTR lpszDevice, 00156 LPCOMMCONFIG lpCommConfig, 00157 DWORD dwSize) 00158 { 00159 UNIMPLEMENTED 00160 } 00161 00162 /* 00163 * @unimplemented 00164 */ 00165 DWORD WINAPI drvGetDefaultCommConfigW(LPCWSTR lpszDevice, 00166 LPCOMMCONFIG lpCommConfig, 00167 LPDWORD lpdwSize) 00168 { 00169 UNIMPLEMENTED 00170 } 00171 00172 /* 00173 * @unimplemented 00174 */ 00175 DWORD WINAPI drvGetDefaultCommConfigA(LPCSTR lpszDevice, 00176 LPCOMMCONFIG lpCommConfig, 00177 LPDWORD lpdwSize) 00178 { 00179 UNIMPLEMENTED 00180 } 00181 00182 00183 /************************************ 00184 * 00185 * INTERNALS 00186 * 00187 ************************************/ 00188 00189 LRESULT CommDlgProc(HWND hDlg, 00190 UINT Msg, 00191 WPARAM wParam, 00192 LPARAM lParam) 00193 { 00194 LPDIALOG_INFO lpDlgInfo = NULL; 00195 HWND hBox; 00196 00197 switch (Msg) 00198 { 00199 00200 case WM_INITDIALOG: 00201 { 00202 WCHAR wstr[255]; 00203 RECT rc, rcDlg, rcOwner; 00204 HWND hOwner; 00205 INT i; 00206 00207 lpDlgInfo = (LPDIALOG_INFO)lParam; 00208 SetWindowLongPtrW(hDlg, DWL_USER, (LONG_PTR)lpDlgInfo); 00209 00210 /* Set title */ 00211 if(LoadStringW(hDllInstance, IDS_TITLE, wstr, sizeof(wstr) / sizeof(wstr[0]))) 00212 { 00213 SetWindowTextW(hDlg, wstr); 00214 } 00215 00216 /* FIXME - this won't work correctly systems with multiple monitors! */ 00217 if(!(hOwner = GetParent(hDlg))) 00218 hOwner = GetDesktopWindow(); 00219 00220 /* Position dialog in the center of owner window */ 00221 GetWindowRect(hOwner, &rcOwner); 00222 GetWindowRect(hDlg, &rcDlg); 00223 CopyRect(&rc, &rcOwner); 00224 OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); 00225 OffsetRect(&rc, -rc.left, -rc.top); 00226 OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); 00227 SetWindowPos(hDlg, HWND_TOP, 00228 rcOwner.left + (rc.right / 2), 00229 rcOwner.top + (rc.bottom / 2), 00230 0, 0, SWP_NOSIZE); 00231 00232 /* Initialize baud rate combo */ 00233 if(!(hBox = GetDlgItem(hDlg, IDC_BAUDRATE))) 00234 EndDialog(hDlg, ERROR_CANCELLED); 00235 00236 for(i = 0; Bauds[i]; i++) 00237 { 00238 wsprintf(wstr, L"%d", Bauds[i]); 00239 SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); 00240 if(Bauds[i] == lpDlgInfo->lpCC->dcb.BaudRate) 00241 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); 00242 } 00243 00244 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0) == CB_ERR) 00245 SendMessageW(hBox, CB_SETCURSEL, DEFAULT_BAUD_INDEX, 0); 00246 00247 /* Initialize byte size combo */ 00248 if(!(hBox = GetDlgItem(hDlg, IDC_BYTESIZE))) 00249 EndDialog(hDlg, ERROR_CANCELLED); 00250 00251 for(i = 0; ByteSizes[i]; i++) 00252 { 00253 wsprintf(wstr, L"%d", Bauds[i]); 00254 SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); 00255 if(ByteSizes[i] == lpDlgInfo->lpCC->dcb.ByteSize) 00256 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); 00257 } 00258 00259 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0) == CB_ERR) 00260 SendMessageW(hBox, CB_SETCURSEL, DEFAULT_BYTESIZE_INDEX, 0); 00261 00262 /* Initialize parity combo */ 00263 if(!(hBox = GetDlgItem(hDlg, IDC_PARITY))) 00264 EndDialog(hDlg, ERROR_CANCELLED); 00265 00266 for(i = 0; Parities[i].StrId; i++) 00267 { 00268 if(LoadStringW(hDllInstance, Parities[i].StrId, wstr, sizeof(wstr) / sizeof(wstr[0]))) 00269 { 00270 SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); 00271 if(Parities[i].Parity == lpDlgInfo->lpCC->dcb.Parity) 00272 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); 00273 } 00274 } 00275 00276 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0)==CB_ERR) 00277 SendMessageW(hBox, CB_SETCURSEL, DEFAULT_PARITY_INDEX, 0); 00278 00279 /* Initialize stop bits combo */ 00280 if(!(hBox = GetDlgItem(hDlg, IDC_STOPBITS))) 00281 EndDialog(hDlg, ERROR_CANCELLED); 00282 00283 for(i = 0; StopBits[i].StrId; i++) 00284 { 00285 if(LoadStringW(hDllInstance, StopBits[i].StrId, wstr, sizeof(wstr) / sizeof(wstr[0]))) 00286 { 00287 SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); 00288 if(StopBits[i].StopBit == lpDlgInfo->lpCC->dcb.StopBits) 00289 SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); 00290 } 00291 } 00292 00293 if(SendMessageW(hBox, CB_GETCURSEL, 0, 0)==CB_ERR) 00294 SendMessageW(hBox, CB_SETCURSEL, DEFAULT_STOPBITS_INDEX, 0); 00295 00296 /* Initialize flow control combo */ 00297 if(!(hBox = GetDlgItem(hDlg, IDC_FLOW))) 00298 EndDialog(hDlg, ERROR_CANCELLED); 00299 00300 if(LoadStringW(hDllInstance, IDS_FC_NO, wstr, sizeof(wstr) / sizeof(wstr[0]))) 00301 { 00302 SendMessageW(hBox, CB_INSERTSTRING, 0, (LPARAM)wstr); 00303 SendMessageW(hBox, CB_SETCURSEL, 0, 0); 00304 lpDlgInfo->InitialFlowIndex = 0; 00305 } 00306 00307 00308 if(LoadStringW(hDllInstance, IDS_FC_CTSRTS, wstr, sizeof(wstr) / sizeof(wstr[0]))) 00309 { 00310 SendMessageW(hBox, CB_INSERTSTRING, 1, (LPARAM)wstr); 00311 if(lpDlgInfo->lpCC->dcb.fRtsControl == RTS_CONTROL_HANDSHAKE 00312 || lpDlgInfo->lpCC->dcb.fOutxCtsFlow == TRUE) 00313 { 00314 SendMessageW(hBox, CB_SETCURSEL, 1, 0); 00315 lpDlgInfo->InitialFlowIndex = 1; 00316 } 00317 } 00318 00319 if(LoadStringW(hDllInstance, IDS_FC_XONXOFF, wstr, sizeof(wstr) / sizeof(wstr[0]))) 00320 { 00321 SendMessageW(hBox, CB_INSERTSTRING, 2, (LPARAM)wstr); 00322 if(lpDlgInfo->lpCC->dcb.fOutX || lpDlgInfo->lpCC->dcb.fInX) 00323 { 00324 SendMessageW(hBox, CB_SETCURSEL, 2, 0); 00325 lpDlgInfo->InitialFlowIndex = 2; 00326 } 00327 } 00328 00329 /* Set focus */ 00330 SetFocus(GetDlgItem(hDlg, IDC_OKBTN)); 00331 00332 return FALSE; 00333 } /* WM_INITDIALOG */ 00334 00335 case WM_COMMAND: 00336 { 00337 switch(wParam) 00338 { 00339 case IDC_CANCELBTN: 00340 EndDialog(hDlg, ERROR_CANCELLED); 00341 break; 00342 case IDC_OKBTN: 00343 OkButton(hDlg); 00344 EndDialog(hDlg, ERROR_SUCCESS); 00345 break; 00346 } 00347 return TRUE; 00348 } /* WM_COMMAND */ 00349 00350 case WM_CLOSE: 00351 { 00352 EndDialog(hDlg, ERROR_CANCELLED); 00353 return TRUE; 00354 } /* WM_CLOSE */ 00355 00356 default: 00357 return FALSE; 00358 } 00359 00360 } 00361 00362 00363 VOID OkButton(HWND hDlg) 00364 { 00365 LPDIALOG_INFO lpDlgInfo; 00366 UINT Index; 00367 00368 lpDlgInfo = (LPDIALOG_INFO) GetWindowLongPtrW(hDlg, DWL_USER); 00369 00370 /* Baud rate */ 00371 Index = SendMessageW(GetDlgItem(hDlg, IDC_BAUDRATE), CB_GETCURSEL, 0, 0); 00372 lpDlgInfo->lpCC->dcb.BaudRate = Bauds[Index]; 00373 00374 /* Byte size */ 00375 Index = SendMessageW(GetDlgItem(hDlg, IDC_BYTESIZE), CB_GETCURSEL, 0, 0); 00376 lpDlgInfo->lpCC->dcb.ByteSize = ByteSizes[Index]; 00377 00378 /* Parity */ 00379 Index = SendMessageW(GetDlgItem(hDlg, IDC_PARITY), CB_GETCURSEL, 0, 0); 00380 lpDlgInfo->lpCC->dcb.Parity = Parities[Index].Parity; 00381 00382 /* Stop bits */ 00383 Index = SendMessageW(GetDlgItem(hDlg, IDC_STOPBITS), CB_GETCURSEL, 0, 0); 00384 lpDlgInfo->lpCC->dcb.StopBits = StopBits[Index].StopBit; 00385 00386 /* Flow Control */ 00387 Index = SendMessageW(GetDlgItem(hDlg, IDC_FLOW), CB_GETCURSEL, 0, 0); 00388 if(lpDlgInfo->InitialFlowIndex != Index) 00389 { 00390 switch(Index) 00391 { 00392 case 0: /* NO */ 00393 lpDlgInfo->lpCC->dcb.fDtrControl = DTR_CONTROL_DISABLE; 00394 lpDlgInfo->lpCC->dcb.fRtsControl = RTS_CONTROL_DISABLE; 00395 lpDlgInfo->lpCC->dcb.fOutxCtsFlow = FALSE; 00396 lpDlgInfo->lpCC->dcb.fOutxDsrFlow = FALSE; 00397 lpDlgInfo->lpCC->dcb.fOutX = FALSE; 00398 lpDlgInfo->lpCC->dcb.fInX = FALSE; 00399 break; 00400 case 1: /* CTS/RTS */ 00401 lpDlgInfo->lpCC->dcb.fDtrControl = DTR_CONTROL_DISABLE; 00402 lpDlgInfo->lpCC->dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; 00403 lpDlgInfo->lpCC->dcb.fOutxCtsFlow = TRUE; 00404 lpDlgInfo->lpCC->dcb.fOutxDsrFlow = FALSE; 00405 lpDlgInfo->lpCC->dcb.fOutX = FALSE; 00406 lpDlgInfo->lpCC->dcb.fInX = FALSE; 00407 break; 00408 case 2: /* XON/XOFF */ 00409 lpDlgInfo->lpCC->dcb.fDtrControl = DTR_CONTROL_DISABLE; 00410 lpDlgInfo->lpCC->dcb.fRtsControl = RTS_CONTROL_DISABLE; 00411 lpDlgInfo->lpCC->dcb.fOutxCtsFlow = FALSE; 00412 lpDlgInfo->lpCC->dcb.fOutxDsrFlow = FALSE; 00413 lpDlgInfo->lpCC->dcb.fOutX = TRUE; 00414 lpDlgInfo->lpCC->dcb.fInX = TRUE; 00415 break; 00416 } 00417 } 00418 } Generated on Sun May 27 2012 04:26:10 for ReactOS by
1.7.6.1
|