Jump to content
Sign in to follow this  
Dana

control handle vs id

Recommended Posts

Dana

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.

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

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
Dana

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.

Share this post


Link to post
Share on other sites
KaFu

And as an additional info

$iCtrlId = _WinAPI_GetWindowLong($hWnd, $GWL_ID)

is the reversal of

$hWnd = GUICtrlGetHandle($iCtrlId)

  • Like 1

Share this post


Link to post
Share on other sites
FireFox

@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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Melba23

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


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  

×