Sign in to follow this  
Followers 0
Mat

Control Handles vs. Id's

6 posts in this topic

Why does AutoIt have all the internal controls as Id's? All I'm wondering is what benefit this has, as surely you'll then need to convert it into a handle in order to use any of the win api functions on it. And also there could be problems with duplicates as I've read somewhere that Control Id's and guaranteed to be unique.

Mat

Share this post


Link to post
Share on other sites



Why does AutoIt have all the internal controls as Id's? All I'm wondering is what benefit this has, as surely you'll then need to convert it into a handle in order to use any of the win api functions on it. And also there could be problems with duplicates as I've read somewhere that Control Id's and guaranteed to be unique.

Mat

Every windows controls in almost all programming languages have ID-s.

Windows recive messages based on specific ID and dispatch them to the system.

You can have constant or variable type( INTEGER ) based ID but still must value in

other words must have numeric ID.

Share this post


Link to post
Share on other sites

Mat,

I can imagine that when Jon first wrote AutoIt he found it more convenient to use an internal array to keep track of created controls - hence the 65532 limit on controls per script. The existence of the built_in GUICtrlGetHandle command lends credence to that idea. And using such an array allows controls to be deleted and recreated without too much playing about with lists of handles - have you noticed that a new control takes the first available ControlID and not the next highest? Altering an already indexed array element is much faster then searching for a given handle in a list and then deleting it (which is what I imagine is the difference between the operation at present and what it would be if Windows handles were used).

As for duplicates - the use of the array prevents that.

Finally, if you create your controls in immediate succession you can use the ControlIDs in a loop to set their styles, fonts, etc. That is something I would be very loath to give up as several of my scripts have used this to good effect.

No doubt Jon will be along in a minute to shoot all this out of the water... :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

First off, what value a handle/id takes is irrelevant for you as a scripter.

The reason? Probably because it's safer to return an int to you so it cannot be fiddled with. Keeping the integrity of ones handles are important, what would happen if autoit returned the HANDLE of a newly opened file and you closed the file manually with _WinAPI_CloseHandle?

It would be catastrophic if any windows function would crash on invalid handle since autoit it now working on a invalid handle. Plus the internal reference count (autoit's) for the handle would mess up so it would mean autoit would try to clear already cleared handles.

Another thing is that it would remove any type safety from the language, you could just use any handle as anything, for example trying to read a HWND as a file.

Keeping them as arbitrary numbers protects you and autoit and it's very fast since array (or operation that works like array lookup) is very fast.

The alternative would be to give you the real handle and make a key/value pair in a hash table, but even that would only overcome half of the problems above.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

It's worth noting as well that the autoit IDs also correspond to the general windows IDs that you see if you hover over the controls in Au3Info (or any other screen reader) - the actual handle changes each run.

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  
Followers 0