Skip to content

Commit

Permalink
Now respects dark mode and light mode making native window background…
Browse files Browse the repository at this point in the history
… on Windows either black or white.
  • Loading branch information
MikeYeager committed Nov 21, 2024
1 parent a1bebaf commit 57552aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
34 changes: 31 additions & 3 deletions Photino.Native/Photino.Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ struct ShowMessageParams
};


const HBRUSH darkBrush = CreateSolidBrush(RGB(0, 0, 0));
const HBRUSH lightBrush = CreateSolidBrush(RGB(255, 255, 255));

void Photino::Register(HINSTANCE hInstance)
{
InitDarkModeSupport();
Expand All @@ -62,7 +65,7 @@ void Photino::Register(HINSTANCE hInstance)
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wcx.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcx.hbrBackground = IsDarkModeEnabled() ? darkBrush : lightBrush;
wcx.lpszMenuName = nullptr;
wcx.lpszClassName = CLASS_NAME;
wcx.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
Expand Down Expand Up @@ -320,6 +323,7 @@ HWND Photino::getHwnd()
return _hWnd;
}


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
Expand All @@ -328,21 +332,45 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
EnableDarkMode(hwnd, true);
if (IsDarkModeEnabled())
{
RefreshNonClientArea(hwnd);
}
break;
}
case WM_SETTINGCHANGE:
{
if (IsColorSchemeChange(lParam))
SendMessageW(hwnd, WM_THEMECHANGED, 0, 0);

break;
}
case WM_THEMECHANGED:
{
EnableDarkMode(hwnd, IsDarkModeEnabled());
RefreshNonClientArea(hwnd);
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);

// Fill the background with the current theme color
if (IsDarkModeEnabled())
{
FillRect(hdc, &ps.rcPaint, darkBrush);
//SetTextColor(hdc, RGB(255,255,255));
}
else
{
FillRect(hdc, &ps.rcPaint, lightBrush);
//SetTextColor(hdc, RGB(0, 0, 0));
}

// Draw some text
//SetBkMode(hdc, TRANSPARENT);
//TextOut(hdc, 10, 10, L"Hello, World! (Dynamic Theme)", 31);

EndPaint(hwnd, &ps);
break;
}
case WM_ACTIVATE:
Expand Down
4 changes: 2 additions & 2 deletions Photino.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private static void FluentStyle()
//.SetMaximized(true)
//.SetMaxSize(640, 480)
//.SetMinimized(true)
.SetMinHeight(240)
.SetMinWidth(320)
.SetMinHeight(480)
.SetMinWidth(640)
//.SetMinSize(320, 240)
//.SetResizable(false)
//.SetTopMost(true)
Expand Down
2 changes: 1 addition & 1 deletion Photino.Test/wwwroot/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@

</script>
</head>
<body style="background-color: rgba(0,0,0,0)">
<body>
<h1 id="Title">Test Bench</h1>
<b>Window</b><br>
<button onclick="SetIconFile()">Icon</button>
Expand Down

0 comments on commit 57552aa

Please sign in to comment.