Setting the title in dark mode. [Gui.SetDarkTitle()]
Setting the Menu in dark mode [Gui.SetDarkMenu()] (this actually sets all the menus of the script in darkmode, I do not know if it is acceptable)
Setting Edit, Buttons and listbox controls in dark mode (only changes the scrollbar, but the effect is nice) [Gui.Control.SetDarkMode()]
In the current script, I added a SetDarkMode() method to all the controls. But as it only effects Button, Edit and Listbox (or was is listview?) maybe it is better to add the method only to these controlls, so that an error will display if the method is set to a control that has no change from it.
we could also add a general gui.SetDarkMode() that loops over all the controlls and sets them all to darkmode. (By my experience, this only affects button, listbox end edit with a scrollbar.) This would only affect the already existing controls.
Code: Select all
; Thanks to jNizM for the interesting DllCalls
; https://www.autohotkey.com/boards/viewtopic.php?t=70852
class Edit_ext {
Static __New() {
Gui.Edit.Prototype.SetCue:= ObjBindMethod(this, "SetCue")
}
Static SetCue(_obj, string, option := true) {
; Links ....................: https://docs.microsoft.com/en-us/windows/win32/controls/em-setcuebanner
; Description ..............: Sets the textual cue, or tip, that is displayed by the edit control to prompt the user for information.
; Option ...................: True -> if the cue banner should show even when the edit control has focus
; False -> if the cue banner disappears when the user clicks in the control
static ECM_FIRST := 0x1500
static EM_SETCUEBANNER := ECM_FIRST + 1
if (DllCall("user32\SendMessage", "ptr", _obj.hwnd, "uint", EM_SETCUEBANNER, "int", option, "str", string, "int"))
return true
return false
}
}
class ComboBox_ext {
Static __New() {
Gui.ComboBox.Prototype.SetCue := ObjBindMethod(this, "SetCue")
}
Static SetCue(_obj, string, option := true) {
; Links ....................: https://docs.microsoft.com/en-us/windows/win32/controls/cb-setcuebanner
; Description ..............: Sets the cue banner text that is displayed for the edit control of a combo box.
static CBM_FIRST := 0x1700
static CB_SETCUEBANNER := CBM_FIRST + 3
if (DllCall("user32\SendMessage", "ptr", _obj.hwnd, "uint", CB_SETCUEBANNER, "int", option, "str", string, "int"))
return true
return false
}
}
class Control_ext {
Static __New() {
Gui.Control.Prototype.SetDarkMode := ObjBindMethod(this, "SetDarkMode")
}
Static SetDarkMode(_obj) {
; This has the following effect:
; Button => dark button
; Edit => if row>1 dark scrollbar
; Listbox => dark scrollbar
if (DllCall("uxtheme\SetWindowTheme", "ptr", _obj.hwnd, "str", "DarkMode_Explorer", "ptr", 0))
return true
return false
}
}
class Gui_ext {
Static __New() {
Gui.Prototype.SetDarkTitle := ObjBindMethod(this, "SetDarkTitle")
Gui.Prototype.SetDarkMenu := ObjBindMethod(this, "SetDarkMenu")
}
Static SetDarkTitle(_obj) {
if VerCompare(A_OSVersion, "10.0.17763") >= 0 {
attr := 19
if VerCompare(A_OSVersion, "10.0.18985") >= 0 {
attr := 20
}
if (DllCall("dwmapi\DwmSetWindowAttribute", "ptr", _obj.hwnd, "int", attr, "int*", true, "int", 4))
return true
}
return false
}
Static SetDarkMenu(_obj) {
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
if DllCall(FlushMenuThemes)
return true
return false
}
}
MyGui := Gui()
Edt01 := MyGui.AddEdit("w300 r3")
Edt01.SetCue("Edit Control Cue Text")
Edt01.SetDarkMode()
Edt02 := MyGui.AddComboBox("w300", ["test 1", "test 2"])
Edt02.SetCue("Enter text here")
Bttn01 := MyGui.AddButton(,"OK")
Bttn01.SetDarkMode()
MyGui.SetDarkTitle()
MyGui.SetDarkMenu()
MyGui.Show()