-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseWindow.cpp
41 lines (37 loc) · 1.16 KB
/
BaseWindow.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
#include "BaseWindow.h"
BaseWindow::BaseWindow(HINSTANCE hInstance) : hInstance(hInstance), hWnd(0)
{
}
BaseWindow::~BaseWindow()
{
SetWindowLongPtr(hWnd, 0, 0);
if (hWnd)
DestroyWindow(hWnd);
}
HWND BaseWindow::GetHWND()
{
return hWnd;
}
void BaseWindow::RegisterClass(HINSTANCE hInstance, const char *classname, HBRUSH background, WORD iconname)
{
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(wc);
wc.cbWndExtra = sizeof(BaseWindow *);
wc.hbrBackground = background;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hIcon = iconname ? LoadIcon(hInstance, MAKEINTRESOURCE(iconname)) : 0;
wc.hIconSm = wc.hIcon;
wc.hInstance = hInstance;
wc.lpfnWndProc = sWndProc;
wc.lpszClassName = classname;
::RegisterClassEx(&wc);
}
LRESULT BaseWindow::sWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == WM_NCCREATE)
SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(reinterpret_cast<CREATESTRUCT *>(lParam)->lpCreateParams));
BaseWindow *window = reinterpret_cast<BaseWindow *>(GetWindowLongPtr(hWnd, 0));
if (window)
return window->WndProc(hWnd, Msg, wParam, lParam);
return DefWindowProc(hWnd, Msg, wParam, lParam);
}