![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
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()]
![Thinking :think:](./images/smilies/icon_think.gif)
![Thinking :think:](./images/smilies/icon_think.gif)
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()