Jump to content

Need help with image on button


Xopar
 Share

Recommended Posts

Hey,

Let me explain my problem:

I have 3 buttons.

First one is empty button that will have a bitmap image on it.

Second button creates image on the first button from file.

Last button needs to delete the image on the first button when I click the last button, so the first button should become empty as it was when I created it.

I need help with the code of last button.

My example script:

#include <GUIConstants.au3>
#include <ButtonConstants.au3>

#Region ### START Koda GUI section ### Form=
$test = GUICreate("Test", 263, 121, 357, 220)
$PicButton = GUICtrlCreateButton("", 24, 24, 73, 57, $BS_BITMAP)
$DeletePic = GUICtrlCreateButton("Delete 1st button's image", 160, 8, 65, 49, $BS_MULTILINE)
$CreatePic = GUICtrlCreateButton("Create image", 160, 72, 73, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CreatePic
            GUICtrlSetImage($PicButton, "C:\Pic.bmp", 0) ;This button creates image on the "$PicButton"

        Case $DeletePic
            ; I need a code that deletes the bitmap image on the "$PicButton" when I click this button.
    EndSwitch
WEnd
Link to comment
Share on other sites

Quick Search and I got this >Example.

Example use of Function:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7

#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <WinAPIRes.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('GUICtrlDeleteImage()', 250, 250)
    Local $iImage = GUICtrlCreateIcon(@AutoItExe, 0, 5, 5, 32, 32)
    Local $iDelete = GUICtrlCreateButton('Delete', 160, 5, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $iDelete
                GUICtrlDeleteImage($iImage)

        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc   ;==>Example

; #FUNCTION# ====================================================================================================================
; Name ..........: GUICtrlDeleteImage
; Description ...: Delete an image set by GUICtrlSetImage().
; Syntax ........: GUICtrlDeleteImage($iCtrlID)
; Parameters ....: $iCtrlID             - A valid controlid.
; Return values .: Success - True
;                  Failure - False
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func GUICtrlDeleteImage($iCtrlID)
    Local Const $STM_SETIMAGE = 0x0172
    Local $aSetImage = 0, _
            $bReturn = True, _
            $iMsg = 0
    Switch _WinAPI_GetClassName($iCtrlID)
        Case 'Button' ; button, checkbox, groupbox, radiobutton.
            Local $aButton = [$IMAGE_BITMAP, $IMAGE_ICON]
            $aSetImage = $aButton
            $aButton = 0
            $iMsg = $BM_SETIMAGE

        Case 'Static' ; icon, label, picture.
            Local $aStatic = [$IMAGE_BITMAP, $IMAGE_CURSOR, $IMAGE_ICON]
            $aSetImage = $aStatic
            $aStatic = 0
            $iMsg = $STM_SETIMAGE

        Case Else
            $bReturn = False

    EndSwitch
    If $bReturn Then
        $bReturn = False
        Local $hImage = 0
        For $i = 0 To UBound($aSetImage) - 1
            $hImage = GUICtrlSendMsg($iCtrlID, $iMsg, $aSetImage[$i], 0)
            If $hImage <> 0 Then
                Switch $aSetImage[$i]
                    Case $IMAGE_BITMAP
                        $bReturn = _WinAPI_DeleteObject($hImage)
                    Case $IMAGE_CURSOR
                        $bReturn = _WinAPI_DeleteObject($hImage)
                        If Not $bReturn Then
                            $bReturn = _WinAPI_DestroyCursor($hImage) > 0
                        EndIf
                    Case $IMAGE_ICON
                        $bReturn = _WinAPI_DeleteObject($hImage)
                        If Not $bReturn Then
                            $bReturn = _WinAPI_DestroyIcon($hImage) > 0
                        EndIf
                EndSwitch
                ExitLoop
            EndIf
        Next
        If Not $bReturn Then
            $bReturn = GUICtrlSetImage($iCtrlID, 'shell32.dll', -50) > 0 ; Super hacky!
        EndIf
    EndIf
    Return $bReturn
EndFunc   ;==>GUICtrlDeleteImage
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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
 Share

  • Recently Browsing   0 members

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