Dark theme / Windows themed AHK

Propose new features and changes
User avatar
raron
Posts: 37
Joined: 11 Aug 2014, 00:50

Dark theme / Windows themed AHK

12 Sep 2021, 23:50

Title...

Surprised I haven't seen this wishlisted? The things showing up in a search is for forum theme or other color stuff.

Now that we finally have dark theme in Windows (and have for some time), AHK stands out in a bad way. Blasting the retina with a bright white big window. It would be nice if it could follow the Windows theme setting, or have a custom one maybe.

That is all :)
User avatar
MrDodel
Posts: 96
Joined: 28 Apr 2021, 09:03
Location: Event Horizon

Re: Dark theme / Windows themed AHK

13 Sep 2021, 01:55

I'm presuming you mean an "Dark" version of an AHK editor, if so I use Notepad++ along with : viewtopic.php?f=88&t=72424

If not, what do you mean by "Dark Theme AHK" -?
User avatar
raron
Posts: 37
Joined: 11 Aug 2014, 00:50

Re: Dark theme / Windows themed AHK

13 Sep 2021, 05:17

Ah, I forgot to clarify that. No, I mean the AHK debugger window I guess you can call it? Where you can see the last keys used, variable contents etc. It pops up if you dobleclick the H icon in taskbar.

I used Notepad++ before, and still use it now and then. But I've mostly moved to the Atom editor now.
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Dark theme / Windows themed AHK

15 Sep 2021, 17:48

themed windows are not really a thing in ahk, ahk uses the provided Windows controls. the fancy new ones you see are not the old "standard" controls, they're a new set. Usually found in Windows Store apps. Possibly a .net thing?

Apart from checking the OS to see if you're dark/light and then coloring SOME controls (cant do borders, menus (?), buttons), to use some generally bad looking dark colors on old controls, not many other possible options.
Yes, theres a handful of nicely skinned UI's around, but those are a ton of work, not really ideal for a quick-to-access lightweight debugger most won't use. Don't really want to be bundling some 8k line GDIP library just for a pretty hidden window
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
raron
Posts: 37
Joined: 11 Aug 2014, 00:50

Re: Dark theme / Windows themed AHK

20 Sep 2021, 04:20

Maybe themed is a bit far fetched, I can appreciate to keep it as simple as possible.
But some simple(?) inverted colors would go a long way. Even if it's a bit high contrast. But no biggie in a way I suppose (still, I'd wish for something like this).

Side-note:

I tried this AHK script by malcev, which almost works great: viewtopic.php?f=6&t=94264
Just one warning in line 4 but it still continued and worked (it didn't find "AutoHotkeyU64_UIA.exe". I just changed it to my installed variant of AHK, AutoHotkeyU64.exe as a test, and then it worked witout any warnings).

It works nicely with most other windows, following the window if moving or resizing. Only AHK debugger window is a bit different. It's only updating the inverted position after releasing it (releasing mouse button and placing the window). But it works. A bit useless as-is as you have to fist switch to it and then invert it, but I guess that can probably be fixed/automated, hopefully for other AHK scripts as well (I haven't really looked much into this yet).
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Dark theme / Windows themed AHK

25 Sep 2021, 02:28

Only UWP apps natively support the dark theme, so you should see that AutoHotkey is far from the only app that doesn't fit in.

There is as yet no documented way to put a window of a Win32 app into dark mode. The undocumented ways are shown here: https://stackoverflow.com/a/58547831/894589

It makes reference to the undocumented "SetPreferredAppMode" function, which must be called before any windows are created. You cannot do this, because the script's main window is created before the script executes. I will not add it to the program, because the function is undocumented, the issue frivolous, and the solution incomplete.

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

Code: Select all

