Dana Posted April 2, 2013 Share Posted April 2, 2013 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 More sharing options...
FireFox Posted April 2, 2013 Share Posted April 2, 2013 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 More sharing options...
Moderators Melba23 Posted April 2, 2013 Moderators Share Posted April 2, 2013 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) Thenwhere if the user passes a ControlID it is converted to the handle before the UDF function gets to work.All clear? M23 SupaNewb 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Dana Posted April 3, 2013 Author Share Posted April 3, 2013 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 More sharing options...
KaFu Posted April 3, 2013 Share Posted April 3, 2013 And as an additional info $iCtrlId = _WinAPI_GetWindowLong($hWnd, $GWL_ID) is the reversal of $hWnd = GUICtrlGetHandle($iCtrlId) SupaNewb 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
FireFox Posted April 3, 2013 Share Posted April 3, 2013 (edited) @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 April 3, 2013 by FireFox Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 3, 2013 Moderators Share Posted April 3, 2013 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now