-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
175 lines (152 loc) · 2.81 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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "Window.h"
Window::Window() = default;
__int64 _stdcall WndProc(HWND hWnd, unsigned int message, unsigned __int64 wParam, __int64 lParam)
{
switch (message)
{
case WM_CREATE:
{
Window* window = (Window*)((LPCREATESTRUCTW)lParam)->lpCreateParams;
SetWindowLongPtrW(hWnd, (-21), (__int64)window);
window->SetHWND(hWnd);
if (window)
{
window->OnCreate();
}
break;
}
case WM_DESTROY:
{
Window* window = (Window*)GetWindowLongPtrW(hWnd, -21);
if (window)
{
window->OnDestroy();
}
PostQuitMessage(0);
break;
}
case WM_SETFOCUS:
{
Window* window = (Window*)GetWindowLongPtrW(hWnd, -21);
if (window)
{
window->OnFocus();
}
break;
}
case WM_KILLFOCUS:
{
Window* window = (Window*)GetWindowLongPtrW(hWnd, -21);
if (window)
{
window->OnUnFocus();
}
break;
}
case WM_SIZE:
{
Window* window = (Window*)GetWindowLongPtrW(hWnd, -21);
if (window)
{
window->OnResize();
}
break;
}
case WM_GETMINMAXINFO:
{
LPMINMAXINFO minmax = (LPMINMAXINFO)lParam;
minmax->ptMinTrackSize.x = 800;
minmax->ptMinTrackSize.y = 600;
break;
}
}
return DefWindowProcW(hWnd, message, wParam, lParam);
}
bool Window::Initialize()
{
WNDCLASSEXW wc{};
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEXW);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)0x0005U;
wc.hCursor = LoadCursor(0, ((LPWSTR)(0x7F00)));
wc.hIcon = LoadIcon(0, ((LPWSTR)(0x7F00)));
wc.hIconSm = LoadIcon(0, ((LPWSTR)(0x7F00)));
wc.hInstance = 0;
wc.lpszClassName = L"CXWindow";
wc.lpszMenuName = 0;
wc.style = 0x0003U;
wc.lpfnWndProc = &WndProc;
if (!RegisterClassExW(&wc))
{
return false;
}
m_hWnd = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, L"CXWindow", L"DirectX 11 Game", WS_OVERLAPPEDWINDOW , ((int)0x80000000), ((int)0x80000000), 1280, 720, 0, 0, 0, this);
if (m_hWnd == 0)
{
return false;
}
ShowWindow(m_hWnd, 0x5);
UpdateWindow(m_hWnd);
m_isRunning = true;
return true;
}
void Window::Broadcast()
{
tagMSG msg{};
this->OnUpdate();
while (PeekMessageW(&msg, 0, 0x0U, 0x0U, 0x0001U) > 0)
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
bool Window::Release()
{
if (DestroyWindow(m_hWnd) == 0)
{
return true;
}
return false;
}
bool Window::IsRunning() const
{
return m_isRunning;
}
void Window::SetHWND(HWND hwnd)
{
this->m_hWnd = hwnd;
}
RECT Window::GetClient() const
{
tagRECT rc{};
GetClientRect(this->m_hWnd, &rc);
return rc;
}
void Window::OnCreate()
{
}
void Window::OnDestroy()
{
m_isRunning = false;
}
void Window::OnUpdate()
{
}
void Window::OnFocus()
{
}
void Window::OnUnFocus()
{
}
void Window::OnResize()
{
}
RECT Window::GetPhysicalScreensize()
{
RECT rc{};
rc.right = GetSystemMetrics(SM_CXSCREEN);
rc.bottom = GetSystemMetrics(SM_CYSCREEN);
return rc;
}
Window::~Window() = default;