'Borderless' buttons on dark backgrounds
Posted: 21 Jul 2014, 09:09
Playing around with the WM_CTLCOLOR... messages I stumbled over an interesting feature. At least on Win 7 and 8 all push buttons seem to send the WM_CTLCOLORBTN message to there parent window before they are redrawn. Most of what Microsoft states on MSDN seems to be pure nonsense. But, after some testing it seems, that the brush returned by the parent will be actually used to draw the button's background. This seems to solve the problem of the somewhat ugly appearance of themed push buttons on dark coloured backgrounds.
So, how to do it?
There's one disadvantage you will notice, the buttons don't seem to be proper aligned with other controls any more. As a workaround, you can adjust the position and size.
*Tested on Win 7 and 8*
So, how to do it?
- If you use e.g. Gui, Color, 808080 or a picture for the Gui background:
- Create a variable (e.g. CtrlColorBtnsBrush) containing a brush using a proper color:
Note: The color has to be specified in BGR (reversed order).
Code: Select all
CtlColorBtnsBrush := DllCall("Gdi32.dll\CreateSolidBrush", "UInt", 0x808080, "UPtr")
- Create a function (e.g. CtrlColorBtns()) which returnes right this brush:
Code: Select all
CtlColorBtns() { Global CtlColorBtnsBrush Return CtlColorBtnsBrush }
- Register the function as handler for WM_CTLCOLORBTN messages:
Code: Select all
OnMessage(0x0135, "CtlColorBtns") ; WM_CTLCOLORBTN = 0x0135
- Create the Gui and the buttons and redraw the Gui once after the first Gui, Show, ... with WinSet, Redraw, ....
- Done!
There's one disadvantage you will notice, the buttons don't seem to be proper aligned with other controls any more. As a workaround, you can adjust the position and size.
Code: Select all
#NoEnv
; MsgBox, PSPad Workaround!
CtlColorBtnsBrush := DllCall("Gdi32.dll\CreateSolidBrush", "UInt", 0x808080, "UPtr") ; BGR!!!
OnMessage(0x0135, "CtlColorBtns") ; WM_CTLCOLORBTN = 0x0135
Gui, +LastFound ; sets the last found window
Gui, Margin, 100, 50
Gui, Color, 808080
Gui, Add, Radio, w100 vRB1, Radio1
Gui, Add, Radio, xm y+10 w100 vRB2, Radio2
Gui, Add, CheckBox, w100 vCB, CheckBox
Gui, Add, Edit, xm w100 h30
Gui, Add, Button, xm y+2 w100 vPB, Button
Gui, Show, , Test
WinSet, Redraw ; uses th last found window
Return
GuiClose:
GuiEscape:
ExitApp
CtlColorBtns() {
Global CtlColorBtnsBrush
Return CtlColorBtnsBrush
}