Sign in to follow this  
Followers 0
cupcake

Restore button style after changing its color

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hey,

thank you for the quick reply. This looks better and more sophisticated.

Kind regards.

Edited by cupcake

Share this post


Link to post
Share on other sites

Or something like this :graduated: ?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("My GUI")
$c_Button = GUICtrlCreateButton("Button", 10, 10, 100, 30)
GUICtrlSetBkColor($c_Button, 0xff00)
GUISetState(@SW_SHOW)
Sleep(2000)
GUICtrlSetStyle($c_Button, $GUI_SS_DEFAULT_BUTTON)

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Share this post


Link to post
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
Sign in to follow this  
Followers 0