if you're talking about the close box in the top right corner of the main SDI window, this causes the program to exit. If you want to intercept this I expect it's done in the ExitInstance() function of your app. You could also try intercepting the appropriate messages before they are processed.
If you mean the 'close' option of the edit menu, then you'll need to keep your eye open for a WM_CLOSE message. You could intercept this in your PreTranslateMessage() function, eg:
[tt]BOOL CClassName:reTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_CLOSE)
{ // do intercept code here
// return TRUE so that message doesn't get
// forwarded
return TRUE;
}
I never seem to explain myself very well...sorry 'bout that. The close button, top right of the window. Reason: Not sure how to explain but from a button in dialog-based application my program opens an SDI window (ie. MainFrame, View and Document). I've made modifications so that the close button in the top right corner only closes the window but the Close option under the File menu still closes the entire application. I think this has something to do with the resource being named ID_APP_EXIT which calls CWinApp::OnAppExit. Not sure how to go about this. ALSO...there is something else not working out properly because with debugging I've come to realize that when the SDI window first opens, only the MainFrame object is constructed...you have to click FILE/NEW or FILE/OPEN before View and Doc objects are constructed. A lot to think about...any help would be much appreciated.
OK... here goes.... your dialog based app opens in an SDI window - well, which resource is named ID_APP_EXIT ?? Is it the close button on the dialog? These are usually named IDCANCEL - even in pure dialog based apps?
Now I do know that if you have a dialog based app and try and intercept a click on the close button that the application will still exit. I also know that the way to stop this is to not have your p_mMainWnd pointing to the dialog. If you point it to your MainFrame instead then you'll be able to use clas wizard to override the OnCancel() on your dialog and you can do whatever in there.
For your second question, to make a new document open when you launch your application, use the CCommandLineClass. When you create a new MDI project, you'll see an example of this class in use in the InitInstance() function of your app.
You can use this class to open/print any of your app's documents whether they be templates or whatever, and all this without opening another instance of your app like ShellExecute does.
You can also prevent your app from opening a blank document at launch by doing this:
[tt]
CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo)) return FALSE;
[/tt]
programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
You are on the wrong track here. This is caused becuase you are hooking the CSingleDocTemplate into your CWinApp of your dialog based application. Don't do that. See my last post in your original thead. I hope it will clear things up for you.
I completely understand what you are saying but if the only code I have is in the function for the dialog button:
*********************************************
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CInvoiceDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CInvoiceView));
pDocTemplate->OpenDocumentFile(NULL);
************************************************
Where the view class is derived from CEditView, why does my close button (top, right) and my File/Exit button still close the entire app...it worked fine in my CRichEditView derived class. I triple checked the code...I don't understand what is different.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.