-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAC2DTest.cpp
More file actions
160 lines (130 loc) · 3.4 KB
/
AC2DTest.cpp
File metadata and controls
160 lines (130 loc) · 3.4 KB
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
// AC2DTest.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "AC2DTest.h"
#include "cClient.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
cClient *Client;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// Show command line parameters
if (lpCmdLine[0] == 0) {
MessageBox(NULL, "No command line parameters were supplied", "Error!", MB_OK);
}
else {
MessageBox(NULL, lpCmdLine, "Commmand Line Parameters:", MB_OK);
}
hInst = hInstance;
// _CrtSetDbgFlag ( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF );
// Initialize global strings
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 64;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_AC2DTEST);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCTSTR)IDC_AC2DTEST;
wcex.lpszClassName = "AC2D";
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
RegisterClassEx(&wcex);
HWND hWnd = CreateWindow("AC2D", "AC2D", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
srand((DWORD) time(0));
if (!hWnd)
return FALSE;
//Now initialize our Client...
Client = new cClient(hInst, hWnd);
//Launch client
Client->Start();
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_AC2DTEST);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Client->Stop();
delete Client;
//_CrtDumpMemoryLeaks();
return (int) msg.wParam;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
if (Client)
{
while (!Client->Initted())
Sleep(1);
Client->WindowsMessage(message, wParam, lParam);
}
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_SIZE:
Client->Resize();
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void _ODS( const char *fmt, ... )
{
va_list valist;
va_start( valist, fmt );
char szText[2048];
memset( szText, 0, 2048 );
_vsnprintf( szText, 2048, fmt, valist );
OutputDebugString( szText );
va_end( valist );
}