SlimShady Posted June 21, 2009 Share Posted June 21, 2009 How do you clear the icon after you've set it? Test code: #include <ButtonConstants.au3> #Include <GuiButton.au3> #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) GUICreate("My GUI") ; will create a dialog box that when displayed is centered dim $btn1 = GUICtrlCreateButton("my picture button", 10, 20, 40, 40, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", 22) dim $btn2 = GUICtrlCreateButton("Clear", 65, 20, 80, 50) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $btn2 GUICtrlSetImage($btn1, ''); Case $GUI_EVENT_CLOSE GUIDelete(); Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
SlimShady Posted June 21, 2009 Author Share Posted June 21, 2009 I also discovered a bug related to buttons and icons. It crashed afterwards. I will minimize my script to reproducible code and add it to the bugtracker. Link to comment Share on other sites More sharing options...
rover Posted June 21, 2009 Share Posted June 21, 2009 (edited) an update of my post here:How do I unset an image?Edit1: fixed radio button sizeEdit2: updated 4th param for GUICtrlSetImage() calls from v3.2.10.0expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <SendMessage.au3> #include <GuiButton.au3> 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) GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "_Events") GUISetState() $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) GUICtrlSetOnEvent(-1, "_Events") $chk = GUICtrlCreateCheckbox("Check1", 70, 10, 55, 32, $BS_ICON) GUICtrlSetImage($chk, "shell32.dll", 14, 1) ;_GUICtrlButton_SetImage($chk, "shell32.dll", 14, True) GUICtrlSetOnEvent(-1, "_Events") $rdo = GUICtrlCreateRadio("Radio1", 140, 10, 55, 32, $BS_ICON) GUICtrlSetImage($rdo, "shell32.dll", 21, 1) ;_GUICtrlButton_SetImage($rdo, "shell32.dll", 21, True) GUICtrlSetOnEvent(-1, "_Events") While 1 Sleep(10000) WEnd 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 ;optionally reset styles instead of InvalidateRect() ;GUICtrlSetStyle($btn, $GUI_SS_DEFAULT_BUTTON); _GUICtrlButton_SetStyle($hWnd, $iStyle) ;GUICtrlSetStyle($chk, $BS_AUTOCHECKBOX) ;GUICtrlSetStyle($rdo, $BS_AUTORADIOBUTTON) ;GUICtrlSetImage($rdo, "shell32.dll", 25, True) GUICtrlSetState($Objects, $GUI_DISABLE) GUICtrlSetState($StyleON, $GUI_DISABLE) Case $StyleOFF ; reset button styles to default, text on buttons GUICtrlSetStyle($btn, $GUI_SS_DEFAULT_BUTTON); _GUICtrlButton_SetStyle($hWnd, $iStyle) GUICtrlSetStyle($chk, $BS_AUTOCHECKBOX) GUICtrlSetStyle($rdo, $BS_AUTORADIOBUTTON) GUICtrlSetState($Objects, $GUI_DISABLE) Case $StyleON ; reset button styles to $BS_BITMAP and $BS_ICON using existing bitmaps of each control GUICtrlSetStyle($btn, BitOR($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) GUICtrlSetStyle($chk, BitOR($BS_AUTOCHECKBOX, $BS_ICON)) GUICtrlSetStyle($rdo, BitOR($BS_AUTORADIOBUTTON, $BS_ICON)) GUICtrlSetState($Objects, $GUI_ENABLE) Case $btn Beep(1000,5) Case $chk Beep(1000,5) Case $rdo Beep(1000,5) Case $GUI_EVENT_CLOSE Exit EndSwitch EndFunc;==>_Events Edited June 21, 2009 by rover I see fascists... Link to comment Share on other sites More sharing options...
SlimShady Posted June 21, 2009 Author Share Posted June 21, 2009 (edited) It had to be more simple than that. But thanks anyways. I got it fixed with _Sendmessage. #Include <GuiButton.au3> #include <SendMessage.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Global Const $IMAGE_ICON = 0x0001; GUICreate("My GUI") ; will create a dialog box that when displayed is centered dim $btn1 = GUICtrlCreateButton("", 10, 20, 40, 40, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", 22) dim $btn2 = GUICtrlCreateButton("Clear", 65, 20, 80, 50) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $btn2 _SendMessage(GUICtrlGetHandle($btn1), $BM_SETIMAGE, $IMAGE_ICON, 0) Case $GUI_EVENT_CLOSE GUIDelete(); Exit EndSwitch WEnd Edited June 21, 2009 by SlimShady Link to comment Share on other sites More sharing options...
BigDod Posted June 22, 2009 Share Posted June 22, 2009 Here is another way #Include <GuiButton.au3> #include <SendMessage.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Global Const $IMAGE_ICON = 0x0001; GUICreate("My GUI") ; will create a dialog box that when displayed is centered dim $btn1 = GUICtrlCreateButton("", 10, 20, 40, 40, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", 22) dim $btn2 = GUICtrlCreateButton("Clear", 65, 20, 80, 50) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $btn2 GUICtrlSetImage($btn1,"shell32.dll", -50) Case $GUI_EVENT_CLOSE GUIDelete(); Exit EndSwitch WEnd Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
martin Posted June 22, 2009 Share Posted June 22, 2009 Here is another way #Include <GuiButton.au3> #include <SendMessage.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Global Const $IMAGE_ICON = 0x0001; GUICreate("My GUI") ; will create a dialog box that when displayed is centered dim $btn1 = GUICtrlCreateButton("", 10, 20, 40, 40, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", 22) dim $btn2 = GUICtrlCreateButton("Clear", 65, 20, 80, 50) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $btn2 GUICtrlSetImage($btn1,"shell32.dll", -50) Case $GUI_EVENT_CLOSE GUIDelete(); Exit EndSwitch WEnd Hey, someone's left the padlock off the chat room door again! Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
BigDod Posted June 23, 2009 Share Posted June 23, 2009 Hey, someone's left the padlock off the chat room door again!I was bored and seen that no-one else answered the question Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now