#requires AutoHotkey v2.0-
if VerCompare(A_OSVersion, "10.0.17763") >= 0 {
    attr := 19
    if VerCompare(A_OSVersion, "10.0.18985") >= 0 {
        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.

Note the minimum required Windows 10 version.

According to my testing, this will make the title bar dark even if the system is set to "Light". The link above leads to C++ code demonstrating how to detect whether the app should use dark mode.

For changing the colours of the main window's Edit control, I suggest searching the forums for WM_CTLCOLOREDIT.

For the menus, I don't know. You could remove the menus with DllCall("SetMenu", "ptr", A_ScriptHwnd, "ptr", 0) (but then you obviously can't use them).
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Dark theme / Windows themed AHK

25 Sep 2021, 12:53

raron, It is better to run magnification script with autohotkey_UIA, because when You create gui with AlwaysOnTop style running from autohotkey_UIA then Your Gui will get the highest band.
I asked lexikos always to display option "Run with UI Access" when install autohotkey, but he did not want to do it.
viewtopic.php?f=13&t=75694
Also You can change, brightness, contrast, saturation in Color Transformation Matrix.
https://www.integral-domain.org/lwilliams/math150/labs/matrixcolorfilter.php
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

22 Oct 2021, 13:15

Related to this topic, I'm specifically interested in creating AHK menus (Menu, MenuName, ... ) suitable for Windows Dark mode. Currently, for users preferring dark display, these menus are, at least, unpleasant.

I explain my concerns here. I just wanted to take it to your attention.
viewtopic.php?f=76&t=95364
: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

22 Oct 2021, 22:18

For menus,

Code: Select all

;https://stackoverflow.com/a/58547831/894589
uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
DllCall(SetPreferredAppMode, "int", 1) ; Dark
DllCall(FlushMenuThemes)
SetPreferredAppMode might affect other things, but doesn't as far as I can tell.

This code is compatible with v1.1 and v2.0-beta.2. I think it requires Windows 1903+.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

22 Oct 2021, 22:33

Great ! I'll switch to dark mode myself and test it to see if there can be side effects.

How can I send you a beer @lexikos ?
:-)
: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
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Dark theme / Windows themed AHK

23 Oct 2021, 02:30

:bravo: This looks great, certainly to apply dark mode to the guis.

Does somebody know if it is possible to apply the dark mode to the gui controls, statusbar and menubar?

Here is an example of applied to a gui.
(titlebar and menu set with Dllcalls, text control with Opt("Background0x1E1E1E cWhite"))
2021-10-23 09_27_45-Window.png
2021-10-23 09_27_45-Window.png (15.23 KiB) Viewed 9319 times
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

23 Oct 2021, 08:40

@lexikos : Could this call be toggled? Would it be something like this?

Code: Select all

;https://stackoverflow.com/a/58547831/894589
uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
DllCall(SetPreferredAppMode, "int", 0) ; *** 0 for NOT Dark
DllCall(FlushMenuThemes)
Does all the lines need to be called if this piece of code has already been executed in the same script?

@AHK_user : Interesting work.

Thanks.
: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

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.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Dark theme / Windows themed AHK

24 Oct 2021, 02:43

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.
:dance:
@Lexicos Thanks for the Dark tip, cool.

I tested to apply it to some controls .

As far that I noticed it affects:
=> Button: to Dark mode, seems to work perfect.
=> Edit: changes scrollbar color to dark mode, but for controls without scrollbar, it seems to change the background color when not active.
=> ListBox: changes scrollbar color to dark mode

The border color of the controls are not affected, and the C option seems to be overridden with this DLLCall for some controls (not for the Edit).

Interesting, it seems to be able to change the scrollbars of several scrollbars, and the buttons seems to work perfectly.

Code: Select all

;V2
For Hwnd, GuiCtrlObj in MyGui{
       DllCall("uxtheme\SetWindowTheme", "ptr", GuiCtrlObj.hwnd, "str", "DarkMode_Explorer", "ptr", 0)
}
2021-10-24 07_49_29-Settings.png
2021-10-24 07_49_29-Settings.png (18.14 KiB) Viewed 9175 times
2021-10-24 07_47_13-Untitled - Dark AHKpad.png
2021-10-24 07_47_13-Untitled - Dark AHKpad.png (10.37 KiB) Viewed 9175 times
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

24 Oct 2021, 10:41

Here a simple working example of lexikos's code for a menu:

v1.1

Code: Select all

uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
DllCall(SetPreferredAppMode, "int", 1) ; Dark
DllCall(FlushMenuThemes)

