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 | int CALLBACK WinMain(HINSTANCE Instance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
WNDCLASS wc;
ATOM atom;
RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
DWORD style = WS_OVERLAPPEDWINDOW ;
DWORD exstyle = WS_EX_APPWINDOW | WS_EX_LAYERED;
HWND window;
HDC dc;
/* Win32 */
memset(&wc, 0, sizeof(wc));
wc.lpfnWndProc = Win32MainWindowCallback;
wc.hInstance = Instance;
wc.hCursor = LoadCursor(NULL,MAKEINTRESOURCE(IDC_POINTER));
wc.lpszClassName = "WindowClass";
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wc.hIcon = LoadIcon(Instance, MAKEINTRESOURCE(IDI_ICON1)); // Make sure to pass instance of app
atom = RegisterClass(&wc);
AdjustWindowRectEx(&rect, style, FALSE, exstyle);
window = CreateWindowEx(exstyle, wc.lpszClassName, "Win32 programming",
style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top,
NULL, NULL, wc.hInstance, NULL);
int aElements[2] = { COLOR_WINDOW, COLOR_ACTIVECAPTION };
DWORD aOldColors[2];
DWORD aNewColors[2];
aOldColors[0] = GetSysColor(aElements[0]);
aOldColors[1] = GetSysColor(aElements[1]);
aNewColors[0] = RGB(0x80, 0x80, 0x80); // light gray
aNewColors[1] = RGB(0x80, 0x00, 0x80); // dark purple
SetSysColors(2, aElements, aNewColors);
dc = GetDC(window);
if (window) {
ShowWindow(window, SW_SHOWDEFAULT);
Win32ResizeDIBSection(&GlobalBackBuffer, 1920, 1080);
memset(GlobalBackBuffer.Memory, 60, GlobalBackBuffer.BytesPerPixel*GlobalBackBuffer.Height*GlobalBackBuffer.Width);
while (GlobalRunning)
{
MSG Message;
while(PeekMessage(&Message, 0, 0, 0, PM_REMOVE)) {
if (Message.message == WM_QUIT) {
GlobalRunning = false;
}
switch (Message.message) {
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP: {
uint32 VKCode = (uint32)Message.wParam;
// NOTE: Since we are comparing WasDown to IsDown,
// we MUST use == or != to convert these bit tests to actual
// 0 or 1 values.
bool WasDown = ((Message.lParam & (1 << 30)) != 0);
bool IsDown = ((Message.lParam & (1 << 31)) == 0);
if (WasDown != IsDown) {
if (VKCode == 'W') {
}
else if (VKCode == 'A') {
}
else if (VKCode == 'S') {
}
else if (VKCode == 'D') {
}
else if (VKCode == 'Q') {
}
else if (VKCode == 'E') {
}
else if (VKCode == VK_UP) {
}
else if (VKCode == VK_LEFT) {
}
else if (VKCode == VK_RIGHT) {
}
else if (VKCode == VK_DOWN) {
}
else if (VKCode == VK_ESCAPE) {
GlobalRunning = false;
}
else if (VKCode == VK_SPACE) {
}
if (IsDown) {
bool32 AltKeyWasDown = (Message.lParam & (1 << 29));
if ((VKCode == VK_F4) && AltKeyWasDown) {
GlobalRunning = false;
}
if ((VKCode == VK_RETURN) && AltKeyWasDown) {
if (Message.hwnd) {
ToggleFullscreen(Message.hwnd);
}
}
}
}
} break;
default: {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
}
}
}
SetSysColors(2, aElements, aOldColors);
ReleaseDC(window, dc);
}
UnregisterClass(wc.lpszClassName, wc.hInstance);
return 0;
}
|