Link to home
Start Free TrialLog in
Avatar of mellor
mellor

asked on

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
Avatar of AlexFM
AlexFM

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, ...)
}



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.


 I use 0xE000 to 0xF000
As long as all the IDs are unique within the dialog there is no problem.
Avatar of mellor

ASKER

Dear aphillips,
Could you expand on your comment.
How does one check that one is only
working with items 'within the dialog'
Yours
Allan
ASKER CERTIFIED SOLUTION
Avatar of aphillips
aphillips
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mellor

ASKER

Thanks very much.
You learn somthing new every day.
Yours
Allan