Jump to content
Sign in to follow this  
Mat

$hWnd ? (understood at last)

Recommended Posts

Mat

Right now i'm trying to set an image as a button, this is the script from the help file;

#Include <GuiButton.au3>
_GUICtrlButton_SetImage([u][b]$hWnd[/b][/u], $sImageFile[, $nIconId = -1[, $fLarge = False]])

here is my script:

$Start = _GUICtrlButton_Create("Start", -1, 0, 65, 30, $BS_BITMAP)
   _GUICtrlButton_SetImage(????????, $Start, $sPath & "\Start.bmp")

everything else is fine - except The "Handle to the control".

sorry for being a noob

Mdiesel

Edited by mdiesel

Share this post


Link to post
Share on other sites
GaryFrost

Error:

Invalid Window handle for _GUICtrlButton_Create 1st parameter

Your missing the handle to the gui for the 1st param


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Mat

Your missing the handle to the gui for the 1st param

.... I guessed almost that much....

what I was trying to ask is what the value should be...

If someone could give it to me in english it would be nice too...

Share this post


Link to post
Share on other sites
Melba23

mdiesel,

This is my understanding of how it works - the purists will probably find it lacking, but it will do for you and me.;-)

When you create "something" in Windows, it is identified by a "handle" - a unique identifier so that everyone/everything knows how to address the "something".

When you create "something" in Autoit, it is given a "ControlID", unique to that script - and of course Windows gives it a "handle" as well.

You can determine the handle from the ControlID (WinGetHandle & ControlGetHandle) and the ControlID from the handle (_WinAPI_GetDlgCtrlID).

Internally, Autoit usually uses the ControlID, so in the case you posted:

$Start = _GUICtrlButton_Create("Start", -1, 0, 65, 30, $BS_BITMAP)
   _GUICtrlButton_SetImage(????????, $Start, $sPath & "\Start.bmp")

you need to use the ControlID of the button, which you have stored in $Start. So you need (as Manadar explained):

$Start = _GUICtrlButton_Create("Start", -1, 0, 65, 30, $BS_BITMAP)
   _GUICtrlButton_SetImage($Start, $sPath & "\Start.bmp")

Because AutoIt is a very pleasant language to use, you can also use "-1" to refer to the last ControlID, so you could code:

$Start = _GUICtrlButton_Create("Start", -1, 0, 65, 30, $BS_BITMAP)
   _GUICtrlButton_SetImage(-1, $sPath & "\Start.bmp")

I am afraid that there is a degree of confusion between the use of ControlID and handle in AutoIt (I just know I am going to get flamed for that, but it is true!). Normally, builtin AutoIt functions use the ControlID, but some UDFs use the Windows handle. A good UDF allows you to use either by checking with IsHwnd and doing any conversion for you.

Still awake? Ask if anything is unclear, but I cannot guarantee you a better answer. :-)

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
GaryFrost

A lot to say and still not the reason for the error.

The user used the UDF function to create the button, tried to. It requires the handle to the gui where as the built-in function does not.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Mat

Thanks a lot - that works now...

not quite sure why or how - but i'll leave that up to the people who know what they're talking about.

thanks again,

Mdiesel

oh, and i was missing the handle for the line before...

Edited by mdiesel

Share this post


Link to post
Share on other sites
Melba23

GaryFrost,

Guilty as charged.....but at least I tried to explain.

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.