Last active
November 27, 2022 20:38
-
-
Save SkyEmie/34cbf48d89b1908648e1b44bc72dc092 to your computer and use it in GitHub Desktop.
This little draft demonstrates how to switch from a light theme, to a dark application title bar with AutoIT, using DWM api.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This little draft demonstrates how to switch from a light theme, to a dark application title bar with AutoIT, using DwmAPI. | |
; It will probably be useful to someone who wants to do this, without any headache. | |
; Because windows does not have any official documentation on this subject today :s | |
#include <GUIConstantsEx.au3> | |
#notrayicon | |
opt('guioneventmode', 1) | |
#cs ---------------------------------------------------------------------------- | |
Function : is_app_dark_theme() | |
Description : returns if the user has enabled the dark theme for applications in the Windows settings (0 on / 1 off) | |
if OS too old (key does not exist) the key returns nothing, so function returns False | |
#ce ---------------------------------------------------------------------------- | |
func is_app_dark_theme() | |
return(regread('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize', 'AppsUseLightTheme') == 0) ? True : False | |
endfunc | |
#cs ---------------------------------------------------------------------------- | |
Function : set_dark_theme($hwnd, $dark_theme = True) | |
Description : set to the handle, the attribute to define whether dark/light theme | |
#ce ---------------------------------------------------------------------------- | |
func set_dark_theme($hwnd, $dark_theme = True) | |
; before this build set to 19, otherwise set to 20, no thanks Windaube to document anything ❤️ | |
$DWMWA_USE_IMMERSIVE_DARK_MODE = (@osbuild <= 18985) ? 19 : 20 | |
$dark_theme = ($dark_theme == True) ? 1 : 0 | |
dllcall( _ | |
'dwmapi.dll', _ | |
'long', 'DwmSetWindowAttribute', _ | |
'hwnd', $hwnd, _ | |
'dword', $DWMWA_USE_IMMERSIVE_DARK_MODE, _ | |
'dword*', $dark_theme, _ | |
'dword', 4 _ | |
) | |
endfunc | |
; create gui | |
$gui_hwnd = guicreate('Tiny gui', 800, 450) | |
guisetonevent($GUI_EVENT_CLOSE, 'gui_close') | |
; if dark theme enabled for apps in windows settings, set dark theme to gui | |
if is_app_dark_theme() == True then | |
set_dark_theme($gui_hwnd, True) | |
endif | |
; display gui | |
guisetstate(@sw_show) | |
while 1 | |
sleep(10) | |
wend | |
func gui_close() | |
exit | |
endfunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment