Dark theme / Windows themed AHK

Propose new features and changes
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Dark theme / Windows themed AHK

24 Oct 2021, 23:27

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.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

25 Oct 2021, 16:28

@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?
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Dark theme / Windows themed AHK

26 Oct 2021, 21:48

🤷‍♂️

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.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

27 Oct 2021, 10:28

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?
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Dark theme / Windows themed AHK

27 Oct 2021, 18:18

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.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

27 Oct 2021, 22:50

@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).
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Dark theme / Windows themed AHK

03 Nov 2021, 02:48

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
User avatar
lmstearn
Posts: 688
Joined: 11 Aug 2016, 02:32
Contact:

Re: Dark theme / Windows themed AHK

03 Nov 2021, 07:40

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. :)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
User avatar
KruschenZ
Posts: 44
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Dark theme / Windows themed AHK

04 Nov 2021, 04:50

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 4195 times
with best regards
KruschenZ
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: Dark theme / Windows themed AHK

05 Jan 2022, 20:32

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)
}
Attachments
Menu.png
Menu.png (40.29 KiB) Viewed 3630 times
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
TheDewd
Posts: 1506
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Dark theme / Windows themed AHK

27 Aug 2022, 16:12

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.
User avatar
tetratheta
Posts: 34
Joined: 16 Jan 2019, 13:28

Re: Dark theme / Windows themed AHK

01 Feb 2024, 02:46

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.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 23 guests