Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions choc/gui/choc_DesktopWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -771,9 +795,6 @@ struct DesktopWindow::Pimpl
return;

setBounds (b);
ShowWindow (hwnd, SW_SHOW);
UpdateWindow (hwnd);
SetFocus (hwnd);
}

~Pimpl()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1021,6 +1049,7 @@ struct DesktopWindow::Pimpl
{
switch (msg)
{
case WM_ERASEBKGND: detail::paintWindowBackground (h, reinterpret_cast<HDC> (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;
Expand Down
13 changes: 12 additions & 1 deletion choc/gui/choc_WebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<BYTE> (GetRValue (colour)),
static_cast<BYTE> (GetGValue (colour)),
static_cast<BYTE> (GetBValue (colour)) };
controller2->put_DefaultBackgroundColor (background);
}
}

Expand Down Expand Up @@ -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<HDC> (wp));
return 1;
}

return DefWindowProcW (h, msg, wp, lp);
}

Expand Down