Menu, MyMenu, Add, Test1, Test
Menu, MyMenu, Add, Test2, Test
Menu, MyMenu, Add, Test3, Test
Menu, MyMenu, Show
return

Test:
ExitApp
And for a button:

v1.1

Code: Select all

Gui, Add, Button, vMyButton gTest, Test
GuiControlGet, hwndMyButton, Hwnd, MyButton
DllCall("uxtheme\SetWindowTheme", "ptr", hwndMyButton, "str", "DarkMode_Explorer", "ptr", 0)
Gui, Show
return

Test:
ExitApp
: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
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Dark theme / Windows themed AHK

24 Oct 2021, 10:51

Who's Lexicos? AHK_user
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

24 Oct 2021, 10:53

And this other example showing how to switch from creating menus dark to not dark:

v1.1

Code: Select all

uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
DllCall(SetPreferredAppMode, "int", 1) ; Dark
DllCall(FlushMenuThemes)

Menu, MyMenuDark, Add, Test1 Dark, Next
Menu, MyMenuDark, Add, Test2 Dark, Next
Menu, MyMenuDark, Add, Test3 Dark, Next
Menu, MyMenuDark, Show

DllCall(SetPreferredAppMode, "int", 0) ; NOT Dark
DllCall(FlushMenuThemes)

Menu, MyMenu, Add, Test1 not Dark, Quit
Menu, MyMenu, Add, Test2 not Dark, Quit
Menu, MyMenu, Add, Test3 not Dark, Quit
Menu, MyMenu, Show

return

Next:
return

Quit:
ExitApp
: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
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Dark theme / Windows themed AHK

24 Oct 2021, 11:32

tidbit wrote:
24 Oct 2021, 10:51
Who's Lexicos? AHK_user
a user that the mods seem keen on not deleting, despite numerous reports.....
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Dark theme / Windows themed AHK

24 Oct 2021, 13:25

I know :P even old time users like him still spell Lexikos wrong, its hilarious. been happening over a decade lol. anywho, this is offtopic.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Dark theme / Windows themed AHK

24 Oct 2021, 17:15

LOL! Back to our topic :-)

The example provided by AHK_user above consists of changing (i.e. "hardcoding") the colors of each control. This is interesting but this will not react if the user changes from "Dark mode" to "Light mode" in Windows Colors Settings. On the opposite, with the above code from LexiKos for menus or buttons, the controls will react immediately to the Windows dark/light mode setting.

A way to adapt a gui to the current dark/light mode is to query the registry to find the current mode:
RegRead, blnLightMode, HKCU, SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
(found here: viewtopic.php?f=6&t=73967&p=319580)

Knowing the current mode with blnLightMode, your script can change the colors of your gui if mode is false (dark). However, the gui will not react immediately if user changes his dark/light mode setting. The gui would have to be reloaded. Here is some code captured during a zoom call with friends that changes the colors of all controls in a gui. If you want to build on it, feel free to do so. For example, earlier in this thread Lexikos explained hot to set the title bar to dark.

Code: Select all

#requires AutoHotkey v1.1
#SingleInstance,Force

Gui, New, +HwndstrHwnd, Dark/Light Mode
Gui, Add, Edit, , My Edit
Gui, Add, Button, , My Button
Gui, Add, ListView, , Column One|Column Two
LV_Add("", "one", "two")
LV_Add("", "one", "two")
LV_Add("", "one", "two")
Gui, Show

RegRead, blnLightMode, HKCU, SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, AppsUseLightTheme ; check SystemUsesLightTheme for Windows system preference
if !(blnLightMode) ; else keep default colors
{
	intWindowColor := 0x404040
	intControlColor := 0xFFFFFF
		
	WinGet,strControlList, ControlList, ahk_id %strHwnd%
	Gui, Color, %intWindowColor%, %intControlColor%
	for strKey, strControl in StrSplit(strControlList,"`n","`r`n")
	{
		ControlGet, strControlHwnd, HWND, , %strControl%, ahk_id %strHwnd%
		
		; for ListView control
		GuiControl, +Background%intWindowColor%,%strControl%
		Gui,Font, c%intControlColor%
		GuiControl, Font, %strControl%
	}
}

return
: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

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 36 guests