| 150 | } |
| 151 | |
| 152 | LRESULT |
| 153 | Win32Window::MessageHandler(HWND hwnd, |
| 154 | UINT const message, |
| 155 | WPARAM const wparam, |
| 156 | LPARAM const lparam) noexcept { |
| 157 | switch (message) { |
| 158 | case WM_DESTROY: |
| 159 | window_handle_ = nullptr; |
| 160 | Destroy(); |
| 161 | if (quit_on_close_) { |
| 162 | PostQuitMessage(0); |
| 163 | } |
| 164 | return 0; |
| 165 | |
| 166 | case WM_DPICHANGED: { |
| 167 | auto newRectSize = reinterpret_cast<RECT*>(lparam); |
| 168 | LONG newWidth = newRectSize->right - newRectSize->left; |
| 169 | LONG newHeight = newRectSize->bottom - newRectSize->top; |
| 170 | |
| 171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, |
| 172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | case WM_SIZE: { |
| 177 | RECT rect = GetClientArea(); |
| 178 | if (child_content_ != nullptr) { |
| 179 | // Size and position the child window. |
| 180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, |
| 181 | rect.bottom - rect.top, TRUE); |
| 182 | } |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | case WM_ACTIVATE: |
| 187 | if (child_content_ != nullptr) { |
| 188 | SetFocus(child_content_); |
| 189 | } |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | return DefWindowProc(window_handle_, message, wparam, lparam); |
| 194 | } |
| 195 | |
| 196 | void Win32Window::Destroy() { |
| 197 | OnDestroy(); |