Jump to content
Sign in to follow this  
Luigi

how to set and unset a bkColor and icon?

Recommended Posts

Luigi

Hi, I try set color and icon on button, it's work... but how do inverse? unset color... if possible no repaint with default color (or the best way to do), any way to back original state?

And how to change from color to icon and reverse?

Thanks a lot.

#include
#include

Global $hGui, $setIcon, $setColor, $noIcon, $noColor, $target
Global $color = "0x00ff00"

$hGui = GUICreate("Icon & Color", 400, 200)
$setIcon = GUICtrlCreateButton("set icon", 20, 50, 80, 20)
$setColor = GUICtrlCreateButton("set color", 300, 50, 80, 20)
$noIcon = GUICtrlCreateButton("no icon", 20, 90, 80, 20)
$noColor = GUICtrlCreateButton("no color", 300, 90, 80, 20)
$target = GUICtrlCreateButton("", 150, 30, 100, 100, $BS_ICON)

GUISetState()

While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $setIcon
ConsoleWrite("setIcon[" & GUICtrlSetImage($target, "c:\windows\system32\explorer.exe", 0) & "]" & @LF)
Case $setColor
ConsoleWrite("setColor[" & GUICtrlSetBkColor($target, $color) & "]" & @LF)
Case $noIcon
ConsoleWrite("noIcon[" & GUICtrlSetImage($target, 0) & "]" & @LF)
Case $noColor
ConsoleWrite("noColor" & @LF)
EndSwitch
WEnd

Whit this code, I can change between color to icon in the same button, but still i can't remove icon or remove color...

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

Global $hGui, $setIcon, $setColor, $noIcon, $noColor, $target
Global $color = "0x00ff00"

$hGui = GUICreate("Icon & Color", 400, 200)
$setIcon = GUICtrlCreateButton("set icon", 20, 50, 80, 20)
$setColor = GUICtrlCreateButton("set color", 300, 50, 80, 20)
$noIcon = GUICtrlCreateButton("no icon", 20, 90, 80, 20)
$noColor = GUICtrlCreateButton("no color", 300, 90, 80, 20)
$target = GUICtrlCreateButton("", 150, 30, 100, 100)
$iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($target), $GWL_STYLE)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $setIcon
            GUICtrlSetStyle($target, BitOR($iStyle, $BS_ICON))
            GUICtrlSetImage($target, "shell32.dll", 22)
        Case $setColor
            ;$iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($target), $GWL_STYLE)
            GUICtrlSetBkColor($target, 0x00ff00)
        Case $noIcon
            ;$iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($target), $GWL_STYLE)
            GUICtrlSetStyle($target, BitXOR($iStyle, $BS_ICON))
            GUICtrlSetImage($target, 0, -1)
            ;GUICtrlSetStyle($target, BitAND($iStyle, BitNOT($BS_ICON)))
        Case $noColor
            ;$iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($target), $GWL_STYLE)

    EndSwitch
WEnd

;    $iStyle   = _WinAPI_GetWindowLong(GUICtrlGetHandle($iControlID), $GWL_STYLE)
;    $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($iControlID), $GWL_EXSTYLE)

;Once you have the current value then you can easily add or subtract other styles from it.

;    Adding a new style is simple - we just use BitOR as we have already seen:

;GUICtrlSetStyle($target, BitOR($iOldStyleValue, $iNewStyle))

;    Subtracting a style can be done in two ways - although one is much easier to use:

;GUICtrlSetStyle($target, BitXOR($iOldStyleValue, $iStyleToRemove))
;GUICtrlSetStyle($iControlID, BitAnd($iOldStyleValue, BitNOT($iStyleToRemove)))
Edited by detefon

Visit my repository

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.