Dynamic creation of controls without ressource ID 
Author Message
 Dynamic creation of controls without ressource ID

Hi there,

I've the following problem:

I've to create dynamic controls, but I only know how many at run time, so I
can't figure out how to set a control ressource ID safely, without setting
one already used. Is there a simple solution I missed?

Thanx.



Mon, 22 Dec 2003 16:37:44 GMT  
 Dynamic creation of controls without ressource ID
Hi,
in your window procedure you can do it as follows:

 CRect Rect (0, 0, 100, 50);

 CButton* pButton = new CButton;
 pButton->Create
    ("test", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, Rect, m_pMainWnd, 101);

These three lines of code create a Pushbutton in the upper left corner of
your window.
The last parameter (101) is the Button ID which can be used in the message
map etc.

I hope this is what you was searching for :)
Sincerely
Jan



Quote:
> Hi there,

> I've the following problem:

> I've to create dynamic controls, but I only know how many at run time, so
I
> can't figure out how to set a control ressource ID safely, without setting
> one already used. Is there a simple solution I missed?

> Thanx.



Mon, 22 Dec 2003 17:36:02 GMT  
 Dynamic creation of controls without ressource ID
The problem is that I have to create more than one button (in fact I deal
with list controls, since I want to create a list control buffer). So how do
I have to choose a correct resource ID unused by other controls?



Quote:
> Hi,
> in your window procedure you can do it as follows:

>  CRect Rect (0, 0, 100, 50);

>  CButton* pButton = new CButton;
>  pButton->Create
>     ("test", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, Rect, m_pMainWnd,
101);

> These three lines of code create a Pushbutton in the upper left corner of
> your window.
> The last parameter (101) is the Button ID which can be used in the message
> map etc.

> I hope this is what you was searching for :)
> Sincerely
> Jan



> > Hi there,

> > I've the following problem:

> > I've to create dynamic controls, but I only know how many at run time,
so
> I
> > can't figure out how to set a control ressource ID safely, without
setting
> > one already used. Is there a simple solution I missed?

> > Thanx.



Mon, 22 Dec 2003 18:52:01 GMT  
 Dynamic creation of controls without ressource ID
hmm
then I would suggest to use High ID numbers to make sure that you don't
collide with other controls of your app. You could make a member variable
which stores the next higher ID.

hmm you could start at m_NextID = 32000 I think.

CRect Rect (0, 0, 100, 50);

 CButton* pButton = new CButton;
 pButton->Create
    ("test", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, Rect, m_pMainWnd,
m_NextID);

m_NextID++;

Sincerely
Jan



Quote:
> The problem is that I have to create more than one button (in fact I deal
> with list controls, since I want to create a list control buffer). So how
do
> I have to choose a correct resource ID unused by other controls?



> > Hi,
> > in your window procedure you can do it as follows:

> >  CRect Rect (0, 0, 100, 50);

> >  CButton* pButton = new CButton;
> >  pButton->Create
> >     ("test", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, Rect, m_pMainWnd,
> 101);

> > These three lines of code create a Pushbutton in the upper left corner
of
> > your window.
> > The last parameter (101) is the Button ID which can be used in the
message
> > map etc.

> > I hope this is what you was searching for :)
> > Sincerely
> > Jan



> > > Hi there,

> > > I've the following problem:

> > > I've to create dynamic controls, but I only know how many at run time,
> so
> > I
> > > can't figure out how to set a control ressource ID safely, without
> setting
> > > one already used. Is there a simple solution I missed?

> > > Thanx.



Mon, 22 Dec 2003 19:06:05 GMT  
 Dynamic creation of controls without ressource ID
In the "View" menu is "Resource Symbols". You can add resource symbols using
that. There are many other ways to safely determine a resource id but that
is one way that could be used. I think that it does not guarantee that a
resource id will be unique but if you are careful it should be easy to be
safe. You can view the resource.h file directly to see exactly what exists.


Quote:
> The problem is that I have to create more than one button (in fact I deal
> with list controls, since I want to create a list control buffer). So how
do
> I have to choose a correct resource ID unused by other controls?



> > Hi,
> > in your window procedure you can do it as follows:

> >  CRect Rect (0, 0, 100, 50);

> >  CButton* pButton = new CButton;
> >  pButton->Create
> >     ("test", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, Rect, m_pMainWnd,
> 101);

> > These three lines of code create a Pushbutton in the upper left corner
of
> > your window.
> > The last parameter (101) is the Button ID which can be used in the
message
> > map etc.

> > I hope this is what you was searching for :)
> > Sincerely
> > Jan



> > > Hi there,

> > > I've the following problem:

> > > I've to create dynamic controls, but I only know how many at run time,
> so
> > I
> > > can't figure out how to set a control ressource ID safely, without
> setting
> > > one already used. Is there a simple solution I missed?

> > > Thanx.



Wed, 24 Dec 2003 08:30:51 GMT  
 Dynamic creation of controls without ressource ID
And what about the other way to safely determine a resource id?



Quote:
> In the "View" menu is "Resource Symbols". You can add resource symbols
using
> that. There are many other ways to safely determine a resource id but that
> is one way that could be used. I think that it does not guarantee that a
> resource id will be unique but if you are careful it should be easy to be
> safe. You can view the resource.h file directly to see exactly what
exists.



> > The problem is that I have to create more than one button (in fact I
deal
> > with list controls, since I want to create a list control buffer). So
how
> do
> > I have to choose a correct resource ID unused by other controls?



> > > Hi,
> > > in your window procedure you can do it as follows:

> > >  CRect Rect (0, 0, 100, 50);

> > >  CButton* pButton = new CButton;
> > >  pButton->Create
> > >     ("test", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, Rect, m_pMainWnd,
> > 101);

> > > These three lines of code create a Pushbutton in the upper left corner
> of
> > > your window.
> > > The last parameter (101) is the Button ID which can be used in the
> message
> > > map etc.

> > > I hope this is what you was searching for :)
> > > Sincerely
> > > Jan



> > > > Hi there,

> > > > I've the following problem:

> > > > I've to create dynamic controls, but I only know how many at run
time,
> > so
> > > I
> > > > can't figure out how to set a control ressource ID safely, without
> > setting
> > > > one already used. Is there a simple solution I missed?

> > > > Thanx.



Mon, 29 Dec 2003 04:46:13 GMT  
 Dynamic creation of controls without ressource ID
Yes. Pick a number well outside the range the resource editor is
likely to use, say, 10000. Each time you create a control, increment
this value. Use ON_COMMAND_RANGE to handle all of the controls.
                        joe

On Thu, 5 Jul 2001 10:37:44 +0200, "Guillaume Gourdin"

Quote:

>Hi there,

>I've the following problem:

>I've to create dynamic controls, but I only know how many at run time, so I
>can't figure out how to set a control ressource ID safely, without setting
>one already used. Is there a simple solution I missed?

>Thanx.

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Tue, 30 Dec 2003 08:41:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. control ID for dynamic created control and menu item

2. Dynamic Control Creation

3. Dynamic Control Creation in C#

4. dynamic control creation

5. Dynamic Creation of Controls

6. Dynamic creation of controls...

7. Dynamic creation of controls in a FormView

8. Dynamic control creation on a DialogBar

9. ATL Bug? Dynamic control Creation problem

10. Dynamic creation of controls on a view

11. Dynamic creation of controls in views

12. Help with dynamic creation of Edit control

 

 
Powered by phpBB® Forum Software