This repository was archived by the owner on Oct 4, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathOSWindow.cpp
More file actions
151 lines (114 loc) · 3.86 KB
/
Copy pathOSWindow.cpp
File metadata and controls
151 lines (114 loc) · 3.86 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
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
#include "defs.h"
#include "OSWindow.h"
Result::Code Win32Window::HandleEvents()
{
MSG msg;
while (PeekMessageW(&msg, hWindow, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
return Result::Generic;
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return Result::Success;
}
Result::Code Win32Window::GetClientArea(Rect<float> *pOutArea)
{
RECT rcClient;
GetClientRect(hWindow, &rcClient);
pOutArea->x = Range<float>(rcClient.left, rcClient.right);
pOutArea->y = Range<float>(rcClient.top, rcClient.bottom);
return Result::Success;
}
Result::Code Win32Window::GetWindowArea(Rect<float> *pOutArea)
{
RECT rcWindow;
GetWindowRect(hWindow, &rcWindow);
pOutArea->x = Range<float>(rcWindow.left, rcWindow.right);
pOutArea->y = Range<float>(rcWindow.top, rcWindow.bottom);
return Result::Success;
}
HWND Win32Window::GetAPIHandle()
{
return hWindow;
}
Result::Code Win32Window::SetClientArea(const Rect<float> *pArea)
{
RECT rcWindow, rcClient;
GetWindowRect(hWindow, &rcWindow);
GetClientRect(hWindow, &rcClient);
unsigned int uWindowWidth = rcWindow.right - rcWindow.left,
uClientWidth = rcClient.right - rcClient.left;
unsigned int uWindowHeight = rcWindow.bottom - rcWindow.top,
uClientHeight = rcClient.bottom - rcClient.top;
SetWindowPos(hWindow, HWND_TOP, pArea->x.min, pArea->y.min,
pArea->x.Length() + (uWindowWidth - uClientWidth),
pArea->y.Length() + (uWindowHeight - uClientHeight), SWP_NOACTIVATE | SWP_NOZORDER);
return Result::Success;
}
Result::Code Win32Window::SetWindowArea(const Rect<float> *pArea)
{
SetWindowPos(hWindow, HWND_TOP, pArea->x.min, pArea->y.min, pArea->x.Length(), pArea->y.Length(), SWP_NOACTIVATE | SWP_NOZORDER);
return Result::Success;
}
Result::Code Win32Window::Show(bool bShow)
{
if (bShow && !bVisible)
{
ShowWindow(hWindow, SW_SHOWNORMAL);
UpdateWindow(hWindow);
bVisible = true;
}
else if (!bShow && bVisible)
{
ShowWindow(hWindow, SW_HIDE);
bVisible = false;
}
return Result::Success;
}
long *__stdcall wMM7DefaultWinProc(HWND, unsigned int, unsigned int, long *);
Result::Code Win32Window::Initialize(const wchar_t *pWindowClassName, const wchar_t *pWindowCaptionName, unsigned int uCreationParams)
{
lstrcpyW(pClassName, pWindowClassName);
lstrcpyW(pWindowName, pWindowCaptionName);
uCreationFlags = uCreationParams;
hWindow = FindWindowW(pClassName, 0);
if (hWindow)
{
if (IsIconic(hWindow))
ShowWindow(hWindow, SW_RESTORE);
SetWindowLongPtrW(hWindow, GWL_STYLE, (LONG_PTR)(WS_OVERLAPPEDWINDOW | WS_VISIBLE));
ShowWindow(hWindow, SW_SHOWNORMAL);
UpdateWindow(hWindow);
SetForegroundWindow(GetLastActivePopup(hWindow));
return Result::Generic;
}
wcxw.cbClsExtra = 0;
wcxw.cbSize = sizeof(WNDCLASSEXW);
wcxw.cbWndExtra = 0;
wcxw.hbrBackground = 0;
wcxw.hCursor = LoadCursorW(nullptr, (const wchar_t *)(IDC_ARROW));
wcxw.hIcon = wcxw.hIconSm = LoadIconW(nullptr, (const wchar_t *)(IDI_APPLICATION));
wcxw.hInstance = GetModuleHandleW(nullptr);
wcxw.lpfnWndProc = (WNDPROC)(wMM7DefaultWinProc);
wcxw.lpszClassName = pClassName;
wcxw.lpszMenuName = 0;
wcxw.style = CS_OWNDC;
RegisterClassExW(&wcxw);
if (uCreationParams & WindowCreationParams::Framed)
hWindow = CreateWindowExW(0, pClassName, pWindowName, WS_OVERLAPPEDWINDOW, 0, 0, 1, 1, 0, 0, wcxw.hInstance, this);
else hWindow = CreateWindowExW(0, pClassName, pWindowName, WS_POPUP, 0, 0, 1, 1, 0, 0, wcxw.hInstance, this);
return Result::Success;
}
Result::Code Win32Window::SystemMessageHandler(unsigned int msg, unsigned int wparam, long *lparam)
{
return Result::NotImplemented;
}
Result::Code Win32Window::OnClose()
{
return Result::NotImplemented;
}
Result::Code Win32Window::Close()
{
return Result::NotImplemented;
}