Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1003
  • Last Modified:

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
0
winkle
Asked:
winkle
1 Solution
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now