Computing.Net > Forums > Programming > Visual C++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Visual C++

Reply to Message Icon

Name: Craig
Date: September 5, 2002 at 07:08:00 Pacific
OS: n/a
CPU/Ram: n/a
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: james
Date: September 5, 2002 at 18:24:33 Pacific
Reply:

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....


0

Response Number 2
Name: Jeff J
Date: September 6, 2002 at 11:20:16 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Visual C++

Visual c++ 6.0 www.computing.net/answers/programming/visual-c-60/81.html

Visual C++ for serial communication www.computing.net/answers/programming/visual-c-for-serial-communication/5188.html

visual C++ vs C++ and C www.computing.net/answers/programming/visual-c-vs-c-and-c/8925.html