Jump to content
Sign in to follow this  

How do I unset an image?

Recommended Posts


I know this will work to set an image on a button

$but_pic = GUICtrlCreateButton('test',20,20,64,64,$BS_BITMAP)

But how do I unset it???

Edited by madflame991

Share this post

Link to post
Share on other sites


Share this post

Link to post
Share on other sites

a little demo

stick with the GUICtrlSetStyle() function method

Edit: added GUICtrlSetState($Objects, $GUI_ENABLE) to $StyleON

added missing function _GUICtrlButton_GetImage() (from GuiButton.au3) for compatibility

; Demo works in and up (beta)
; BM_GETIMAGE constant needed for
; uses GUIButton management UDF's in beta
; replace bmp file with your own

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>
;#include <GuiButton.au3> ; v3.2.11.0 and up
;Global Const $BM_GETIMAGE = 0xF6 ; included in ButtonConstants.au3 for and up

Opt("GUIOnEventMode", 1)
Local $btn, $chk, $rdo, $Msg
Local $sPath = @WindowsDir & "\pchealth\helpctr\System\images\48x48\desktop_icon_01.bmp"
Local $hgui = GUICreate("Delete bitmap/icon - Change style", 300, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Events")

$Objects = GUICtrlCreateButton("Remove Bitmap/Icon", 10, 80, 120, 30)
GUICtrlSetOnEvent(-1, "_Events")
GUICtrlCreateLabel("Bitmap or Icon style remains", 150, 88, 140, 30)

$StyleOFF = GUICtrlCreateButton("Button style OFF", 10, 120, 120, 30)
GUICtrlSetOnEvent(-1, "_Events")
GUICtrlCreateLabel("Default styles set, text shown", 150, 128, 140, 30)

$StyleON = GUICtrlCreateButton("Button style ON", 10, 160, 120, 30)
GUICtrlSetOnEvent(-1, "_Events")
GUICtrlCreateLabel("Bitmap/Icon styles set, text hidden", 150, 168, 140, 30)

$btn = GUICtrlCreateButton("Button1", 10, 10, 50, 50, $BS_BITMAP)
GUICtrlSetImage(-1, $sPath)
;_GUICtrlButton_SetImage($btn, $sPath) ; v3.2.11.0 and up
GUICtrlSetOnEvent(-1, "_Events")

$chk = GUICtrlCreateCheckbox("Check1", 70, 10, 55, 32, $BS_ICON)
GUICtrlSetImage($chk, "shell32.dll", 14, True)
;_GUICtrlButton_SetImage($chk, "shell32.dll", 14, True) ; v3.2.11.0 and up
GUICtrlSetOnEvent(-1, "_Events")

$rdo = GUICtrlCreateRadio("Radio1", 140, 10, 50, 32, $BS_ICON)
GUICtrlSetImage($rdo, "shell32.dll", 21, True)
;_GUICtrlButton_SetImage($rdo, "shell32.dll", 21, True) ; v3.2.11.0 and up
GUICtrlSetOnEvent(-1, "_Events")

While 1

Func _Events()
    Switch @GUI_CtrlId
        Case $Objects
            ; delete bitmap/icon, style remains $BS_BITMAP and $BS_ICON, no text on buttons
            _WinAPI_DeleteObject(_GUICtrlButton_GetImage(GUICtrlGetHandle($btn))) ; delete bitmap
            _WinAPI_InvalidateRect(GUICtrlGetHandle($btn), 0, True) ; repaint control
            _WinAPI_DestroyIcon(_GUICtrlButton_GetImage(GUICtrlGetHandle($chk))) ; delete icon
            _WinAPI_InvalidateRect(GUICtrlGetHandle($chk), 0, True) ; repaint control
            _WinAPI_DestroyIcon(_GUICtrlButton_GetImage(GUICtrlGetHandle($rdo))) ; delete icon
            _WinAPI_InvalidateRect(GUICtrlGetHandle($rdo), 0, True) ; repaint control
            GUICtrlSetState($Objects, $GUI_DISABLE)
            GUICtrlSetState($StyleON, $GUI_DISABLE)
        Case $StyleOFF
            ; reset button styles to default
            GUICtrlSetStyle($btn, $GUI_SS_DEFAULT_BUTTON) ; _GUICtrlButton_SetStyle($hWnd, $iStyle) v3.2.11.0 and up
            GUICtrlSetStyle($chk, $BS_AUTOCHECKBOX)
            GUICtrlSetStyle($rdo, $BS_AUTORADIOBUTTON)
            GUICtrlSetState($Objects, $GUI_DISABLE)
        Case $StyleON
            GUICtrlSetStyle($btn, $BS_BITMAP)
            GUICtrlSetStyle($chk, BitOR($BS_AUTOCHECKBOX, $BS_ICON))
            GUICtrlSetStyle($rdo, BitOR($BS_AUTORADIOBUTTON, $BS_ICON))
            GUICtrlSetState($Objects, $GUI_ENABLE)
        Case $btn
        Case $chk
        Case $rdo
        Case $GUI_EVENT_CLOSE
EndFunc   ;==>_Events

; taken from beta v3.2.11.3 #include <GuiButton.au3>
Func _GUICtrlButton_GetImage($hWnd) ; v3.2.11.0 and up
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $iResult = _SendMessage($hWnd, $BM_GETIMAGE, 0, 0, 0, "wparam", "lparam", "hwnd") ; check IMAGE_BITMAP
    If $iResult <> 0x00000000 Then Return $iResult
    $iResult = _SendMessage($hWnd, $BM_GETIMAGE, 1, 0, 0, "wparam", "lparam", "hwnd") ; check IMAGE_ICON
    If $iResult = 0x00000000 Then Return 0
    Return $iResult
EndFunc   ;==>_GUICtrlButton_GetImage
Edited by rover

I see fascists...

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.