• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

Creation of MFC controls at run time: How to allocate resource ID's?

Hi,
I may be missing something, I don't pretend to be an expert,
but I have to create a dialog box with controls that can only
be created at run time.
I have to give these controls a resource ID but the number I
require varies. It seems that I could just create a block
of them via 'view' 'ID's' in the PWB but that seems to me to
be a 'hack'. If I just start at resource 1 and increment
will they get confused with other ID's already created in
resource.h?

Yours
confused
Allan
0
mellor
Asked:
mellor
1 Solution
 
AlexFMCommented:
Visual Studio resource editor starts resource IDs from 100. You can be quiet starting from 1.
You can also add your own resource ID using function View - Resource Symbols. To be 100% correct, add some number of consequent IDs:

ID_MYCONTROL1
ID_MYCONTROL2
...

and use first of them as start value:

for ( int i = 0; i < ..., i++ )
{
   ... Create(ID_MYCONTROL1 + i, ...)
}



0
 
KurtVonCommented:
You can also allocate a block of control IDs by adding one new control ID, then closing the resource file and opening the resource.h file then changing the value after _APS_NEXT_CONTROL_VALUE.  Close resource.h, reopen the resource editor, and add the "last" control for marking the end of the block you just reserved.
0
 
williamcampbellCommented:


 I use 0xE000 to 0xF000
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
aphillipsCommented:
As long as all the IDs are unique within the dialog there is no problem.
0
 
mellorAuthor Commented:
Dear aphillips,
Could you expand on your comment.
How does one check that one is only
working with items 'within the dialog'
Yours
Allan
0
 
aphillipsCommented:
> Could you expand on your comment.

When you do anything (ie call an API function or an MFC class method) that uses a control ID you also specify a window, in this case a dialog.  At the Windows API level the HWND of the dialog and the ID of the control uniquely identify the control.

I guess your confusion arises from the fact that Developer Studio puts a lot of effort into keeping track of IDs in resource.h.  However, this is due to the use of #defined values which for C/C++ are in the global "namespace" and hence its is trying to avoid conflicts in the names.

I hope this makes sense.

One reason you may want unique IDs across all dialogs is if you use Developer Studio to generate help IDs from the control IDs.  In this case the help IDs must be unique within the help file.  But I doubt whether you are using the context help facility for controls since it sounds like you generate the controls dynamically and are not sure of the number or type.
0
 
mellorAuthor Commented:
Thanks very much.
You learn somthing new every day.
Yours
Allan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now