'Borderless' buttons on dark backgrounds

Put simple Tips and Tricks that are not entire Tutorials in this forum
just me
Posts: 8600
Joined: 02 Oct 2013, 08:51
Location: Germany

'Borderless' buttons on dark backgrounds

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?
  1. If you use e.g. Gui, Color, 808080 or a picture for the Gui background:
  2. Create a variable (e.g. CtrlColorBtnsBrush) containing a brush using a proper color:

    Code: Select all

    CtlColorBtnsBrush := DllCall("Gdi32.dll\CreateSolidBrush", "UInt", 0x808080, "UPtr")
    Note: The color has to be specified in BGR (reversed order).
  3. Create a function (e.g. CtrlColorBtns()) which returnes right this brush:

    Code: Select all

    CtlColorBtns() {
       Global CtlColorBtnsBrush
       Return CtlColorBtnsBrush
  4. Register the function as handler for WM_CTLCOLORBTN messages:

    Code: Select all

    OnMessage(0x0135, "CtlColorBtns") ; WM_CTLCOLORBTN = 0x0135
  5. Create the Gui and the buttons and redraw the Gui once after the first Gui, Show, ... with WinSet, Redraw, ....
  6. Done!
Because OnMessage() functions aren't Gui related as yet, multiple Guis will need some adjustment, but that should be feasible.

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

; 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


CtlColorBtns() {
   Global CtlColorBtnsBrush
   Return CtlColorBtnsBrush
*Tested on Win 7 and 8*
User avatar
Posts: 432
Joined: 29 Jan 2014, 21:39

Re: 'Borderless' buttons on dark backgrounds

22 Jul 2014, 12:00

Sweet! Thank you!

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest