-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoreWindow.cpp
More file actions
91 lines (74 loc) · 2.45 KB
/
Copy pathCoreWindow.cpp
File metadata and controls
91 lines (74 loc) · 2.45 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
#include "CoreWindow.h"
CoreWindow* CoreWindow::s_instance = nullptr;
CoreWindow::MessageHandler CoreWindow::m_CreateEventHandler = nullptr;
DUMP_TYPE CoreWindow::g_dumpType = DUMP_TYPE::DUNP_TYPE_MINI;
LRESULT CoreWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
CoreWindow* self = nullptr;
if (message == WM_NCCREATE)
{
// 윈도우 생성 시 초기화
CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lParam);
self = static_cast<CoreWindow*>(cs->lpCreateParams);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(self));
}
else
{
self = reinterpret_cast<CoreWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
}
if (self && self->m_desc.messageInterceptor)
{
if (const std::optional<LRESULT> result =
self->m_desc.messageInterceptor(hWnd, message, wParam, lParam))
{
return *result;
}
}
if (message == WM_CREATE && m_CreateEventHandler)
{
m_CreateEventHandler(hWnd, wParam, lParam);
}
if (self)
{
return self->HandleMessage(hWnd, message, wParam, lParam);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
LRESULT CoreWindow::HandleMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
auto it = m_handlers.find(message);
if (it != m_handlers.end())
{
return it->second(hWnd, wParam, lParam);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
void CoreWindow::EnsureSwapChainCompatibleStyle()
{
if (!m_hWnd)
{
return;
}
constexpr LONG requiredStyleMask = WS_POPUP | WS_BORDER | WS_CAPTION | WS_SYSMENU |
WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME;
LONG currentStyle = GetWindowLong(m_hWnd, GWL_STYLE);
LONG currentExStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);
bool styleUpdated = false;
if ((currentStyle & requiredStyleMask) == 0)
{
currentStyle |= WS_OVERLAPPEDWINDOW;
styleUpdated = true;
}
if ((currentExStyle & WS_EX_TOPMOST) != 0)
{
currentExStyle &= ~WS_EX_TOPMOST;
styleUpdated = true;
}
if (styleUpdated)
{
SetWindowLong(m_hWnd, GWL_STYLE, currentStyle);
SetWindowLong(m_hWnd, GWL_EXSTYLE, currentExStyle);
SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
}
}