晕,有人来抢分,我把代码给我写好了BOOL C???????App::InitInstance() { ..... // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if( CCommandLineInfo::FileNew == cmdInfo.m_nShellCommand ) cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; .........}
在app的InitInstance里面把把语句改为发下: CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;//加上这句 // Dispatch commands specified on the command line // if (!ProcessShellCommand(cmdInfo))///去掉这两句就OK了。 // return FALSE;
在App.InitInstance()中
找到 CCommandInfo cmdInfo; 在这附近加一个断点,运行到这里后使用F11跟进去.你可以看到MFC提供的源代码,有你需要的一个参数实际上,为了解决用户双击时打开文档,你应当分析当前命令是否是 filenew 如果是,你才能删除之,否则不能修改.要不然打不开用户双击的文档.
晕,有人来抢分,我把代码给我写好了BOOL C???????App::InitInstance()
{
..... // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); if( CCommandLineInfo::FileNew == cmdInfo.m_nShellCommand )
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
.........}
呵呵!帮了忙的都有分。
你那个方法不错,
接下来我点击“新建”创建一下视图怎么做?
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;//加上这句 // Dispatch commands specified on the command line
// if (!ProcessShellCommand(cmdInfo))///去掉这两句就OK了。
// return FALSE;
我明明回过的,怎么没有了?
重载 CView::InitUpdate() 应该是这个函数
生成新的框加后,立即调用了该函数
如果想在视图类外做些操作,那么自己重载 OnFileNew
完了后再调用 APP::OnFileNew
“CWinApp::OnFileNew”: 无法访问 protected 成员(在“CWinApp”类中声明)
{ CWinAPP::OnFileNew();
}
最后大概是这样的
看在楼主晚上十一点还在努力就回个贴咯一般来说 MDI 启动时不想打开文档就修改启动参数就可以了在APP 的initinstance函数里
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;至于[新建]则在MainFrame 类中使用::AfxGetApp()->OpenDocumentFile(NULL)就可以了如果涉及到多文档或多视图,那么使用::AfxGetApp()->m_pDocManager找到相应的DocTemplate;再用 DocTemplate->OpenDocumentFile(NULL) 即可
你的方法能行,
我还想知道AfxGetApp()->OpenDocumentFile(NULL)生成的是那个视图的模板,我想修改这个默认视图。
void CSearchView::OnFileNew()
{
//TODO: 在此添加命令处理程序代码
CCondition cc;
if(cc.DoModal() == IDOK)
{
CCommandLineInfo cmdInfo;
AfxGetApp()->ParseCommandLine(cmdInfo);
//ParseCommandLine(cmdInfo);
if (!AfxGetApp()->ProcessShellCommand(cmdInfo))
return;
//AfxGetApp()->OpenDocumentFile(NULL);
}
}这用这样的代码也能达到自己想要的效果,和你的有什么区别?
AfxGetApp()->ParseCommandLine(cmdInfo);
//ParseCommandLine(cmdInfo);
if (!AfxGetApp()->ProcessShellCommand(cmdInfo))
return;
//AfxGetApp()->OpenDocumentFile(NULL);可以处理的选项多点,我的是简化了,没其它参数,另外可以揭帖了
晕啊,不行!原来是我自己的代码生成的视图。。