Sign in to follow this  
Followers 0
pekster

Control ID Ordering

4 posts in this topic

I'm creating a GUI that dynamically creates some GUI elements based on an external data source and have a question about the returned control ID from the GUICtrlCreate*() functions.

It seems that each control element returns an ID one higher than the last, but is this consistent? Ultimately I need to relate the Control ID to the text on a control, but for performance I don't want to use a lookup table. I have searched for this topic in the forums, but didn't find an answer to the ordering of the control ID's.

A simplified example of my control creation is as follows:

#include <GUIConstantsEx.au3>
 
 $max_buttons = 5
 GUICreate("Sample GUI", 300, 300)
 For $i = 1 To $max_buttons
     $control_id = GUICtrlCreateButton("Button " & $i, 0, $i * 20, 100, 20)
     Assign("button" & $i, $control_id)
 Next
 
 GUISetState()
 
 While 1
     $msg = GUIGetMsg()
     Select
     Case $msg >= $button1 AND $msg <= Eval("button" & $max_buttons)
        MsgBox(0, "Result", "You Pressed Button #" & $msg - $button1 + 1)
     Case $msg = $GUI_EVENT_CLOSE
        Exit
     EndSelect
 WEnd

Now, when I check the values of the returns, the difference is always 1. So $button2 is $button1 + 1, and so on. Assuming I am always creating controls one after the other as in my sample code above, can I rely on this to properly report the control pressed?

Thanks.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Controlids are created in order that the script creates them, and I think that starts at 3 by default. No clue what 1 & 2 are.

The controls created dynamically are numbered based on your loop steps i.e. For $x = 1 to 20 (controlids will be 1 thru 20)... For $x 1 to 100 step 5 (controldids will be 5, 10, 15, 20 .... 100)

Any controls created after the loop(s) will get the next available number.

Edit: Correction.

Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

...

... For $x 1 to 100 step 5 (controldids will be 5, 10, 15, 20 .... 100)

...

That's not true , Autoit will still give the next ctl id to the next control no matter if you step 5 or 50000..

If the next available ctrl id is lets say 4 and you step through the loop by any number, then the next ctrl id will still be 4 regaurdless of the step value in the for loop .

Edited by smashly

Share this post


Link to post
Share on other sites

That's not true , Autoit will still give the next ctl id to the next control no matter if you step 5 or 50000..

If the next available ctrl id is lets say 4 and you step through the loop by any number, then the next ctrl id will still be 4 regaurdless of the step value in the for loop .

You are correct, my oversight.

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

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