-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
117 lines (86 loc) · 1.87 KB
/
window.cpp
File metadata and controls
117 lines (86 loc) · 1.87 KB
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
#include "window.hpp"
Window* window = nullptr;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_CREATE:
// Evenement lors de la création de la fenêtre
window->setHWND(hwnd);
window->onCreate();
break;
case WM_DESTROY:
// Evenement lors de la déstruction de la fenêtre
window->onDestroy();
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}
bool Window::init()
{
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
m_szClassname = L"DirectX-Engine";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW);
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
wc.hIconSm = wc.hIcon;
wc.hInstance = nullptr;
wc.lpszClassName = m_szClassname;
wc.lpszMenuName = nullptr;
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
if (!RegisterClassEx(&wc))
return false;
if (!window)
window = this;
m_hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, m_szClassname, L"DirectX Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, nullptr, nullptr, nullptr, nullptr);
if (!m_hwnd)
return false;
ShowWindow(m_hwnd, SW_SHOW);
UpdateWindow(m_hwnd);
m_isRun = true;
return true;
}
bool Window::broadcast()
{
MSG msg;
window->onUpdate();
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Sleep(0);
return false;
}
bool Window::release()
{
if (DestroyWindow(m_hwnd))
return false;
return true;
}
bool Window::isRun()
{
return m_isRun;
}
RECT Window::getClientWindowRect()
{
RECT rc;
GetClientRect(this->m_hwnd, &rc);
return rc;
}
void Window::setHWND(HWND hwnd)
{
this->m_hwnd = hwnd;
}
void Window::onDestroy()
{
m_isRun = false;
}