Create vs DoModal for CDialog w/ controls created on the fly

I have a situation where I create a window with a number of buttons on it. The number and label of these buttons are unknown at dialog creation time. What I do now is Create() the dialog window and call ShowWindow() once everthing has been created. On cancel and okay the dialog window is destroyed (I tried using hide if okay was clicked and the program crashed. I'm ignoring htis point right now because I haven't gone back through and tried it again no that the program is stable. Point is I did try the hide/show method). This functions just fine, however, I'm not sure what this is doing to memory. What I'm wondering is if there is a way to create a window with DoModal and create child controls before the dialog is shown.

THanks

ps. I'm using MFC DevStudio Visual C++ version 5.0
winkleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Yes. Derive your own dialog class from CDialog and override OnInitDialog or OnCreate to create the controls. There is another method that is complicated. You can create the dialog template in memory to do so. Please see the Win32 SDK documentation for detailed information and sample code: Win32 SDK/Win32 Programmer's Reference/Overviews/Window Management/Dialog Boxes.

But, in your case, it is easier and simpler to create a window instead of a dialog box.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.