Jump to content

GUIImageButton* - Create GDIP button with image and with frame


Guest
 Share

Recommended Posts

Hello,

I worte this:

example.gif.767e7cb7df346dc7d85cf1265f4f

$hGUI = GUICreate('', 326, 260, 312, 159)
WinSetOnTop($hGUI,'',1)
GUISetBkColor(0xF5FF82)

GUISetState(@SW_SHOW)

 _GDIPlus_Startup()


$hGUI_hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)

$Button1Image = @ScriptDir&'\button.png'
; $Button1Image = 'img_button' ; <- Activate this line if you want the image to be loaded from resources

$Button2Image = @ScriptDir&'\button2.png'
; $Button2Image = 'img_button2' ; <- Activate this line if you want the image to be loaded from resources


$Button = GUIImageButton_Create($hGUI_hGraphics,$Button1Image,95, 72)

Sleep(1000)

; Set frame for the button
GUIImageButton_SetSquareFrame($hGUI,$hGUI_hGraphics,$Button,10,0xFF00A300)

Sleep(1000)

; Set the image button2.png for the button
GUIImageButton_SetNewImage($hGUI_hGraphics,$Button,$Button2Image)

Sleep(1000)

; Set the image button1.png for the button
GUIImageButton_SetNewImage($hGUI_hGraphics,$Button,$Button1Image)

Sleep(1000)

; Set new frame instead of the previous
GUIImageButton_SetSquareFrame($hGUI,$hGUI_hGraphics,$Button,5,0xFFFF0505)

Sleep(1000)

; Remove the frame from the button
GUIImageButton_RemoveSquareFrame($hGUI,$Button)

Sleep(1000)

; Set frame again
GUIImageButton_SetSquareFrame($hGUI,$hGUI_hGraphics,$Button,1)

Sleep(1000)



; Remove only the image from the button
GUIImageButton_CleanGraphics($hGUI,$Button,0)
; If the 3 parameter is 1 then it will clean also the frame. *It will not remove the button! only clean the visual output

Sleep(1000)

; Set the image button2.png for the button
GUIImageButton_SetNewImage($hGUI_hGraphics,$Button,$Button2Image)


; This will remove the button. you can call it without calling GUIImageButton_CleanGraphics before

;~ GUIImageButton_Delete($hGUI,$Button1)
;~ Do
;~ Until GUIGetMsg() = $GUI_EVENT_CLOSE



; To use the button just:


; This will not work if you activated line 80 and will not work during the sleeps...
ConsoleWrite('listening to $Button:' & @CRLF)
While Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button[0] ; <- *[0]
            ConsoleWrite('$Button1 Clicked' & @CRLF)
    EndSwitch
WEnd








; #FUNCTION# ====================================================================================================================
; Name ..........: GUIImageButton_Create
; Description ...: Create button with image
; Syntax ........: GUIImageButton_Create($hGUI_hGraphics, $Image, $x_pos, $y_pos[, $x_size = Default[, $y_size = Default]])
; Parameters ....: $hGUI_hGraphics      - value of _GDIPlus_GraphicsCreateFromHWND($hGUI)
;                  $Image               - Can be path the the image file or resource name
;                  $x_pos               - the x pos of the image in the GUI.
;                  $y_pos               - the y pos of the image in the GUI.
;                  $x_size              - [optional] the x size of the image
;                  $y_size              - [optional] the y size of the image
;                                       ** x size and y size must be the same as the real xy size of the image file!
; Return values .: Button handle (Array):
;                   [0] is the ctrl id and this is the only important thing. [1] & [2] are for internal use only
; Author ........: gil900
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================



; #FUNCTION# ====================================================================================================================
; Name ..........: GUIImageButton_SetSquareFrame
; Description ...: Create frame around the button
; Syntax ........: GUIImageButton_SetSquareFrame($hGUI, $hGUI_hGraphics, Byref $aButton[,$iLineWidth = 1 [,
;                  $LineColor_rgba = 0xFF000000]])
; Parameters ....: $hGUI                - A handle for the GUI
;                  $hGUI_hGraphics      - value of _GDIPlus_GraphicsCreateFromHWND($hGUI).
;                  $aButton             - value of GUIImageButton_Create
;                  $iLineWidth          - [optional] The width in pixels of the frame. Default is 1.
;                  $LineColor_rgba      - [optional] the color value - [0xFF & RGB code].
;                                       Default is 0xFF000000.
; Return values .: None
; Author ........: gil900
; ===============================================================================================================================




; #FUNCTION# ====================================================================================================================
; Name ..........: GUIImageButton_SetNewImage
; Description ...: Set new image over the previous one. ** The new image must be the same size!
; Syntax ........: GUIImageButton_SetNewImage($hGUI_hGraphics, $aButton, $Image)
; Parameters ....: $hGUI_hGraphics      - value of _GDIPlus_GraphicsCreateFromHWND($hGUI).
;                  $aButton             - value of GUIImageButton_Create
;                  $Image               - Can be path the the image file or resource name
; Return values .: None
; Author ........: gil900
; ===============================================================================================================================



; #FUNCTION# ====================================================================================================================
; Name ..........: GUIImageButton_RemoveSquareFrame
; Description ...: Remove only the frame around the image(if exists)
; Syntax ........: GUIImageButton_RemoveSquareFrame($hGUI, Byref $aButton)
; Parameters ....: $hGUI                - A handle for the GUI
;                  $aButton             - value of GUIImageButton_Create
; Return values .: None
; Author ........: gil900
; Example .......: No
; ===============================================================================================================================


; #FUNCTION# ====================================================================================================================
; Name ..........: GUIImageButton_Delete
; Description ...: Remove the button
; Syntax ........: GUIImageButton_Delete($hGUI, Byref $aButton)
; Parameters ....: $hGUI                -  A handle for the GUI
;                  $aButton             - value of GUIImageButton_Create
; Return values .: None
; Author ........: gil900
; ===============================================================================================================================


; #FUNCTION# ====================================================================================================================
; Name ..........: GUIImageButton_CleanGraphics
; Description ...: Clean ONLY the graphics of the button. Can clean only the image without the frame or the image+frame((if exists))
;                  * It will not delete the button.
; Syntax ........: GUIImageButton_CleanGraphics($hGUI, Byref $aButton[, $CleanFrame = 1])
; Parameters ....: $hGUI                - A handle for the GUI
;                  $aButton             - value of GUIImageButton_Create
;                  $CleanFrame          - [optional] 1 = clean image+frame(if exists)
;                                                    2 = clean image only
;                                       . Default is 1.
; Return values .: None
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================

 

Download full code with the images:

GUIImageButton - r2.rar

GUIImageButton.rar

Tested on Autoit 3.3.14.2

If the title is not good enough then you can edit it and and write better one.

 

Hope you found it useful. If so then please leave a comment. It took a long time to share this piece of code with the documentation

Edited by Guest
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

×
×
  • Create New...