-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleWindowWin32.cpp
63 lines (51 loc) · 1.63 KB
/
simpleWindowWin32.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
// STL
#include <string_view>
// OS
#include <Windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR pCmdLine, int nCmdShow) {
int width = 640;
int height = 480;
constexpr auto cTitle = std::string_view{"HelloWorld!"};
WNDCLASS windowClass = {};
windowClass.lpfnWndProc = WindowProc;
windowClass.hInstance = hInstance;
windowClass.lpszClassName = cTitle.data();
RegisterClass(&windowClass);
HWND hwnd = CreateWindowEx(0,
cTitle.data(),
cTitle.data(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
width,
height,
nullptr, // Parent window
nullptr, // Menu
hInstance, // Instance handle
nullptr // Additional application data
);
if(hwnd == nullptr) {
OutputDebugString("Can not create win32 Window");
return 0;
}
ShowWindow(hwnd, nCmdShow);
MSG msg = {};
while(GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
case WM_DESTROY: {
PostQuitMessage(0);
return 0;
}
case WM_PAINT: {
return 0;
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}