Page 2 of 2

Re: Dark theme / Windows themed AHK

Posted: 24 Oct 2021, 23:27
by lexikos
A way to adapt a gui to the current dark/light mode is to query the registry to find the current mode:
The approach shown in the StackOverflow answer I referenced earlier is to call ShouldAppsUseDarkMode (uxtheme\132). They also call !IsHighContrast(), but I can't find that function.

Re: Dark theme / Windows themed AHK

Posted: 25 Oct 2021, 00:06
by malcev

Re: Dark theme / Windows themed AHK

Posted: 25 Oct 2021, 16:28
by JnLlnd
@lexikos , I just found that when a menu is split in columns with the Break or BarBreak Menu, Add options, the menu is not dark.

Image

Is this something that can be fixed?

Re: Dark theme / Windows themed AHK

Posted: 26 Oct 2021, 21:48
by lexikos
🤷‍♂️

I've only gone far enough to determine what I've already posted in this topic, and haven't even used any of it outside of basic tests.

Re: Dark theme / Windows themed AHK

Posted: 27 Oct 2021, 10:28
by JnLlnd
lexikos wrote:
26 Oct 2021, 21:48
🤷‍♂️
@lexikos : I understand. If whenever you have time to dig this, at your convenience.

Or maybe someone else has an idea?

Re: Dark theme / Windows themed AHK

Posted: 27 Oct 2021, 18:18
by lexikos
Actually, I realized that this is to be expected. There are some cases where the menu falls back to classic Windows look, instead of the themed look, and this is one of those cases. It's hard to tell in Windows 10 because the themed look uses solid colours. If you compare the menu with BarBreak to one in light mode without BarBreak, you will see that the colours are different. Perhaps the theme data simply doesn't cover the elements needed to render the menu. Of course, UWP apps don't use Win32 menus to begin with.

It is likely that the only possible solutions are owner-drawn menus or a custom GUI. majkinetor wrote a script named MMenu back in 2007 that allowed complete customization of colours and fonts, and other features, but being so old it does not support Unicode/x64 and is hard to find.

Re: Dark theme / Windows themed AHK

Posted: 27 Oct 2021, 22:50
by JnLlnd
@lexikos :Thanks for the explanation even if it's not very encouraging ;-)
lexikos wrote:
27 Oct 2021, 18:18
It is likely that the only possible solutions are owner-drawn menus or a custom GUI. majkinetor wrote a script named MMenu back in 2007 that allowed complete customization of colours and fonts, and other features, but being so old it does not support Unicode/x64 and is hard to find.
I've considered this a few times and always concluded that I did ont want to take this route. Too much work and risk for the benefits (compare to code new or improved actual features).

Re: Dark theme / Windows themed AHK

Posted: 03 Nov 2021, 02:48
by KruschenZ
lexikos wrote:
23 Oct 2021, 18:30
The module handle and function addresses do not change. To change the setting back, you need only the last two lines (assuming the variables are global or static).

I did not work out how to affect the menu bar, although I suppose you can use owner-drawn menus.

For Button controls (and maybe some others?), you can set the DarkMode_Explorer theme.

Code: Select all

DllCall("uxtheme\SetWindowTheme", "ptr", ctrl_hwnd, "str", "DarkMode_Explorer", "ptr", 0)
I think the StackOverflow answer contains a workaround for the scroll bars, but I didn't look into it let alone translate it.
This works perfect :-) Thank you @lexikos for this! :bravo: :salute:

...too bad it does not work on ListView Header (SysHeader321).
I know, I have to draw my own if I want to change the color (I found an old example for AutoIt > https://www.autoitscript.com/forum/topic/182405-solved-set-headercolumn-color-in-listview/ )
But I hoped to change the color easy :D ;)

with best regards
KruschenZ

Re: Dark theme / Windows themed AHK

Posted: 03 Nov 2021, 07:40
by lmstearn
lexikos wrote:
27 Oct 2021, 18:18
majkinetor wrote a script named MMenu back in 2007 that allowed complete customization of colours and fonts, and other features, but being so old it does not support Unicode/x64 and is hard to find.
Here it is, the comments and suggestions in the thread may also help in case anyone is interested in a touch up for v2. :)

Re: Dark theme / Windows themed AHK

Posted: 04 Nov 2021, 04:50
by KruschenZ
Hi there,

if someone also had problems to find out the HWND from a ComboLBox to color the Scrollbar dark:

https://www.autohotkey.com/board/topic/85044-get-hwnd-to-comboboxs-edit-field/
from @just me ; Thank you for that :D :bravo:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

PtrType := A_PtrSize ? "Ptr" : "Uint"
PtrSize := A_PtrSize ? A_PtrSize : 4

