Jump to content

Using a handle instead of id to interact with a control.

Recommended Posts

I wasn't sure how to search for this but I did try and couldn't find anything.

In my script I have a for loop create a bunch of labels and through this I was wanting to be able to click on any label and call the function "_Click" so that I can change the color of the box accordingly.

I originally started using @gui_ctrlid to get the id of the label but I realized that once I started adding more code it would mess with getting the correct id. I thought I could use the macro @gui_ctrlhandle but I'm not sure on how to interact with the control through this (normally I would use the ControlId)

The code below should hopefully help you understand if you are confused.

Func _Click()
   $id = @GUI_CtrlHandle

Thanks for any help and if you need additional information please let me know so I can aid you in aiding me.

Link to post
Share on other sites
  • Moderators


but I realized that once I started adding more code it would mess with getting the correct id

I do not see why it should - ControlIDs to not vary unless you delete and recreate the associated control. This works just fine:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $i = 0 To 9
    GUICtrlCreateLabel("", 10, 10 + (30 * $i), 200, 20)
    GUICtrlSetBkColor(-1, 0xCCFFCC)
    GUICtrlSetOnEvent(-1, "_Click")


While 1

Func _Click()
    $cCID = @GUI_CtrlId

    GUICtrlSetBkColor($cCID, 0xFFCCCC)

Func _Exit()


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:


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 post
Share on other sites

I realized that the function that I posted I had modified and I modified it to work properly, in my script instead of having this:

Func _Click()
   $id = @GUI_CtrlId


I had this:

Func _Click()
   $id = @GUI_CtrlId


A simple mistake but thank you for the help melba, I compared your example code to my script and found the error that way.

Appreciate it!

Edited by gottygolly
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...