在MFC中覆盖OnFileOpen(ID_FILE_OPEN) [英] Overriding OnFileOpen in MFC (ID_FILE_OPEN)

查看:377
本文介绍了在MFC中覆盖OnFileOpen(ID_FILE_OPEN)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解在阅读此处和 [ ^ ].但是,我无法弄清楚如何使我的SDI-Doc/View-CFormView应用程序在应用程序启动时打开单个文件,而不必从对话框中选择文件.如何完成这个简单但难以捉摸的解决方案?

请客气;)

-DrB

I understand I need to override the OnFileOpen to customize my app after reading a few articles here and at this MSDN link[^]. But, I can''t figure out how to make my SDI-Doc/View-CFormView app open a single file on app startup without having to select the file from a dialog. How do I accomplish this simple but elusive solution?

Please be kind ;)

-DrB

推荐答案

如果要在启动应用程序时打开特定文件,则可以在解析后修改CCommandLineInfo.此方法还可用于避免从新文档开始.

一个可选的示例,可以在程序启动时加载文件,或者只是在没有任何文档的情况下启动文件,如下所示:

If you want to open a specific file upon starting your application, you can modify the CCommandLineInfo after parsing. This method can be also used to avoid starting with a new document.

An example to optional load a file at program start or just start without any document might look like this:

CMyApp::OnInitInstance()
{
    ...
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
    // No file name passed on command line
    if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
    {
	cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
	if (GetProfileInt(_T("Config"), _T("OpenAtStart")))
	{
            cmdInfo.m_strFileName = GetProfileString(
                _T("Config"), _T("InitialFile"));
            if (!cmdInfo.m_strFileName.IsEmpty())
                cmdInfo.m_nShellCommand = CCommandLineInfo::FileOpen;
        }
    }
    ProcessShellCommand(cmdInfo);
    ...
}


这篇关于在MFC中覆盖OnFileOpen(ID_FILE_OPEN)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