Jump to content

Recommended Posts

Posted (edited)

Using GUICtrlSetBkColor() to change the color of a button when pressed. When it presses another button, I want this one to go back to what the default color was.Help file doesn't specify a way to 'reset' it back to its default, and color-picking won't work as the default color scheme doesn't use a solid color on the buttons (there's a fade effect).I didn't see any other functions that could get the bkcolor property of a button either or else I'd store it prior to the initial change.Me thinks the only way to do this is to destroy the button and re-create it?

Edited by mechaflash213
  Reveal hidden contents

 

Posted

Look at GUICtrlGetColor in my signature as well as _Flash in my profile (under snippets.)

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Tested your example for GUICtrlGetColor(), noticed it uses _WinAPI_GetPixel() which only looks at the color of a single pixel in the control... which is exactly what it did in the output.

By default, the buttons have a gradient to them which the function can't get.

Also tried using _WinAPI_GetSysColor() with all of the parameters specified in the help file to no avail.

Edited by mechaflash213
  Reveal hidden contents

 

  • Moderators
Posted

mechaflash213,

Be very careful about colouring buttons. There is a bug deep in the core code (#376) which creates problems when buttons are coloured - it is so deep-seated that there is no chance of it being fixed any time soon, if ever. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

I'm with Melba23 on this one. I don't colour buttons not just because of the bug but also the 'tacky' look it adds to the UI. I'm content with using the default colour provided by Windows and from an article I read (no link I'm afraid) creating a UI that fits with the OS is better and easier for the end user to use,

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

I think this is the wrong way to go. Look here for a direction:http://msdn.microsoft.com/en-us/library/windows/desktop/bb761849(v=vs.85).aspx

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

Posted (edited)

I don't know whether is approach is a good idea but try it:

#include <ButtonConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>

Global $hGui = GUICreate("Test", 255, 178)
Global $iButton1 = GUICtrlCreateButton("Test 1", 38, 26, 75, 49)
GUICtrlSetBkColor(-1, 0xFFFF00)
Global $iButton2 = GUICtrlCreateButton("Reset 1", 38, 96, 75, 49)
Global $iButton3 = GUICtrlCreateButton("Test 2", 140, 26, 75, 49)
GUICtrlSetBkColor(-1, 0xFF0000)
Global $iButton4 = GUICtrlCreateButton("Reset 2", 140, 96, 75, 49)
GUISetState(@SW_SHOW)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
        Case $iButton1
            GUICtrlSetBkColor($iButton1, Random(0x600000, 0xFFFFFF, 1))
        Case $iButton2
            ResetButtonColor($hGUI, $iButton1, "iButton1")
        Case $iButton3
            GUICtrlSetBkColor($iButton3, Random(0x600000, 0xFFFFFF, 1))
        Case $iButton4
            ResetButtonColor($hGUI, $iButton3, "iButton3")
    EndSwitch
WEnd

Func ResetButtonColor($hGUI, $iButtonID, $sVar, $sHBtn = "") ;coded by UEZ 2012 build 2012-07-26
    Local $hButton = GUICtrlGetHandle($iButtonID)
    If Not $hButton Then Return SetError(1, 0, 0)
    If Not _WinAPI_IsClassName($hButton, "Button") Then Return SetError(2, 0, 0)
    If Not IsHWnd($hGUI) Then Return SetError(3, 0, 0)
    If Not IsDeclared($sVar) Then Return SetError(4, 0, 0)
    If $sHBtn And Not IsDeclared($sHBtn) Then Return SetError(5, 0, 0)
    Local $aPos = ControlGetPos($hGui, "", $iButtonID)
    If @error Then Return SetError(6, 0, 0)
    Local $iStyle = _WinAPI_GetWindowLong($hButton, $GWL_STYLE)
    If @error Then Return SetError(7, 0, 0)
    Local $iExStyle = _WinAPI_GetWindowLong($hButton, $GWL_EXSTYLE)
    If @error Then Return SetError(8, 0, 0)
    Local $sButtonText = _WinAPI_GetWindowText($hButton)
    If @error Then Return SetError(9, 0, 0)
    GUISwitch($hGUI)
    Local $hBtnBmp = _SendMessage($hButton, $BM_GETIMAGE, 0, 0, 0, "wparam", "lparam", "hwnd")
    Local $hBtnIco = _SendMessage($hButton, $BM_GETIMAGE, 1, 0, 0, "wparam", "lparam", "hwnd")
    GUISetState(@SW_LOCK, $hGUI)
    GUICtrlDelete($iButtonID)
    Local $iButton = GUICtrlCreateButton($sButtonText, $aPos[0], $aPos[1], $aPos[2], $aPos[3], $iStyle, $iExStyle)
    Local $hBtn = GUICtrlGetHandle($iButton)
    Assign($sVar, $iButton)
    If $sHBtn Then Assign($sButtonText, $hBtn)
    If $hBtnBmp Then _SendMessage($hBtn, $BM_SETIMAGE, 0, $hBtnBmp)
    If $hBtnIco Then _SendMessage($hBtn, $BM_SETIMAGE, 0, $hBtnIco)
    GUISetState(@SW_UNLOCK, $hGUI)
    Return 1
EndFunc

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

Posted

  On 7/26/2012 at 8:20 AM, 'UEZ said:

I don't know whether is approach is a good idea but try it:

It looks like you're just destroy/recreating the button?

  Reveal hidden contents

 

Posted

  On 7/26/2012 at 1:35 PM, 'UEZ said:

Yes, and that's why I think this is not the best approach.

Br,

UEZ

Currently I have it implemented that way. I separated the creation/destruction of the buttons in their own functions to make it easier, assigning them to a global array so any changes made will always be caught.

It works... but like you, I don't like taking this approach. However, I may not have a choice.

  Reveal hidden contents

 

Posted

For me it is very hard to understand the syntax of the C/C++ code which provided on many sites.

I tried it using subclassing to modify the color of the button but I failed.

Then this idea came up...

Br,

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

Posted

  On 7/26/2012 at 1:56 PM, 'Yashied said:

It's easy.

GUICtrlSetStyle($Button, 0)

LOLOLOLOLOLOL!

wow... it was that simple... I would've never thought to change it's style to reset it...

  Reveal hidden contents

 

Posted

I learnt something new today.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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