Jump to content

$hWnd ? (understood at last)


 Share

Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

  • Moderators

GaryFrost,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...