Solved

Subclassing dynamically created control (No ID)

Posted on 1998-12-24
3
205 Views
Last Modified: 2013-11-20
When creating variable numbers of controls at run-time, I generally give them an ID of NULL. However, if I wish to sub-class these controls, then they need to have an ID. Is there any way to generate a unique ID at runtime?
0
Comment
Question by:murrayc
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 30 total points
ID: 1326672
Say CWnd * (or your derived class from CWnd) to the control, called pWnd

Change the id using

SetWindowLong( pWnd->m_hWnd, GWL_ID, _id_value_here ) ;

Doing this is no different from using CreateWindow with a valid id in the first place.


Now if the question is how to work out the id, they are at least 3 methods :-

Either
(a) Reserve a range of IDs that are never used for normal dialog controls( say 10000 to 10999)
Then use these up sequential.  Remember you can start again from the lowest value when the control is destroyed.

or
(b) On the Window, using EnumChildWindows to find all the other controls.  Get their id's using GetWindowLong.  Store these in a map or array.  Then set your ids to values not in the array/map

or
(c) If all your controls are dynamically created
Assign numbers sequential to your controls as they are created.  If you are worried that you might eventually run out of possible values, then keep a list of used (or unused) id's in a map (and when a windows is created/destroyed update the map), and then you re-use values when you need em.



0
 

Author Comment

by:murrayc
ID: 1326673
b) Is the kind of thing I'm looking for, but what range of IDs will be acceptable?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1326674
Anything you're not using.

Lookup at the values in resource.h

I suggest you pick a very high value, then it's easy to ensure the resource.h always uses values less than that
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 55
Importing  SSL Certificate into Firefox using GPO 28 202
substring method in java 1 97
fizzArray2 challenge 1 72
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now