-
Notifications
You must be signed in to change notification settings - Fork 2
/
TerminalEmulator.c
189 lines (167 loc) · 6.55 KB
/
TerminalEmulator.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*------------------------------------------------------------------------------
-- SOURCE FILE: TerminalEmulator.c - Contains the WinMain() and WinProc()
-- functions for the Intelligent Terminal
-- Emulator.
--
-- PROGRAM: Advanced Terminal Emulator Pro
--
-- FUNCTIONS:
-- int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int)
-- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
--
--
-- DATE: Oct 18, 2010
--
-- REVISIONS: (Date and Description)
--
-- DESIGNER: Dean Morin
--
-- PROGRAMMER: Dean Morin
--
-- NOTES:
-- The main entry point for the program.
------------------------------------------------------------------------------*/
#include "TerminalEmulator.h"
/*------------------------------------------------------------------------------
-- FUNCTION: WinMain
--
-- DATE: Oct 18, 2010
--
-- REVISIONS: (Date and Description)
--
-- 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("TerminalEmulator");
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("Advanced Terminal Emulator Pro (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: (Date and Description)
--
-- 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. For the messages WW_CREATE,
-- WM_SIZE, and WM_PAINT, the logic is contained in this function.
-- For other messages, the majority of the logic is in
-- Application.c. Currently, WM_PAINT will update the screen with
-- black text only.
------------------------------------------------------------------------------*/
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_SETFOCUS:
CreateCaret(hWnd, NULL, CHAR_WIDTH, CHAR_HEIGHT);
SetCaretPos(X_POS, Y_POS);
ShowCaret(hWnd);
return 0;
case WM_KILLFOCUS:
HideCaret(hWnd);
DestroyCaret();
return 0;
case WM_KEYDOWN:
if (pwd->bConnected) {
// check if it's a special virtual-key that we need to handle
if ((wParam >= VK_END && wParam <= VK_DOWN) ||
(wParam >= VK_F1 && wParam <= VK_F4)) {
if (!ProcessWrite(hWnd, wParam, TRUE)) {
DISPLAY_ERROR("Error writing to serial port");
}
}
}
return 0;
case WM_CHAR:
if (pwd->bConnected) {
if (!ProcessWrite(hWnd, wParam, FALSE)) {
DISPLAY_ERROR("Error writing to serial port");
}
}
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);
}
}