/
WndProc.cpp
73 lines (64 loc) · 2.21 KB
/
WndProc.cpp
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
#include "Main.h"
#include "MenuItems.h"
#include "Transmit.h"
#include "Receive.h"
#include "Buffer.h"
/************************************************************************
* SOURCE FILE : WndProc.cpp
* PROGRAM : Dumb Terminal
* FUNCTION : LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
* HWND hwnd - A handle to the window
* UINT Message - The message to handle
* WPARAM wParam - wParam parameters
* LPARAM lParam - lParam parameters
* RETURNS : LRESULT
* DATE : September 27, 2010a
* REVISIONS : None
* DESIGNER : Nick Huber
* PROGRAMMER : Nick Huber
* NOTES :
*
* The WndProc for the terminal program, all messages are handled here
*************************************************************************/
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
PCPARAMS cp;
HDC hdc;
PAINTSTRUCT ps;
switch (Message)
{
case WM_COMMAND:
cp = (PCPARAMS)GetWindowLongPtr(hwnd, 0);
if (cp->connectMode) {
MessageBox(NULL, TEXT("Unable to change settings while in Connect Mode, press ESC to return to Command Mode"), TEXT(""), MB_OK);
return 0;
}
MainMenu(hwnd, LOWORD (wParam), cp);
return 0;
case WM_CHAR:
cp = (PCPARAMS) GetWindowLongPtr(hwnd,0);
if (cp->connectMode) {
if(VK_ESCAPE == wParam) {
SetWindowText(hwnd, TEXT("Dumb Terminal - Command Mode"));
CloseHandle(cp->hComm);
cp->connectMode = FALSE;
return 0;
}
if(!Transmit(wParam, cp)) {
MessageBox (NULL, TEXT("Error sending data"), TEXT(""), MB_OK);
return 0;
}
}
return 0;
case WM_PAINT:
cp = (PCPARAMS) GetWindowLongPtr(hwnd,0);
hdc = BeginPaint(hwnd, &ps);
DisplayData(hwnd, hdc, cp);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
cp = (PCPARAMS) GetWindowLongPtr(hwnd,0);
PostQuitMessage (0);
return 0;
}
return DefWindowProc(hwnd, Message, wParam, lParam);
}