FrancescoDiMuro

Usage of _GUICtrlButton_SetImage

8 posts in this topic

Good morning everyone. I'm trying to do a simple thing, but, for now, it seems to be very difficult... Maybe, I'm missing something, so I'm asking here.

I'm trying to let an image be clickable, so, I found out the _GUICtrlButton_SetImage function, which seems to very powerful. But for me, it doesn't work! 

$Motore1 = GUICtrlCreateButton("Something",10,10,58,54)
_GUICtrlButton_SetImage($Motore1,"C:\Dynamics\PIC\LOCALI_HVAC181 - Copia.jpg")

In this case, the image should fit in the button, right? Can someone help me out, please? Thanks :)


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

Works only with BMP's and ICON's. For BMP's the style $BS_BITMAP must be used.

Share this post


Link to post
Share on other sites

I still can't use it... Even if I write this:
 

$Motore1 = GUICtrlCreateButton("",10,10,58,54,$BS_BITMAP)
_GUICtrlButton_SetImage($Motore1,"A.bmp")

Why? Thank you for your answer :)


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

FrancescoDiMuro,

If you create the button using the native function, then use the native function to set the image - see the script below.

Quote

I'm trying to let an image be clickable

Images are clickable - try clicking on both the button and image in this script:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>

$sImage = "M:\Program\AutoIt3\Examples\GUI\Advanced\Images\Red.bmp" ; Adjust to match your AutoIt installation path

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("", 10, 10, 80, 30, $BS_BITMAP)
GUICtrlSetImage($cButton, $sImage)

$cPic = GUICtrlCreatePic($sImage, 10, 100, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            MsgBox($MB_SYSTEMMODAL, "Button", "Button clicked")
        Case $cPic
            MsgBox($MB_SYSTEMMODAL, "Image", "Image clicked")
    EndSwitch

WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thank you M23! You're my Script Hero! Ahahahah :D Ok, I understood the use of native functions 

GUICtrlCreateButton

and 

GUICtrlSetImage

For the BMP... Are there any restrictions about the width and height of the image? And, If the image is in the same folder where the script is running, the function GUICtrlSetImage doesn't need the whole path where the image stands, is it right? Thank you M23. You're the one that manage to help me when I have problem with script... A very big thank you! :):):)


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

FrancescoDiMuro,

As far as I know there are no restrictions on the size of the BMP - just try with your image file and see if it works. And, yes, if the image file is in the same folder as the script then all you need is the filename.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Again a big thank you M23. Have a wonderful day! -Francesco


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

FrancescoDiMuro,

Glad I could help.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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