-
Notifications
You must be signed in to change notification settings - Fork 77
/
main.cpp
61 lines (53 loc) · 1.4 KB
/
main.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
#include <windows.h>
enum { id_button1 = 1, id_button2 };
void on_create(HWND hw)
{
// TODO: create two child windows of type button
}
void on_command(HWND hw, int id)
{
// TODO: show message box with text depending on which button was pressed
}
void on_destroy()
{
::PostQuitMessage(0);
}
LRESULT CALLBACK window_proc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_CREATE:
on_create(hw);
return 0;
case WM_COMMAND:
on_command(hw, LOWORD(wp));
return 0;
case WM_DESTROY:
on_destroy();
return 0;
}
return ::DefWindowProc(hw, msg, wp, lp);
}
int register_class(HINSTANCE hi, const char* name)
{
WNDCLASS wc{};
wc.lpfnWndProc = window_proc;
wc.lpszClassName = name;
wc.hInstance = hi;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
wc.hbrBackground = static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH)); // TODO: replace with cyan background
return ::RegisterClass(&wc);
}
int WINAPI WinMain(HINSTANCE hi, HINSTANCE, LPSTR cmd_line, int show_flag)
{
const auto class_name = "NWPClass";
if (!register_class(hi, class_name))
return 0;
::CreateWindow(class_name, "NWP 1", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hi, 0);
MSG msg;
while (::GetMessage(&msg, 0, 0, 0))
::DispatchMessage(&msg);
return msg.wParam;
}