Jump to content

Restore button style after changing its color


cupcake
 Share

Recommended Posts

Hi,

after I changed a buttons color, I want to restore the initial style (3D, Windows-grey).

Here is the code, the button is supposed to be blinking:

GUICtrlSetBkColor($buttoncontrol, 0xff00) ;green
Sleep($2000)
GUICtrlSetBkColor($buttoncontrol, ??? ) ;back to normal
Sleep($2000)
GUICtrlSetBkColor($buttoncontrol, 0xff00) ;green

What I did in the past was this:

GUICtrlDelete($buttoncontrol)
$buttoncontrol = GUICtrlCreateButton("", 125, 260, 100, 30)
GUICtrlSetState($buttoncontrol, $GUI_SHOW)

But this seems to be a weird work around. I hope there is a better way :graduated:

Thanks for your help.

Edited by cupcake
Link to comment
Share on other sites

Try this:

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 245, 151, 192, 124)
$Button = GUICtrlCreateButton("Reset Color", 37, 23, 171, 105)
$hButton = GUICtrlGetHandle($Button)

$Button_Style = _WinAPI_GetWindowLong($hButton, $GWL_STYLE)
$Button_ExStyle = _WinAPI_GetWindowLong($hButton, $GWL_EXSTYLE)
$Button_DefColor = _WinAPI_GetSysColor($COLOR_BTNFACE)

GUISetState(@SW_SHOW)
GUICtrlSetBkColor($Button, 0xA0F0A0)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            GUICtrlSetBkColor($Button, $Button_DefColor)
            _WinAPI_SetWindowLong($hButton, $GWL_STYLE, $Button_Style)
            _WinAPI_SetWindowLong($hButton, $GWL_EXSTYLE, $Button_ExStyle)
            _WinAPI_RedrawWindow($hButton)
    EndSwitch
WEnd

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...