Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any function called after the OnInitDialog function in MFC?

I want to create a thread after the creation of a dialog box in MFC. Is there any function that Windows has provided and is automatically called after OnInitDialog so that I can create my thread inside it?

like image 883
Suri Avatar asked Feb 23 '11 08:02

Suri


People also ask

When OnInitDialog is called?

For a modeless dialog box, OnInitDialog is called when Create is called. You typically override OnInitDialog to initialize the dialog box's controls, such as setting the initial text of an edit box. You must call the OnInitDialog member function of the base class, CDialog , from your OnInitDialog override.

What is the use of OnInitDialog?

OnInitDialog is called after all the dialog controls are created and just before the dialog box is displayed. You can call CWnd::UpdateData at any time during the execution of a modal or modeless dialog box.


1 Answers

You can simply create your thread in the OnInitDialog function. There's no reason to overcomplicate things by going and searching for a different function, or splitting your initialization code up in two pieces. (There also isn't any such function, because there's no corresponding Windows message that is sent.)

If you want to get your dialog box on the screen before you create the thread, you can just show it manually using the ShowWindow function. For example:

ShowWindow(SW_SHOW);
RedrawWindow();

Also see this post by Raymond Chen: Waiting until the dialog box is displayed before doing something

like image 178
Cody Gray Avatar answered Sep 24 '22 11:09

Cody Gray