ReactOS 0.4.15-dev-7906-g1b85a5f
fdebug.c
Go to the documentation of this file.
1/* fdebug.c : Defines the entry point for the application. */
2
3#include <tchar.h>
4
5#include <windef.h>
6#include <winbase.h>
7#include <wingdi.h>
8#include <winuser.h>
9#include <commdlg.h>
10#include <process.h>
11
12#include "resource.h"
13#include "rs232.h"
14
15#define MAX_LOADSTRING 100
16
17// Global Variables:
18HINSTANCE hInst; // current instance
19TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
20TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
21HWND hMainWnd; // The main window handle
22HWND hDisplayWnd; // The window to display the incoming data
23HWND hEditWnd; // The edit window to get input from the user
24TCHAR strComPort[MAX_PATH] = TEXT("COM1"); // The COM port to use
25TCHAR strBaudRate[MAX_PATH] = TEXT("115200"); // The baud rate to use
26TCHAR strCaptureFileName[MAX_PATH] = TEXT(""); // The file name to capture to
27BOOL bConnected = FALSE; // Tells us if we are currently connected
28BOOL bCapturing = FALSE; // Tells us if we are currently capturing data
29BOOL bLocalEcho = FALSE; // Tells us if local echo is currently enabled
30HANDLE hCaptureFile; // Handle to the capture file
31DWORD dwThreadId = 0; // Thread id of RS232 communication thread
32
33// Forward declarations of functions included in this code module:
43
45 HINSTANCE hPrevInstance,
46 LPTSTR lpCmdLine,
47 int nCmdShow)
48{
49 // TODO: Place code here.
50 MSG msg;
51 HACCEL hAccelTable;
52
53 UNREFERENCED_PARAMETER(lpCmdLine);
54 UNREFERENCED_PARAMETER(hPrevInstance);
55
56 // Initialize global strings
60
61 // Perform application initialization:
62 if (!InitInstance (hInstance, nCmdShow))
63 {
64 return FALSE;
65 }
66
68
69 // Main message loop:
70 while (GetMessage(&msg, NULL, 0, 0))
71 {
72 if (!TranslateAccelerator(hMainWnd, hAccelTable, &msg))
73 {
76 }
77 }
78
79 return (int)msg.wParam;
80}
81
82
83
84//
85// FUNCTION: MyRegisterClass()
86//
87// PURPOSE: Registers the window class.
88//
89// COMMENTS:
90//
91// This function and its usage is only necessary if you want this code
92// to be compatible with Win32 systems prior to the 'RegisterClassEx'
93// function that was added to Windows 95. It is important to call this function
94// so that the application will get 'well formed' small icons associated
95// with it.
96//
98{
99 WNDCLASSEX wcex;
100
101 wcex.cbSize = sizeof(wcex);
102
103 wcex.style = CS_HREDRAW | CS_VREDRAW;
104 wcex.lpfnWndProc = WndProc;
105 wcex.cbClsExtra = 0;
106 wcex.cbWndExtra = 0;
107 wcex.hInstance = hInstance;
110 wcex.hbrBackground = NULL;//(HBRUSH)(COLOR_WINDOW+1);
116 16,
117 16,
118 LR_SHARED);
119
120 return RegisterClassEx(&wcex);
121}
122
123//
124// FUNCTION: InitInstance(HANDLE, int)
125//
126// PURPOSE: Saves instance handle and creates main window
127//
128// COMMENTS:
129//
130// In this function, we save the instance handle in a global variable and
131// create and display the main program window.
132//
134{
135 HWND hWnd;
136
137 hInst = hInstance; // Store instance handle in our global variable
138
141
142 if (!hWnd)
143 {
144 return FALSE;
145 }
146
147 hMainWnd = hWnd;
148
149 ShowWindow(hWnd, nCmdShow);
151
152 return TRUE;
153}
154
156{
157 int wmId, wmEvent;
158 PAINTSTRUCT ps;
159 HDC hdc;
160 RECT rc;
161 TCHAR WndText[MAX_PATH];
162 DWORD Index;
163 NONCLIENTMETRICS ncm;
164 HFONT hFont;
165
166 switch (message)
167 {
168 case WM_CREATE:
169
172
173 ZeroMemory(&ncm, sizeof(ncm));
174 ncm.cbSize = sizeof(ncm);
175 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
176
177 hFont = CreateFontIndirect(&ncm.lfMessageFont);
178
181
182 break;
183 case WM_COMMAND:
184 wmId = LOWORD(wParam);
185 wmEvent = HIWORD(wParam);
186
187 if (lParam == (LPARAM)hEditWnd && wmEvent == EN_CHANGE)
188 {
190
191 if (_tcslen(WndText) > 0)
192 {
194
195 if (!bConnected)
196 {
197 MessageBox(hWnd, TEXT("You are not currently connected!"), TEXT("Error"), MB_OK|MB_ICONSTOP);
198 break;
199 }
200
201 for (Index=0; Index<_tcslen(WndText); Index++)
202 {
203 if (dwThreadId != 0)
204 {
206 }
207 }
208 }
209 }
210
211 // Parse the menu selections:
212 switch (wmId)
213 {
214 case IDM_ABOUT:
216 break;
217 case IDM_EXIT:
219 break;
222 break;
223 case IDM_FILE_CONNECT:
224 if (bConnected)
225 {
226 MessageBox(hWnd, TEXT("You are already connected!"), TEXT("Error"), MB_OK|MB_ICONSTOP);
227 }
228 else
229 {
231 {
236 }
237 }
238 break;
240 if (bConnected)
241 {
245 }
246 else
247 {
248 MessageBox(hWnd, TEXT("You are not currently connected!"), TEXT("Error"), MB_OK|MB_ICONSTOP);
249 }
250 break;
253 {
258 }
259 break;
261 if (bCapturing)
262 {
268 }
269 break;
271 if (bLocalEcho)
272 {
275 }
276 else
277 {
280 }
281 break;
282 default:
284 }
285 break;
286 case WM_PAINT:
287 hdc = BeginPaint(hWnd, &ps);
288 (void)hdc; // FIXME
289 EndPaint(hWnd, &ps);
290 break;
291 case WM_SIZE:
292
293 GetClientRect(hWnd, &rc);
294
295 MoveWindow(hDisplayWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top - 20, TRUE);
296 MoveWindow(hEditWnd, rc.left, rc.bottom - 20, rc.right - rc.left, 20, TRUE);
297
298 break;
299 case WM_DESTROY:
301 break;
302 default:
304 }
305 return 0;
306}
307
309{
310 HWND hLicenseEditWnd;
311 TCHAR strLicense[0x1000];
312
314
315 switch (message)
316 {
317 case WM_INITDIALOG:
318
319 hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE_EDIT);
320
321 LoadString(hInst, IDS_LICENSE, strLicense, 0x1000);
322
323 SetWindowText(hLicenseEditWnd, strLicense);
324
325 return TRUE;
326
327 case WM_COMMAND:
328 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
329 {
330 EndDialog(hDlg, LOWORD(wParam));
331 return TRUE;
332 }
333 break;
334 }
335 return FALSE;
336}
337
339{
341
342 switch (message)
343 {
344 case WM_INITDIALOG:
345
348
349 return TRUE;
350
351 case WM_COMMAND:
352 if (LOWORD(wParam) == IDOK)
353 {
356 }
357
358 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
359 {
360 EndDialog(hDlg, LOWORD(wParam));
361 return TRUE;
362 }
363 break;
364 }
365 return FALSE;
366}
367
369{
371
373
374 switch (message)
375 {
376 case WM_INITDIALOG:
377
379
380 return TRUE;
381
382 case WM_COMMAND:
383 if (LOWORD(wParam) == IDC_BROWSE)
384 {
385 ZeroMemory(&ofn, sizeof(ofn));
386 ofn.lStructSize = sizeof(ofn);
387 ofn.hwndOwner = hDlg;
392 ofn.nFilterIndex = 0;
396 ofn.nMaxFileTitle = 0;
400
401 if (GetOpenFileName(&ofn))
402 {
404 }
405 }
406
407 if (LOWORD(wParam) == IDOK)
408 {
410 }
411
412 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
413 {
414 EndDialog(hDlg, LOWORD(wParam));
415 return TRUE;
416 }
417 break;
418 }
419 return FALSE;
420}
421
423{
424 HMENU hMenuBar;
425 HMENU hFileMenu;
426
427 hMenuBar = GetMenu(hMainWnd);
428 hFileMenu = GetSubMenu(hMenuBar, 0);
430}
431
433{
434 HMENU hMenuBar;
435 HMENU hFileMenu;
436
437 hMenuBar = GetMenu(hMainWnd);
438 hFileMenu = GetSubMenu(hMenuBar, 0);
440}
441
443{
444 BYTE Byte;
446 MSG msg;
447 DWORD dwNumberOfBytesWritten;
448
450
452
454 {
455 MessageBox(hMainWnd, TEXT("Error opening port!"), TEXT("Error"), MB_OK|MB_ICONSTOP);
457 return;
458 }
459
460 _stprintf(String, TEXT("%s,n,8,1"), strBaudRate);
462 {
463 MessageBox(hMainWnd, TEXT("Error configuring port!"), TEXT("Error"), MB_OK|MB_ICONSTOP);
465 return;
466 }
467
468 while (bConnected)
469 {
470 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
471 {
472 if (msg.message == WM_CHAR)
473 {
475
476 if (bLocalEcho && msg.wParam != (WPARAM)TEXT('\r'))
477 {
479
480 if (hCaptureFile)
481 {
482 WriteFile(hCaptureFile, &msg.wParam, sizeof(TCHAR), &dwNumberOfBytesWritten, NULL);
483 }
484 }
485 }
486 }
487
489 {
490 _stprintf(String, TEXT("%c"), Byte);
491
493
494 if (hCaptureFile)
495 {
496 WriteFile(hCaptureFile, &String[0], sizeof(TCHAR), &dwNumberOfBytesWritten, NULL);
497 }
498 }
499 }
500
501 dwThreadId = 0;
503}
DWORD Id
#define __cdecl
Definition: accygwin.h:79
#define msg(x)
Definition: auth_time.c:54
#define IDD_ABOUTBOX
Definition: resource.h:8
#define IDC_LICENSE_EDIT
Definition: resource.h:20
#define IDS_LICENSE
Definition: resource.h:28
HWND hWnd
Definition: settings.c:17
#define IDS_APP_TITLE
Definition: resource.h:10
#define IDM_ABOUT
Definition: resource.h:29
#define IDM_EXIT
Definition: resource.h:27
HFONT hFont
Definition: main.c:53
#define IDD_CONNECTION
Definition: resource.h:15
#define IDM_FILE_STOPCAPTURE
Definition: resource.h:28
#define IDM_FILE_STARTCAPTURE
Definition: resource.h:27
#define IDC_FDEBUG
Definition: resource.h:12
#define IDM_FILE_CONNECT
Definition: resource.h:25
#define IDC_CAPTUREFILENAME
Definition: resource.h:20
#define IDD_CAPTURE
Definition: resource.h:16
#define IDM_FILE_LOCALECHO
Definition: resource.h:29
#define IDI_FDEBUG
Definition: resource.h:11
#define IDC_BROWSE
Definition: resource.h:21
#define IDM_FILE_CLEARDISPLAY
Definition: resource.h:24
#define IDM_FILE_DISCONNECT
Definition: resource.h:26
#define IDC_COMPORT
Definition: resource.h:18
#define IDC_BAUTRATE
Definition: resource.h:19
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_NOREADONLYRETURN
Definition: commdlg.h:113
#define GetOpenFileName
Definition: commdlg.h:665
WORD ATOM
Definition: dimm.idl:113
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
#define CloseHandle
Definition: compat.h:739
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CALLBACK
Definition: compat.h:35
#define FILE_SHARE_READ
Definition: compat.h:136
unsigned char Byte
Definition: zlib.h:37
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
BOOL Rs232OpenPortWin32(TCHAR *CommPort)
Definition: rs232.c:32
BOOL Rs232ClosePortWin32(VOID)
Definition: rs232.c:68
BOOL Rs232ReadByteWin32(BYTE *DataByte)
Definition: rs232.c:215
BOOL Rs232ConfigurePortWin32(TCHAR *DeviceControlString)
Definition: rs232.c:96
BOOL Rs232WriteByteWin32(BYTE DataByte)
Definition: rs232.c:240
TCHAR szTitle[MAX_LOADSTRING]
Definition: fdebug.c:19
VOID __cdecl Rs232Thread(VOID *Parameter)
Definition: fdebug.c:442
HANDLE hCaptureFile
Definition: fdebug.c:30
#define MAX_LOADSTRING
Definition: fdebug.c:15
INT_PTR CALLBACK CaptureDialogProc(HWND, UINT, WPARAM, LPARAM)
Definition: fdebug.c:368
VOID CheckLocalEchoMenuItem(BOOL Checked)
Definition: fdebug.c:432
VOID EnableFileMenuItemByID(UINT Id, BOOL Enable)
Definition: fdebug.c:422
DWORD dwThreadId
Definition: fdebug.c:31
HINSTANCE hInst
Definition: fdebug.c:18
HWND hMainWnd
Definition: fdebug.c:21
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM)
Definition: fdebug.c:308
TCHAR strCaptureFileName[MAX_PATH]
Definition: fdebug.c:26
BOOL InitInstance(HINSTANCE, int)
Definition: fdebug.c:133
TCHAR strBaudRate[MAX_PATH]
Definition: fdebug.c:25
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
Definition: fdebug.c:155
HWND hDisplayWnd
Definition: fdebug.c:22
ATOM MyRegisterClass(HINSTANCE hInstance)
Definition: fdebug.c:97
TCHAR strComPort[MAX_PATH]
Definition: fdebug.c:24
BOOL bConnected
Definition: fdebug.c:27
TCHAR szWindowClass[MAX_LOADSTRING]
Definition: fdebug.c:20
BOOL bCapturing
Definition: fdebug.c:28
INT_PTR CALLBACK ConnectionDialogProc(HWND, UINT, WPARAM, LPARAM)
Definition: fdebug.c:338
BOOL bLocalEcho
Definition: fdebug.c:29
HWND hEditWnd
Definition: fdebug.c:23
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _tWinMain
Definition: tchar.h:498
#define TEXT(s)
Definition: k32.h:26
#define _stprintf
Definition: utility.h:124
#define OPEN_ALWAYS
Definition: disk.h:70
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
static HICON
Definition: imagelist.c:84
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned int UINT
Definition: ndis.h:50
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VSCROLL
Definition: pedump.c:627
#define ES_AUTOHSCROLL
Definition: pedump.c:672
#define WS_VISIBLE
Definition: pedump.c:620
#define ES_LEFT
Definition: pedump.c:664
#define WS_HSCROLL
Definition: pedump.c:628
#define ES_MULTILINE
Definition: pedump.c:667
#define DefWindowProc
Definition: ros2win.h:31
_CRTIMP uintptr_t __cdecl _beginthread(_In_ void(__cdecl *_StartAddress)(void *), _In_ unsigned _StackSize, _In_opt_ void *_ArgList)
OPENFILENAME ofn
Definition: sndrec32.cpp:56
int cbClsExtra
Definition: winuser.h:3204
HINSTANCE hInstance
Definition: winuser.h:3206
HCURSOR hCursor
Definition: winuser.h:3208
LPCSTR lpszMenuName
Definition: winuser.h:3210
HICON hIconSm
Definition: winuser.h:3212
UINT style
Definition: winuser.h:3202
int cbWndExtra
Definition: winuser.h:3205
UINT cbSize
Definition: winuser.h:3201
WNDPROC lpfnWndProc
Definition: winuser.h:3203
LPCSTR lpszClassName
Definition: winuser.h:3211
HICON hIcon
Definition: winuser.h:3207
HBRUSH hbrBackground
Definition: winuser.h:3209
Definition: tftpd.h:60
DWORD nMaxCustFilter
Definition: commdlg.h:334
LPSTR lpstrFileTitle
Definition: commdlg.h:338
LPSTR lpstrCustomFilter
Definition: commdlg.h:333
DWORD nFilterIndex
Definition: commdlg.h:335
HWND hwndOwner
Definition: commdlg.h:330
LPCSTR lpstrTitle
Definition: commdlg.h:341
HINSTANCE hInstance
Definition: commdlg.h:331
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD nMaxFileTitle
Definition: commdlg.h:339
DWORD Flags
Definition: commdlg.h:342
LPCSTR lpstrInitialDir
Definition: commdlg.h:340
DWORD lStructSize
Definition: commdlg.h:329
LPCSTR lpstrFilter
Definition: commdlg.h:332
DWORD nMaxFile
Definition: commdlg.h:337
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT_PTR
Definition: typedefs.h:64
#define HIWORD(l)
Definition: typedefs.h:247
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
#define CreateFile
Definition: winbase.h:3749
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define CreateFontIndirect
Definition: wingdi.h:4444
#define WM_PAINT
Definition: winuser.h:1620
#define CS_VREDRAW
Definition: winuser.h:658
#define CreateWindowEx
Definition: winuser.h:5755
#define MF_BYCOMMAND
Definition: winuser.h:202
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IDCANCEL
Definition: winuser.h:831
#define IMAGE_ICON
Definition: winuser.h:212
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1611
#define WM_COMMAND
Definition: winuser.h:1740
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define MF_CHECKED
Definition: winuser.h:132
#define WM_INITDIALOG
Definition: winuser.h:1739
#define PostThreadMessage
Definition: winuser.h:5833
#define MF_UNCHECKED
Definition: winuser.h:204
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:830
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define CreateWindow
Definition: winuser.h:5754
#define GetMessage
Definition: winuser.h:5790
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define RegisterClassEx
Definition: winuser.h:5837
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define MF_ENABLED
Definition: winuser.h:128
#define WM_SETFONT
Definition: winuser.h:1650
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define PM_REMOVE
Definition: winuser.h:1196
#define LoadIcon
Definition: winuser.h:5813
BOOL WINAPI UpdateWindow(_In_ HWND)
#define SendMessage
Definition: winuser.h:5843
#define LoadCursor
Definition: winuser.h:5812
#define PeekMessage
Definition: winuser.h:5830
#define LR_SHARED
Definition: winuser.h:1100
#define MB_OK
Definition: winuser.h:790
#define WM_CHAR
Definition: winuser.h:1717
#define GetWindowText
Definition: winuser.h:5798
#define PostMessage
Definition: winuser.h:5832
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadImage
Definition: winuser.h:5815
#define LoadString
Definition: winuser.h:5819
#define MessageBox
Definition: winuser.h:5822
#define MB_ICONSTOP
Definition: winuser.h:803
#define WM_DESTROY
Definition: winuser.h:1609
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define SetWindowText
Definition: winuser.h:5857
#define DispatchMessage
Definition: winuser.h:5765
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define SystemParametersInfo
Definition: winuser.h:5858
#define TranslateAccelerator
Definition: winuser.h:5860
BOOL WINAPI DestroyWindow(_In_ HWND)
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
#define LoadAccelerators
Definition: winuser.h:5810
HMENU WINAPI GetMenu(_In_ HWND)
#define DialogBox
Definition: winuser.h:5761
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define MF_GRAYED
Definition: winuser.h:129
#define EN_CHANGE
Definition: winuser.h:2022
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323
char TCHAR
Definition: xmlstorage.h:189
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcslen
Definition: xmlstorage.h:198
unsigned char BYTE
Definition: xxhash.c:193