From: Jd on 20 Apr 2010 01:20 I have an SDI application with multiple views. By default, it creates a new document when the application starts. I want to modify this behavior so that a new document is created only when user explicitly clicks on "New". Or at least mimic this behavior. I am using Visual Studio 2008 with MFC feature pack. I googled and found some solution to this problem in an old MS Journal article. http://www.microsoft.com/msj/archive/S204D.aspx But unfortunately it doesn't seem to work now, because framework is sending the command ID_FILE_NEW instead of calling the virtual function OnFileNew(). Any workarounds or solutions? In short, I need to differentiate between framework call to OnFileNew() and User Click on New. Is this a correct approach/design/choice in first place? TIA, Jd
From: Mikel Luri on 20 Apr 2010 03:56 El 20/04/2010 7:20, Jd escribi�: > I have an SDI application with multiple views. By default, it creates > a new document when the application starts. I want to modify this > behavior so that a new document is created only when user explicitly > clicks on "New". Or at least mimic this behavior. > I am using Visual Studio 2008 with MFC feature pack. > I googled and found some solution to this problem in an old MS Journal > article. > http://www.microsoft.com/msj/archive/S204D.aspx > But unfortunately it doesn't seem to work now, because framework is > sending the command ID_FILE_NEW instead of calling the virtual > function OnFileNew(). > Any workarounds or solutions? > > In short, I need to differentiate between framework call to > OnFileNew() and User Click on New. > > Is this a correct approach/design/choice in first place? > > TIA, > Jd Does that even make sense? I think you cannot have an SDI without a document. But you can have a MDI with a 1 document limit though, and you can prevent a new document from opening at startup with MDI (just as explained in the link you provide)
From: Mikel Luri on 20 Apr 2010 04:29 El 20/04/2010 9:56, Mikel Luri escribi�: > El 20/04/2010 7:20, Jd escribi�: >> I have an SDI application with multiple views. By default, it creates >> a new document when the application starts. I want to modify this >> behavior so that a new document is created only when user explicitly >> clicks on "New". Or at least mimic this behavior. >> I am using Visual Studio 2008 with MFC feature pack. >> I googled and found some solution to this problem in an old MS Journal >> article. >> http://www.microsoft.com/msj/archive/S204D.aspx >> But unfortunately it doesn't seem to work now, because framework is >> sending the command ID_FILE_NEW instead of calling the virtual >> function OnFileNew(). >> Any workarounds or solutions? >> >> In short, I need to differentiate between framework call to >> OnFileNew() and User Click on New. >> >> Is this a correct approach/design/choice in first place? >> >> TIA, >> Jd > > Does that even make sense? I think you cannot have an SDI without a > document. > But you can have a MDI with a 1 document limit though, and you can > prevent a new document from opening at startup with MDI (just as > explained in the link you provide) Sorry, I've taken a better look at the link and I see it refers to SDI. Well, maybe they've changed something and that's why it doesn't work. Sorry again
From: Mikel Luri on 20 Apr 2010 05:20 El 20/04/2010 10:29, Mikel Luri escribi�: > El 20/04/2010 9:56, Mikel Luri escribi�: >> El 20/04/2010 7:20, Jd escribi�: >>> I have an SDI application with multiple views. By default, it creates >>> a new document when the application starts. I want to modify this >>> behavior so that a new document is created only when user explicitly >>> clicks on "New". Or at least mimic this behavior. >>> I am using Visual Studio 2008 with MFC feature pack. >>> I googled and found some solution to this problem in an old MS Journal >>> article. >>> http://www.microsoft.com/msj/archive/S204D.aspx >>> But unfortunately it doesn't seem to work now, because framework is >>> sending the command ID_FILE_NEW instead of calling the virtual >>> function OnFileNew(). >>> Any workarounds or solutions? >>> >>> In short, I need to differentiate between framework call to >>> OnFileNew() and User Click on New. >>> >>> Is this a correct approach/design/choice in first place? >>> >>> TIA, >>> Jd >> >> Does that even make sense? I think you cannot have an SDI without a >> document. >> But you can have a MDI with a 1 document limit though, and you can >> prevent a new document from opening at startup with MDI (just as >> explained in the link you provide) > Sorry, I've taken a better look at the link and I see it refers to SDI. > Well, maybe they've changed something and that's why it doesn't work. > Sorry again It's me again. I've been reading carefully the article you linked to, while doing what it says in a little test app, and it seems like the command routing doesn't work as stated in the article, at least while initializing the app. Specifically, we can see: BOOL CWinApp::ProcessShellCommand(CCommandLineInfo& rCmdInfo) { BOOL bResult = TRUE; switch (rCmdInfo.m_nShellCommand) { case CCommandLineInfo::FileNew: if (!AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL)) OnFileNew(); if (m_pMainWnd == NULL) bResult = FALSE; break; [...] } So it seems that ProcessShellCommand sends directly a ID_FILE_NEW command to the App, thus invalidating Paul's workaround. A possible solution would be to make that particular call to OnCmdMsg return FALSE. To do so, you can declare a member variable in your app class, say m_bInit, which would be FALSE until the end of InitInstance, where you set it to TRUE, and override OnCmdMsg. If m_bInit is FALSE, (and the command ID is ID_FILE_NEW) you return FALSE, otherwise, you call your base class' OnCmdMsg. I've tried it and in seems to work. OnMyNewFile does not get called until the user asks for a new file. I'm not sure it's the best solution, though. If I had to do it, I would probably take the MDI route, setting a 1 document limit and doing the "cmdInfo.m_nShellCommand = FileNothing;" thing.
From: Goran on 20 Apr 2010 09:54
On Apr 20, 3:53 pm, Goran <goran.pu...(a)gmail.com> wrote: Whoops! Copy-pasted MFC code (the "no magic" part) went out horribly. Sorry 'bout that. Goran. |