Normally you go to Settings to change it.
The first script will do this for you.
The second one shows you how to implement it in your scripts.
have fun.
The compiled version with icon (next to startbutton in the screenshots.
Code: Select all
#SingleInstance Force ; Allow only one instance off this app]
#NoTrayIcon ; we don't want a SystemTray icon
; read the System lightmode from the registry
RegRead,L_LightMode,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,SystemUsesLightTheme
If L_LightMode { ; if the mode was Light
; write both system end App lightmode to the registry
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,SystemUsesLightTheme,0
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,AppsUseLightTheme ,0
}
else { ; if the mode was dark
; write both system end App lightmode to the registry
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,SystemUsesLightTheme,1
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,AppsUseLightTheme ,1
}
; tell the system it needs to refresh the user settings
run,RUNDLL32.EXE USER32.DLL`, UpdatePerUserSystemParameters `,2 `,True
Exitapp
Code: Select all
#SingleInstance Force ; Allow only one instance off this app]
; setting up some global variables with prefix G_ for clarity
Global G_LightMode ; will contain the value from the system
Global G_ScriptLightMode := 0 ; the mode for the script
Global G_hTV ; handle for the treeview
Global G_hLV ; handle for the listview
Global G_hEB ; handle for the edit box
; read the System lightmode from the registry
RegRead,G_LightMode,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,AppsUseLightTheme
; setting up the GUI
; using handles instead of a control variable
Gui,Font,s14
Gui,Add,Treeview,x00 y0 w200 h700 hwndG_hTV
Gui,Add,Listview,x+0 yp w200 h700 hwndG_hLV,Name
Gui,Add,Edit ,x+0 yp w600 h700 hwndG_hEB,Press Win + n to toggle nightmode for this app
; Fill up the gui with some data
Loop,10
TV_Add("TV " A_Index)
Loop,50
LV_Add("","LV " A_Index)
Gui_Color_Changed(G_LightMode) ; Apply the lightmode from the system
gui,show,,NightModeCapableApp ; Show our GUI
OnMessage(0x001A,"WM_SETTINGCHANGE") ; Get this message to see if the system changed lightmode
Return
#IfWinActive,NightModeCapableApp ; if our app is active
#n::MI_Toggle_DarkMode() ; set Win + n to toggle nightmode
WM_SETTINGCHANGE(L_wParam,L_lParam,L_msg,L_hwnd){ ; message handler
If (L_msg=0x001A) ; WM_SETTINGCHANGE := 0x001A
RegRead,L_LightMode,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,AppsUseLightTheme
if L_LightMode<>G_LightMode ; If the lightmode has changed
Gui_Color_Changed(G_LightMode:=L_LightMode) ; assign the new mode and change the colors
Return,1
}
MI_Toggle_DarkMode(){ ; MI_ stands for MenuItem
G_ScriptLightMode := !G_ScriptLightMode ; toggle the scripts lightmode
Gui_Color_Changed() ; change the colors
}
Gui_Color_Changed(L_LightMode:=""){
If (L_LightMode=0) ; if lightmode is off
G_ScriptLightMode:=0 ; overwrite the app mode
else If (L_LightMode=1) ; if lightmode is on
G_ScriptLightMode:=1 ; overwrite the app mode
If G_ScriptLightMode { ; if the script needs to be Light
Gui,Color,White,White ; change the gui color, and controls
Gui,Font ,cBlack ; new controls wil have this text color
GuiControl,+BackGroundWhite +cBlack,%G_hTV%
GuiControl,+BackGroundWhite +cBlack,%G_hLV%
GuiControl,+BackGroundWhite +cBlack,%G_hEB%
}
else { ; if the script needs to be Dark
Gui,Color,Black,Black ; change the gui color, and controls
Gui,Font ,cWhite ; new controls wil have this text color
GuiControl,+BackGroundBlack +cWhite,%G_hTV%
GuiControl,+BackGroundBlack +cWhite,%G_hLV%
GuiControl,+BackGroundBlack +cWhite,%G_hEB%
}
}