-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.c
157 lines (140 loc) · 5.47 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
/*------------------------------------------------------------------------------
-- SOURCE FILE: Main.c - Contains the WinMain() and WinProc()
-- functions for the Intelligent Terminal
-- Emulator.
--
-- PROGRAM: RFID Reader - Enterprise Edition
--
-- FUNCTIONS:
-- int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int)
-- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
--
--
-- DATE: Oct 18, 2010
--
-- REVISIONS: Nov 06, 2010
-- Removed any code not needed for the RFID reader.
-- (this file was copied from the Advanced Terminal Emulator Pro).
--
-- DESIGNER: Dean Morin
--
-- PROGRAMMER: Dean Morin
--
-- NOTES:
-- The main entry point for the program.
------------------------------------------------------------------------------*/
#include "Main.h"
/*------------------------------------------------------------------------------
-- FUNCTION: WinMain
--
-- DATE: Oct 18, 2010
--
-- REVISIONS: Nov 06, 2010
-- Changed the window name.
--
-- DESIGNER: Dean Morin
--
-- PROGRAMMER: Dean Morin
--
-- INTERFACE: int 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.o
------------------------------------------------------------------------------*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow) {
static TCHAR szAppName[] = TEXT("Main");
HWND hWnd = NULL;
MSG msg = {0};
WNDCLASS wndclass = {0};
PWNDDATA pwd = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(PWNDDATA);
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = TEXT("MYMENU");
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass)) {
MessageBox(NULL, TEXT("Upgrade your OS! Seriously!"),
szAppName, MB_ICONERROR);
return 0;
}
hWnd = CreateWindow(szAppName,
TEXT("RFID Reader - Enterprise Edition (Trial Expired)"),
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);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
/*------------------------------------------------------------------------------
-- FUNCTION: WndProc
--
-- DATE: Oct 18, 2010
--
-- REVISIONS: Nov 06, 2010
-- Removed message handling that doesn't apply to this program.
--
-- DESIGNER: Dean Morin
--
-- PROGRAMMER: Dean Morin
--
-- INTERFACE: LRESULT 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_PAINT:
Paint(hWnd);
return 0;
case WM_COMMAND:
PerformMenuAction(hWnd, wParam);
return 0;
case WM_DESTROY:
Disconnect(hWnd);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}