-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.c
170 lines (149 loc) · 5.84 KB
/
Main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*------------------------------------------------------------------------------
-- SOURCE FILE: Main.c Contains the WinMain() and WinProc() functions
-- for the program.
--
-- PROGRAM: Dean and the Rockets' Wireless Protocol Testing and Evaluation
-- Facilitator
--
-- FUNCTIONS:
-- int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int)
-- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
--
--
-- DATE: Nov 24, 2010
--
-- REVISIONS:
--
-- DESIGNER: Dean Morin
--
-- PROGRAMMER: Dean Morin
--
-- NOTES: The main entry point for the program.
------------------------------------------------------------------------------*/
#include "Main.h"
/*------------------------------------------------------------------------------
-- FUNCTION: WinMain
--
-- DATE: Nov 24, 2010
--
-- REVISIONS: Dec 02, 2010 - Added dialog boxes
--
-- DESIGNER: Dean Morin
--
-- PROGRAMMER: Dean Morin
--
-- INTERFACE: WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
-- hInstance - a handle to the current instance
-- hPrevInstanc - a handle to the previous instance
-- szCmdLine - the command line arguments
-- iCmdShow - specifies how the window should
-- be shown
--
-- RETURNS: If the function succeeds, terminating when it receives a WM_QUIT
-- message, it should return the exit value contained in that
-- message's wParam parameter. If the function terminates before
-- entering the message loop, it should return zero.
--
-- NOTES: WinMain is the conventional name used for the application entry
-- point. The standard message loop has been modified to poll the
-- an open serial port if there are no messages on the queue.
------------------------------------------------------------------------------*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow) {
static TCHAR szAppName[] = TEXT("Main");
HWND hWnd = NULL;
MSG msg = {0};
WNDCLASSEX wndclass = {0};
PWNDDATA pwd = NULL;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(PWNDDATA);
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = TEXT("MYMENU");
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2));
if (!RegisterClassEx(&wndclass)) {
MessageBox(NULL, TEXT("Upgrade your OS! Seriously!"),
szAppName, MB_ICONERROR);
return 0;
}
hWnd = CreateWindow(szAppName,
WND_CAPTION,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
| WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
pwd = (PWNDDATA) GetWindowLongPtr(hWnd, 0);
pwd->hDlgStats = CreateDialog (hInstance, TEXT("Statistics"), hWnd, Stats);
pwd->hDlgDebug = CreateDialog (hInstance, TEXT("Debug"), hWnd, Debug);
SetWindowLongPtr(hWnd, 0, (LONG_PTR) pwd);
while (GetMessage(&msg, NULL, 0, 0)) {
if (pwd->hDlgStats == 0 || !IsDialogMessage (pwd->hDlgStats, &msg)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
return msg.wParam;
}
/*------------------------------------------------------------------------------
-- FUNCTION: WndProc
--
-- DATE: Nov 24, 2010
--
-- REVISIONS: Dec 02, 2010 - Added buffer messages
--
-- DESIGNER: Dean Morin
--
-- PROGRAMMER: Dean Morin
--
-- INTERFACE: CALLBACK WndProc(HWND hWnd, UNIT message,
-- WPARAM wParam, LPARAM)
-- hWnd - the handle to the window
-- message - the message
-- wParam - contents vary based on the message
lParam - contents vary based on the message
--
-- RETURNS: The return value is the result of the message processing and
-- depends on the message sent.
--
-- NOTES: The standard WndProc function.
------------------------------------------------------------------------------*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PWNDDATA pwd = {0};
pwd = (PWNDDATA) GetWindowLongPtr(hWnd, 0);
switch (message) {
case WM_CREATE:
InitTerminal(hWnd);
return 0;
case WM_STAT:
UpdateStatStruct(hWnd, wParam, lParam);
return 0;
case WM_PAINT:
Paint(hWnd);
return 0;
case WM_COMMAND:
PerformMenuAction(hWnd, wParam);
return 0;
case WM_FILLFTPBUF:
ReadFromFile(hWnd);
return 0;
case WM_EMPTYPTFBUF:
WriteToFile(hWnd);
return 0;
case WM_DESTROY:
Disconnect(hWnd);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}