Jump to content

control handle vs id


Dana
 Share

Recommended Posts

What is the difference between a control id (returned by most of the GUICtrlCreate... functions) and the handle (returned by GUICtrlGetHandle)? If I understand correctly, most of the built in AutoIt functions use the id, but the UDFs all seem to use the handle instead? Just trying to understand the reason behind the difference.

Link to comment
Share on other sites

Hi,

An Id is an identifier for the application itself, for each control created this last is incremented; whereas a handle is a unique Id, so if you want to interact with it you don't need to specify the parent window.

Br, FireFox.

Link to comment
Share on other sites

  • Moderators

Dana,

A ControlID is actually an index to an internal AutoIt array holding details of all the controls created by the native AutoIt functions - it is a simple decimal integer. Each of these controls also has a handle - a unique ID allocated by Windows to everything created - which is stored in that array and used by AutoIt to act on the control internally. Yu can access the handle by using GUICtrlGetHandle.

A UDF control returns a handle directly - which looks like a multi-digit hex integer, but is in fact a special variable type. Anything created by a non-native function (i.e. most of the UDFs) will return a handle.

This is why the native GUICtrl* functions will not work on UDF controls - they require a ControlID - and why you see code like this in UDFs:

; Check handle
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
If Not IsHWnd($hWnd) Then

where if the user passes a ControlID it is converted to the handle before the UDF function gets to work.

All clear? :)

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

All clear? :)

I think so: The AutoIT native commands have access to the integer ID and internal array, but UDF functions don't, so they have to use the Windows handle. One wonders why the control ID exists at all, seems redundant... though I suppose there could be a situation where having sequential integer IDs would be useful in some sort of flexible GUI.

Link to comment
Share on other sites

@Dana

Nope, UDF functions are generally window messages sent to the controls, if you pass a control Id it will work (either it will be converted to a handle to use the _SendMessage function or the GUICtrlSendMessage function will be used).

Edit2: The controls created with the UDFs return a handle because they are not internaly created by the application, hence you need the handle to manage it because it has no Id.

Melba23 should reply better than me ;)

Edit: _WinAPI_GetDlgCtrlID also works for the additional info.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

  • Moderators

Dana,

If you want an example of where ControlIDs are useful take a look at the Tabs tutorial in the Wiki. AutoIt is quite happy looking after its own native controls within the tabs, but completely ignores anything created by a UDF. Because the ControlIDs refer to the internal array, AutoIt can deal with them internally - other controls need to be dealt with by the code itself. Remember that AutoIt is essentially a wrapper around the Windows API - as in fact are most of the UDFs - and a lot goes on "under the hood" when you use a simple function. ;)

As to having lists of sequential integers as ControlIDs of a range of controls - this is very useful on occasion. But beware, AutoIt uses the first available empty slot in the array so if you have deleted a control and then create some new ones, the ControlID will not be sequential. I once posted some code on the forum to demonstrate this and I will try and find it (or just rewrite it!) later. :D

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