Jump to content
Sign in to follow this  

Help with GUICtrlCreate handles and GUICtrlDelete

Recommended Posts

Hello AutoIT community,

From what I understand, GUICtrlCreate functions generates controls on a GUI and returns the identifier i.e. controlID of the control, while GUICtrlDelete deletes a control specified by its controlID.

I believe that the identifier returned by GUICtrlCreate functions is unique for every control generated, but I have noticed a case where it is possible that after GUICtrlDelete is used to delete controls, GUICtrlCreate functions reuse the controlID values of the controls that were deleted by GUICtrlDelete.

To give an example,

$ctrl1 = GUICtrlCreateLabel("1",10,10,100,30)
MsgBox(0,"Value of $ctrl1",$ctrl1)
$ctrl2 = GUICtrlCreateLabel("2",10,10,100,30)
MsgBox(0,"Value of $ctrl2",$ctrl2)


When I tested the code, both Messageboxes gave me the same value for the controlIDs ('3' and '3' in my case when I ran the code).

Is it possible for GUICtrlCreate not to return controlIDs of controls that were deleted beforehand? The program I am currently writing requires the constant generation and destruction of controls, and this is causing me problems because the wrong controls are being deleted... I couldn't find any relevant topics regarding this by search the forums so any help will be greatly appreciated!


(p.s. this is my first post in the forum, pls be gentle :sweating: )

Share this post

Link to post
Share on other sites

Why would you need to Create and Delete Controls? Can't you re-use them or Hide the ones you don't want to show?


Share this post

Link to post
Share on other sites

Hi Jos,

It's kind of hard to accurately explain my program to you, but I'll try.

I'm creating this program where users can make their own full fledged Windows apps using my program. To elaborate, it's kind of like Koda but forms, not code, are generated and the forms that are generated are actually able to take in input and do useful stuff with it. It comprises two GUIs, one where the user enters information to generate his forms, and the other which is the application itself, which is generated according to what the user entered in the other GUI. 

The form creation process begins with the user adding objects to the form that he wants to create. Objects include the usual GUICtrlCreate controls (labels, buttons, images lists etc) and database tables for the user to store information in. To make the form useful, users can then associate these objects with functions, such as opening another form, saving the information from an inputbox into a database table previously created by the user, reading information from a database and displaying the information into a listview etc.

The problem mentioned in the previous post comes in when I try to make the object defining controls in the form creation GUI. Since each object has functions specific to itself, I have to tweak the object defining controls such that it shows the correct functions available to the object. To tweak this input, I used to do it using a myriad functions such as GUICtrlSet, GUICtrlHide, ControlMove etc but lately I realised that performance would be much more efficient and quick if I just recreate the object defining controls (using GUICtrlDelete then GUICtrlCreate) such that it shows the correct stuff. However, I have realised that the recreation process sometimes cause the wrong control to be deleted due to the control handle problem as mentioned in OP, thus OP.

Hope it's not too confusing T_T


Share this post

Link to post
Share on other sites

If you're creating and deleting controls, and you're deleting the wrong ones because the handles are reused, then you've got more problems with your script than the reused control IDs. You should be keeping track of which variables go with which control and not depending upon whatever it is you're doing now.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

  • Create New...