|
@@ -122,9 +122,11 @@ bool Win32Window::CreateAndShow(const std::wstring& title,
|
|
|
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
|
|
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
|
|
|
nullptr, nullptr, GetModuleHandle(nullptr), this);
|
|
nullptr, nullptr, GetModuleHandle(nullptr), this);
|
|
|
|
|
|
|
|
- OnCreate();
|
|
|
|
|
|
|
+ if (!window) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return window != nullptr;
|
|
|
|
|
|
|
+ return OnCreate();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
// static
|
|
@@ -152,13 +154,6 @@ Win32Window::MessageHandler(HWND hwnd,
|
|
|
UINT const message,
|
|
UINT const message,
|
|
|
WPARAM const wparam,
|
|
WPARAM const wparam,
|
|
|
LPARAM const lparam) noexcept {
|
|
LPARAM const lparam) noexcept {
|
|
|
- auto window =
|
|
|
|
|
- reinterpret_cast<Win32Window*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
|
|
|
|
-
|
|
|
|
|
- if (window == nullptr) {
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
switch (message) {
|
|
switch (message) {
|
|
|
case WM_DESTROY:
|
|
case WM_DESTROY:
|
|
|
window_handle_ = nullptr;
|
|
window_handle_ = nullptr;
|
|
@@ -178,26 +173,21 @@ Win32Window::MessageHandler(HWND hwnd,
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- case WM_SIZE:
|
|
|
|
|
- RECT rect;
|
|
|
|
|
- GetClientRect(hwnd, &rect);
|
|
|
|
|
|
|
+ case WM_SIZE: {
|
|
|
|
|
+ RECT rect = GetClientArea();
|
|
|
if (child_content_ != nullptr) {
|
|
if (child_content_ != nullptr) {
|
|
|
// Size and position the child window.
|
|
// Size and position the child window.
|
|
|
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
|
|
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
|
|
|
rect.bottom - rect.top, TRUE);
|
|
rect.bottom - rect.top, TRUE);
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
case WM_ACTIVATE:
|
|
case WM_ACTIVATE:
|
|
|
if (child_content_ != nullptr) {
|
|
if (child_content_ != nullptr) {
|
|
|
SetFocus(child_content_);
|
|
SetFocus(child_content_);
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
-
|
|
|
|
|
- // Messages that are directly forwarded to embedding.
|
|
|
|
|
- case WM_FONTCHANGE:
|
|
|
|
|
- SendMessage(child_content_, WM_FONTCHANGE, NULL, NULL);
|
|
|
|
|
- return 0;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(window_handle_, message, wparam, lparam);
|
|
return DefWindowProc(window_handle_, message, wparam, lparam);
|
|
@@ -223,8 +213,7 @@ Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
|
|
|
void Win32Window::SetChildContent(HWND content) {
|
|
void Win32Window::SetChildContent(HWND content) {
|
|
|
child_content_ = content;
|
|
child_content_ = content;
|
|
|
SetParent(content, window_handle_);
|
|
SetParent(content, window_handle_);
|
|
|
- RECT frame;
|
|
|
|
|
- GetClientRect(window_handle_, &frame);
|
|
|
|
|
|
|
+ RECT frame = GetClientArea();
|
|
|
|
|
|
|
|
MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
|
|
MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
|
|
|
frame.bottom - frame.top, true);
|
|
frame.bottom - frame.top, true);
|
|
@@ -232,6 +221,12 @@ void Win32Window::SetChildContent(HWND content) {
|
|
|
SetFocus(child_content_);
|
|
SetFocus(child_content_);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+RECT Win32Window::GetClientArea() {
|
|
|
|
|
+ RECT frame;
|
|
|
|
|
+ GetClientRect(window_handle_, &frame);
|
|
|
|
|
+ return frame;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
HWND Win32Window::GetHandle() {
|
|
HWND Win32Window::GetHandle() {
|
|
|
return window_handle_;
|
|
return window_handle_;
|
|
|
}
|
|
}
|
|
@@ -240,8 +235,9 @@ void Win32Window::SetQuitOnClose(bool quit_on_close) {
|
|
|
quit_on_close_ = quit_on_close;
|
|
quit_on_close_ = quit_on_close;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Win32Window::OnCreate() {
|
|
|
|
|
|
|
+bool Win32Window::OnCreate() {
|
|
|
// No-op; provided for subclasses.
|
|
// No-op; provided for subclasses.
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Win32Window::OnDestroy() {
|
|
void Win32Window::OnDestroy() {
|