Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to figure out how to create controls dynamically. I have seen that a dialog class has a 'CreateControl' member but understanding the actual parameters it takes is a little confusing.
As an example, say you have a Dialog box with 1 Edit box and 1 Button...you enter the number of Edit boxes you want to appear in the Edit box that is currently shown...then click the button and that many Edit boxes are displayed.I think I use an array of CEdit objects...
The number of objects is determined only once while the program is rinning...
Any suggestions would be appreciated...even where I might want to look for the answer..
Thanks in Advance
CES

i have jes started learning c++ a few days ago(yes im a total newbie) but if you use UpdateData(true); in the code for your button it should update the amount of edit boxes every time you click the button instead of only once whilst the program is running, although i am probbably giving you useless info that wont work cos i am a newbie but i had a few problems making some one of my programs a few days ago cos of not having updatedata in my code....

Possibly your biggest hurdle is trying to do this within a regular dialog (resource-templated window), rather than a purely code-generated window. As far as the OS is concerned about the final product (a window containing controls), there is little difference, mostly just the calls required by your app to generate things, and how the OS handles things by default. However, since little is done in code to generate dialogs, controlling them is more difficult. It is possible to add and move around the controls in a dialog like with code-generated windows, but it requires getting the handles to the controls, etc.
Since manipulating resourced dialogs is more difficult (and I'm dubious about tutorials out there about it), perhaps you could look into generating your "dialog" purely in code. That is, create a separate window based on CWnd, and embed some controls in it. This will work best if your dialog can be modeless (modeless dialogs are mostly regular windows anyway). If you go that route, then a dynamic array of CEdit controls is fine, whether using an MFC CArray, a C++ vector, or whatever.
If you need to go modal, then you could look into generating your entire dialog dynamically. There is an MFC example called DLGTEMPL that explains this in more detail. In essence this is fairly similar in many ways to creating your own window in code, but it has the added advantage of allowing to go modal easier.
I hope some of this helps, as it is very difficult to respond to broad questions. You just happen to be trying to do one of those trickier things that is less common. Please feel free to post again regarding any hurdles along the way.
Cheers

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |