-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
38 lines (31 loc) · 1.04 KB
/
Window.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
#include "Window.h"
Window::Window(int width, int height, const std::wstring& title) {
WNDCLASS wc = {0};
wc.lpfnWndProc = Window::WndProc;
wc.hInstance = GetModuleHandle(nullptr);
wc.lpszClassName = L"WindowClass";
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
RegisterClass(&wc);
hwnd_ = CreateWindowEx(0, L"WindowClass", title.c_str(),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
width, height, nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
ShowWindow(hwnd_, SW_SHOW);
UpdateWindow(hwnd_);
}
Window::~Window() {
DestroyWindow(hwnd_);
}
HWND Window::getHandle() const {
return hwnd_;
}
LRESULT CALLBACK Window::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}