diff --git a/choc/gui/choc_DesktopWindow.h b/choc/gui/choc_DesktopWindow.h index 2a423d2..fa2afea 100644 --- a/choc/gui/choc_DesktopWindow.h +++ b/choc/gui/choc_DesktopWindow.h @@ -627,6 +627,29 @@ struct DesktopWindow::Pimpl namespace choc::ui { +namespace detail +{ + inline COLORREF getDefaultWindowColour() + { + return RGB(25, 25, 25); + } + + inline HBRUSH getDefaultWindowBrush() + { + static HBRUSH brush = CreateSolidBrush(getDefaultWindowColour()); + return brush; + } + + inline void paintWindowBackground(HWND hwnd, HDC dc) + { + if (!dc) + return; + + RECT r{}; + GetClientRect(hwnd, &r); + FillRect(dc, &r, getDefaultWindowBrush()); + } +} static RECT boundsToRect (Bounds b) { @@ -686,6 +709,7 @@ struct WindowClass wc.hIcon = icon; wc.hIconSm = icon; wc.lpfnWndProc = wndProc; + wc.hbrBackground = detail::getDefaultWindowBrush(); classAtom = (LPCWSTR) (uintptr_t) RegisterClassExW (&wc); CHOC_ASSERT (classAtom != 0); @@ -771,9 +795,6 @@ struct DesktopWindow::Pimpl return; setBounds (b); - ShowWindow (hwnd, SW_SHOW); - UpdateWindow (hwnd); - SetFocus (hwnd); } ~Pimpl() @@ -810,8 +831,15 @@ struct DesktopWindow::Pimpl { ShowWindow (hwnd, visible ? SW_SHOW : SW_HIDE); + if (auto child = getFirstChildWindow()) + ShowWindow (child, visible ? SW_SHOW : SW_HIDE); + if (visible) + { InvalidateRect (hwnd, nullptr, 0); + UpdateWindow (hwnd); + SetFocus (hwnd); + } } void setResizable (bool b) @@ -1021,6 +1049,7 @@ struct DesktopWindow::Pimpl { switch (msg) { + case WM_ERASEBKGND: detail::paintWindowBackground (h, reinterpret_cast (wp)); return 1; case WM_NCCREATE: enableNonClientDPIScaling (h); break; case WM_SIZE: if (auto w = getPimpl (h)) w->handleSizeChange(); break; case WM_CLOSE: if (auto w = getPimpl (h)) w->handleClose(); return 0; diff --git a/choc/gui/choc_WebView.h b/choc/gui/choc_WebView.h index fcfdf42..8c0e0da 100644 --- a/choc/gui/choc_WebView.h +++ b/choc/gui/choc_WebView.h @@ -1469,7 +1469,12 @@ struct WebView::Pimpl if (controller->QueryInterface (ICoreWebView2Controller2::getIID(), (void**) controller2.getAddress()) == S_OK && controller2 != nullptr) { - controller2->put_DefaultBackgroundColor ({ 0, 0, 0, 0 }); + auto colour = detail::getDefaultWindowColour(); + COREWEBVIEW2_COLOR background { 0xff, + static_cast (GetRValue (colour)), + static_cast (GetGValue (colour)), + static_cast (GetBValue (colour)) }; + controller2->put_DefaultBackgroundColor (background); } } @@ -1568,6 +1573,12 @@ struct WebView::Pimpl if (auto w = getPimpl (h)) w->setVisible (wp != 0); + if (msg == WM_ERASEBKGND) + { + detail::paintWindowBackground (h, reinterpret_cast (wp)); + return 1; + } + return DefWindowProcW (h, msg, wp, lp); }