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?
 
chensuConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.