manimatters
manimatters

Reputation: 434

Messagebox in CMainFrame OnCreate

I have an old MFC application with an OnCreate function that spans upwards of 200 lines.

CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
PostMessage(LOAD_IMAGES,0,0);
...
ValidatePermissions();
...
}

The LOAD_IMAGES is a user message whose handler tries to Load images which had been unsaved from the last session.. basically it tries to create a new CDocument...

The ValidatePermissions function pops up a modal messagebox if it finds any permissions missing..

I notice that if I have the modal message box pop up, then I get a crash when LOAD_IMAGES handler fires (since it cannot create a CDocument, I think it is because the CMainFrame has not yet created).

How should I be handling such a case. Is there any documentation that suggests not to have modal messageboxes in the OnCreate?

Upvotes: 0

Views: 469

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

Try moving the call to ValidatePermissions to the message handler for LOAD_IMAGES. That should let the window creating complete before you let the message box pump messages.

Upvotes: 1

Related Questions