Gui, +LastFound

WinGet, hWindow,ID
Gui, Add, ComboBox, w400 r6 hwndHCBB, a|b|c|e|f|g|h|i|j|k
Gui, Show, , ComboBox & Edit

GetComboBoxInfo(HCBB, CBBInfo)
HCBBEDIT := NumGet(CBBInfo, 40 + PtrSize, PtrType)
HCBBLIST := NumGet(CBBInfo, 40 + (2 * PtrSize), PtrType)
HCBB += 0
ControlSetText, , % "ComboBox: " . (HCBB + 0) . " - Edit: " . HCBBEDIT . " - ListBox: " . HCBBLIST, ahk_id %HCBBEDIT%

DllCall("UxTheme.DLL\SetWindowTheme", "Ptr", HCBBLIST, "Str", "DarkMode_Explorer", "Ptr", 0)

Return

;_______________________________________________________________________________________________________________________

GuiClose:
ExitApp

;_______________________________________________________________________________________________________________________

GetComboBoxInfo(HCBB, ByRef CBBI)
 {
	; http://msdn.microsoft.com/en-us/library/bb775939%28VS.85%29.aspx
	Global PtrSize, PtrType
	CBBISize := 40 + (3 * PtrSize)
	VarSetCapacity(CBBI, CBBISize, 0)
	NumPut(CBBISize, CBBI, 0, "UInt")
	Return DllCall("User32.dll\GetComboBoxInfo", PtrType, HCBB, PtrType, &CBBI)
}
Dark Scrollbar.PNG
Dark Scrollbar.PNG (4.61 KiB) Viewed 4584 times
with best regards
KruschenZ

Re: Dark theme / Windows themed AHK

Posted: 05 Jan 2022, 20:32
by gwarble
Wonderful, thanks guys, I've wanted dark menus from the taskbar for a while and randomly decided to search for a solution.

In my case, all my workstations are set up as Light "app mode", Dark "window mode" (ie dark taskbar, see screenshot), which yielded the dark menu solution in this thread non-functional.

The reason for this is that in older builds of Windows 10, the option was AllowDarkModeForWindow and boolean, but the SetPreferredAppMode options are something like:

Code: Select all

0=Default
1=AllowDark
2=ForceDark
3=ForceLight
4=Max
So with my config, the API considers it still "light", but when my menu comes from the taskbar i want it to be dark like the other taskbar menus, so DllCall(SetPreferredAppMode, "int", 2) forces dark when I want it by using "2". 3 is obvious, and I haven't tried 4 yet to see what max means, but hopefully someone will find this useful.

Code: Select all

Menu_Dark(2)
Menu, Tray, Show

Menu_Dark(d) { ; 0=Default  1=AllowDark  2=ForceDark  3=ForceLight  4=Max  
 global Name, MenuIconSize
 static uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
 static SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
 static FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")

 DllCall(SetPreferredAppMode, "int", d) ; 0=Default  1=AllowDark  2=ForceDark  3=ForceLight  4=Max  
 DllCall(FlushMenuThemes)
}

Re: Dark theme / Windows themed AHK

Posted: 27 Aug 2022, 16:12
by TheDewd
I can't figure out how to make my Gui titlebar dark. The ListLines window is dark as stated, but I don't know how to execute this for my other Gui windows. I see screenshots from the other replies showing dark titlebars.

Edit: Nevermind. I had to call it BEFORE Gui, Show.
lexikos wrote:
25 Sep 2021, 02:28
However, you can at least put the title bar into dark mode by calling DwmSetWindowAttribute via DllCall.

Code: Select all

#requires AutoHotkey v1.1
if (A_OSVersion >= "10.0.17763" && SubStr(A_OSVersion, 1, 3) = "10.") {
    attr := 19
    if (A_OSVersion >= "10.0.18985") {
        attr := 20
    }
    DllCall("dwmapi\DwmSetWindowAttribute", "ptr", A_ScriptHwnd, "int", attr, "int*", true, "int", 4)
}
ListLines
Pause
DwmSetWindowAttribute need only be called once for each window.

Re: Dark theme / Windows themed AHK

Posted: 01 Feb 2024, 02:46
by tetratheta
I also wish AHK supports Windows' dark theme 'natively', but I think it must be almost impossible.

Even .NET WinForms, which would be first-party to MS, doesn't support dark theme nativly. They have opened issue for tracking it though.

Basically, those dark theme things are not well documented. All those workarounds I've found are using DllCall or P/Invoke for accessing internal methods. The closest way of using dark theme is this, but it has few limitations like Checkbox, ListView etc.