GUIs: change the highlight colour

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

GUIs: change the highlight colour

01 Mar 2019, 01:50

- I've been investigating setting the text/background colours for GUI controls.
- Something slightly different is the colour for a focused item/selected items/highlighted text.
- I was wondering what scripts we have for setting that colour in various controls e.g. Edit controls, in internal/external processes. Thanks.

- So far I've found the following scripts. Thanks just me.
[SOLVED] Custom selected color in ListView - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=122
[SOLVED] Gui ListBox Hightlight Color - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=3938
TV_SetSelColors - user defined colors for selected/focused/highlighted TreeView itemsed - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=17877

- So that's: ListBox, SysListView32, SysTreeView32. Other candidates would be: ComboBox (which could reuse code from ListBox) and Scintilla (covered below).
- I would be in interested in Edit/RichEdit controls also, however, I believe that there isn't built-in support for changing these, other than by changing the system-wide settings.

- Here's some code for the Scintilla control.

Code: Select all

q:: ;scintilla control - set selection foreground/background colours
;note: colours are BGR
SendMessage, 2067, 1, 0x0000FF, Scintilla1, A ;SCI_SETSELFORE := 2067
PostMessage, 2068, 1, 0xFF0000, Scintilla1, A ;SCI_SETSELBACK := 2068
return

- Here's some code for changing the system-wide settings. It reports the current settings, changes them for 5 seconds, then restores the previous settings.

Code: Select all

q:: ;get/set system-wide highlight colours
;get colours
;COLOR_HIGHLIGHT := 13 ;COLOR_HIGHLIGHTTEXT := 14
vColBGR := DllCall("user32\GetSysColor", Int,13, UInt)
vColRGB1 := ((0xFF & vColBGR) << 16) + (0xFF00 & vColBGR) + ((0xFF0000 & vColBGR) >> 16)
vColBGR := DllCall("user32\GetSysColor", Int,14, UInt)
vColRGB2 := ((0xFF & vColBGR) << 16) + (0xFF00 & vColBGR) + ((0xFF0000 & vColBGR) >> 16)
MsgBox, % Format("0x{:06X}`r`n0x{:06X}", vColRGB1, vColRGB2)

;set colours
vColRGB := 0xFFFF00 ;yellow
vColBGR := ((0xFF & vColRGB) << 16) + (0xFF00 & vColRGB) + ((0xFF0000 & vColRGB) >> 16)
DllCall("user32\SetSysColors", Int,1, IntP,14, UIntP,vColBGR)
;vColRGB := 0xABCDEF ;azure
vColRGB := 0x008000 ;dark green
vColBGR := ((0xFF & vColRGB) << 16) + (0xFF00 & vColRGB) + ((0xFF0000 & vColRGB) >> 16)
DllCall("user32\SetSysColors", Int,1, IntP,13, UIntP,vColBGR)

Sleep, 5000

;set colours
;vColRGB := 0xFFFFFF ;white
vColRGB := vColRGB2
vColBGR := ((0xFF & vColRGB) << 16) + (0xFF00 & vColRGB) + ((0xFF0000 & vColRGB) >> 16)
DllCall("user32\SetSysColors", Int,1, IntP,14, UIntP,vColBGR)
;vColRGB := 0x3399FF ;dark blue
vColRGB := vColRGB1
vColBGR := ((0xFF & vColRGB) << 16) + (0xFF00 & vColRGB) + ((0xFF0000 & vColRGB) >> 16)
DllCall("user32\SetSysColors", Int,1, IntP,13, UIntP,vColBGR)
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot] and 202 guests