gil900

GUIImageButton* - Create GDIP button with image and with frame

1 post in this topic

#1 ·  Posted (edited)

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 gil900
2 people like this

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

  • Similar Content

    • Skeletor
      By Skeletor
      MS Splash Screens
      The office 2016/17 office suite has made many people turn heads with its functions and especially their splash screen.
      I now present to you, the MS Style Splash Screen. For Rookies, Novices and anyone who wants a ready made splash screen for your gui application.

      You can now download it and also try it out yourself.
      You have three colors to choose from:
      Blue
      Red
      Green
      All three colours are from the famous programs.
      I also included the KODA form to you can have freedom with this splash screen.
      Note: the KODA form does not have the three colours as well as the correct blue. 

      Have fun and enjoy.
      Note:
      I will update the splash to add the automated 3 dots animation at a later stage. 
       
       
    • Skeletor
      By Skeletor
      A gui splash screen. Themed after the famous MS Office Suite.
      Three colours to choose from, Red, Blue and Green.
      You can change the labels to your own application.

      Also bundled with this is the KODA form. So you can open up and see the basic structure of this splash screen.
       
      Splash Screen GUI.zip
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
    • SteveJM
      By SteveJM
      I have a working program currently driven largely through menu selections. I would like to add a toolbar where most of the tollbar button actions are basically the same as menu items, but quicker to access. I have been wading around in toolbar examples, MSDN pages etc, it's clearly going to be a bit of a slog to get everything right, including tooltips etc. I thought I would start with something simple to prove the principle.
      Using bits from the help file examples I have a small program that successfully displays a toolbar. However, what seemed like the most elegant way to deal with the button commands does not seem to work. My understanding was that a toolbar button fires a WM_COMMAND message, with the command Id set by the second parameter in the call to
      _GUICtrlToolbar_AddButton ( $hWnd, $iID, $iImage)
      so I though it would be a good idea to set this Id to the same value as my menu item Id; then it would run the same task which is what I wanted. This did not work. I am using message loop mode and would like to stick with this because some of my scripts run hardware at the same time as the gui; it is easier if I don't have to worry about code being interrupted with the hardware in an unknown state . So I added a handler for WM_COMMAND, with some cribbed display code to try and see why. The toolbar button defintely fired a WM_COMMAND message and the Id looked the same, so no explanation there.
      I guess the issue is with GUIGetMsg() which may be constructed to ignore all but a limited number of control handles, i.e. those made with the GuiCtrlCreate... commands; this is speculation.
      I would dearly love to find a tidy way to get around this. Having some controls handled in the message loop and some in a WM_COMMAND handler, performing the same task, feels ugly. I would be very grateful for further insight from someone experienced with handling a toolbar. Perhaps I should be trying to fire the menu item. I have attached a code snippet to try and illustrate the issue.
       
       
       
      ToolbarTrial.au3
    • XinYoung
      By XinYoung
      Hello all,
      I've been working on 4 standalone scripts. They each have their own GUI and are now independent .exe's. But instead of having 4 separate icons on my computer, is it possible to put them all together into one .exe?
      What I want is one interface with tabs. Each script's GUI would be on their own respective tab. Is this possible?
      The different scripts don't need to communicate with one another. I just want them all in one .exe.
      I can't find this anywhere... Any help would be greatly appreciated. Thank you!