-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWindow.h
74 lines (61 loc) · 1.56 KB
/
Window.h
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
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
HWND CreateWnd(const CREATESTRUCT& cs, const class Window* wnd);
template<class T>
class WindowManager
{
public:
static void GetWndClass(WNDCLASS& cs)
{
cs.lpszClassName = T::ClassName();
T::GetWndClass(cs);
}
static ATOM Register()
{
WNDCLASS wc = {};
GetWndClass(wc);
return ::RegisterClass(&wc);
}
static void GetCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = T::ClassName();
T::GetCreateWindow(cs);
}
static T* Create(LPVOID lpCreateParams = nullptr)
{
CREATESTRUCT cs = {};
cs.lpCreateParams = lpCreateParams;
GetCreateWindow(cs);
return Create(cs);
}
static T* Create(const CREATESTRUCT& cs)
{
T* self = new T();
if (self && CreateWnd(cs, self) != NULL)
return self;
else
{
delete self;
return nullptr;
}
}
};
class Window
{
public:
HWND GetHWND() const { return m_hWnd; }
operator HWND() const { return m_hWnd; }
protected:
static void GetCreateWindow(CREATESTRUCT& cs);
static void GetWndClass(WNDCLASS& wc);
virtual ~Window() = default;
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual void OnDraw(const PAINTSTRUCT* pps) const { }
private:
void OnPaint();
void OnPrintClient(HDC hdc);
static LRESULT CALLBACK s_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND m_hWnd = NULL;
};