how to disable message box "Fail to create Empty Document " Message box in MFC SDI application

StackOverflow https://stackoverflow.com/questions/20988131

  •  25-09-2022
  •  | 
  •  

Question

I am using VS2010 for my MFC SDI application. In MainFrame Class in OnCreate(LPCREATESTRUCT lpCreateStruct) function I am opening one dialog box and on IDCANCLE replay from the Dialog box I want to close my application. I am using following code for the same in onCreate Function.

CTermsConditionDlg objTNCDlg;
if(!objTNCDlg.DoModal() == IDCANCLE){
return -1;
}

Now my Question is after return Statement the application is Showing message box as shown in Image. Message on close

I want to disable this message box and close my application. Can any one help how can I do That. Thank You in Advance.

Was it helpful?

Solution

Why do you place this dialog so late into you initialization? The problem is the SDI framework that relay on some initial things that are expected to run always. In this case it is always expected that the mainframe can be created. See code in CSingleDocTemplate::OpenDocumentFile

Just place this code into InitInistance before LoadFrame or ProcessShellCommand is called. In this case you can easily terminate without disturbing problems.

Another Idea is to allow the creation of the window, but simply using a PostMessage(WM_CLOSE); In this case the initialization is done, everything is created and the application terminates again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top