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
|
internal LRESULT CALLBACK win32_window_proc(HWND handle, UINT messages, WPARAM wparam,
LPARAM lparam)
{
switch (messages) {
case WM_DESTROY:
Win32Running = false;
break;
case WM_PAINT: {
} break;
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP: {
// TODO: ...
} break;
}
return DefWindowProcA(handle, messages, wparam, lparam);
}
internal HWND win32_create_window(HINSTANCE instance, int height, int width, int display_x,
int display_y, const char *window_name)
{
Win32Running = true;
WNDCLASS window_class = {0};
// TODO(nasr): check if CS_OWNDC CS_HREDRAW CS_VEREDRAW still matter
window_class.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
window_class.lpfnWndProc = win32_window_proc;
window_class.hInstance = instance;
window_class.lpszClassName = window_name;
HWND window_handle = {};
if (RegisterClass(&window_class)) {
window_handle = CreateWindowEx(0, window_class.lpszClassName, window_name,
WS_OVERLAPPEDWINDOW | WS_VISIBLE, height, width, display_x,
display_y, 0, 0, instance, 0);
}
Assert(window_handle);
ShowWindow(window_handle, true);
MSG message = {};
while (Win32Running) {
Log("status : %d", Win32Running);
b32 result = GetMessage(&message, 0, 0, 0);
if (result > 0) {
TranslateMessage(&message);
DispatchMessage(&message);
} else {
break;
}
} // cleanup get's handled by the OS, so there is no need worry about that
return window_handle;
}
|