Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
SDClowen committed Dec 30, 2024
1 parent 7153922 commit 645d152
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
3 changes: 1 addition & 2 deletions SDUI/Controls/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public ListView()
UpdateStyles();

_headerSubClass = new();
WindowsHelper.UseImmersiveDarkMode(Handle, ColorScheme.BackColor.IsDark());
}

protected override void OnSelectedIndexChanged(EventArgs e)
Expand Down Expand Up @@ -68,8 +69,6 @@ protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);


WindowsHelper.UseImmersiveDarkMode(Handle, ColorScheme.BackColor.IsDark());
_headerSubClass.AssignHandle(this.Handle);
SendMessage(Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
}
Expand Down
31 changes: 20 additions & 11 deletions SDUI/Controls/Subclasses/ListViewHeaderSubclassedWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using static SDUI.NativeMethods;

namespace SDUI.Controls.Subclasses
Expand Down Expand Up @@ -62,12 +59,13 @@ public void AssignHandle(IntPtr handle)
++_uses;
Handle = handle;

SetWindowSubclass(handle, _windowProcHandle, UIntPtr.Zero, UIntPtr.Zero);

IntPtr hHeader = SendMessage(handle, LVM_GETHEADER, 0, 0);

SetWindowTheme(hHeader, "ItemsView", null); // DarkMode
SetWindowTheme(handle, "ItemsView", null); // DarkMode
var isDark = ColorScheme.BackColor.IsDark();
SetWindowTheme(hHeader, isDark ? "DarkMode_ItemsView" : "ItemsView", null); // DarkMode
SetWindowTheme(handle, isDark ? "DarkMode_ItemsView" : "ItemsView", null); // DarkMode
SetWindowSubclass(handle, _windowProcHandle, UIntPtr.Zero, UIntPtr.Zero);

OnHandleChange();
}
Expand Down Expand Up @@ -125,11 +123,16 @@ UIntPtr dwRefData
case WM_THEMECHANGED:

IntPtr hHeader = SendMessage(Handle, LVM_GETHEADER, 0, 0);
var isDark = ColorScheme.BackColor.IsDark();

//SetWindowTheme(hHeader, isDark ? "DarkMode_ItemsView" : "ItemsView", null); // DarkMode
//SetWindowTheme(Handle, isDark ? "DarkMode_ItemsView" : "ItemsView", null); // DarkMode

AllowDarkModeForWindow(Handle, ColorScheme.BackColor.IsDark());
AllowDarkModeForWindow(hHeader, ColorScheme.BackColor.IsDark());

var hTheme = OpenThemeData(IntPtr.Zero, "ItemsView");
//AllowDarkModeForWindow(Handle, ColorScheme.BackColor.IsDark());
//AllowDarkModeForWindow(hHeader, ColorScheme.BackColor.IsDark());

var hTheme = OpenThemeData(IntPtr.Zero, isDark ? "DarkMode_ItemsView" : "ItemsView");

const int HP_HEADERITEM = 1;
const int TMT_FILLCOLOR = 3802;
Expand All @@ -138,11 +141,17 @@ UIntPtr dwRefData
if (hTheme != IntPtr.Zero)
{
COLORREF color;
if (GetThemeColor(hTheme, 0, 0, TMT_TEXTCOLOR, out color) > 0)
if (isDark)
color.R = color.G = color.B = 255;
else
color.R = color.G = color.B = 0;

//if (GetThemeColor(hTheme, 0, 0, TMT_TEXTCOLOR, out color) > 0)
{
SendMessage(Handle, LVM_FIRST + 36, IntPtr.Zero, ref color);
}
if (GetThemeColor(hTheme, 0, 0, TMT_FILLCOLOR, out color) > 0)

//if (GetThemeColor(hTheme, 0, 0, TMT_FILLCOLOR, out color) > 0)
{
SendMessage(Handle, LVM_FIRST + 38, IntPtr.Zero, ref color);
SendMessage(Handle, LVM_FIRST + 1, IntPtr.Zero, ref color);
Expand Down

0 comments on commit 645d152

Please sign in to comment.