'Borderless' buttons on dark backgrounds

Put simple Tips and Tricks that are not entire Tutorials in this forum
just me
Posts: 5456
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?

    If you use e.g. Gui, Color, 808080 or a picture for the Gui background:

  1. Create a variable (e.g. CtrlColorBtnsBrush) containing a brush using a proper color:

    Code: [Select all] [Download] GeSHi © Codebox Plus

    CtlColorBtnsBrush := DllCall("Gdi32.dll\CreateSolidBrush", "UInt", 0x808080, "UPtr")
    Note: The color has to be specified in BGR (reversed order).

  2. Create a function (e.g. CtrlColorBtns()) which returnes right this brush:

    Code: [Select all] [Download] GeSHi © Codebox Plus

    CtlColorBtns() {
    Global CtlColorBtnsBrush
    Return CtlColorBtnsBrush

  3. Register the function as handler for WM_CTLCOLORBTN messages:

    Code: [Select all] [Download] GeSHi © Codebox Plus

    OnMessage(0x0135, "CtlColorBtns") ; WM_CTLCOLORBTN = 0x0135

  4. Create the Gui and the buttons and redraw the Gui once after the first Gui, Show, ... with WinSet, Redraw, ....

  5. 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] [Expand] [Download] (Sample.ahk)GeSHi © Codebox Plus

*Tested on Win 7 and 8*
User avatar
Posts: 422
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 0 guests