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

1.7k views Asked by At

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.

1

There are 1 answers

2
xMRi On BEST ANSWER

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.