简体   繁体   English

将 DDE 注册的文件关联与 CDialog 应用程序一起使用?

[英]Using DDE registered file associations with CDialog app?

I know that SDI and MDI projects by design have the concept of a file type and that you can double-click from file explorer.我知道 SDI 和 MDI 项目的设计具有文件类型的概念,您可以从文件资源管理器中双击。 For example:例如:

BOOL CCommunityTalksApp::InitInstance()
{
    // Enable DDE Execute open
    EnableShellOpen();
    RegisterShellFileTypes(TRUE);

    // Process command line arguments (standard shell commands, DDE, file open)
    if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
        cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing ;

    // Dispatch commands specified on the command line
    if ( !ProcessShellCommand( cmdInfo ) )
        return FALSE;
}

But I have a CDialog project which has two editors.但我有一个有两个编辑器的CDialog项目。 Assuming that my installer has registered the two needed file type associations how do then get my CDialog based app to detect the file that was opened and direct it to the relevant editor?假设我的安装程序已经注册了两个所需的文件类型关联,那么如何让我的基于CDialog的应用程序检测已打开的文件并将其定向到相关编辑器?

Is this done in InitInstance ?这是在InitInstance中完成的吗?

In short:简而言之:

  • Did the user double-click a file?用户是否双击文件?
  • Was it a SRR or MWB file?是 SRR 还是 MWB 文件?
  • Then post / cache a message to the m_pMainDlg for it to open the stated file in the appropriate editor.然后将消息发布/缓存到m_pMainDlg以便它在适当的编辑器中打开所述文件。

How do I do the first two bullet points?我如何做前两个要点?

Is this done in InitInstance ?这是在InitInstance中完成的吗?

Yes, you can use ParseCommandLine or handle m_lpCmdLine directly.是的,您可以使用ParseCommandLine或直接处理m_lpCmdLine

Did the user double-click a file?用户是否双击文件?

Does it really matter?真的有关系吗? That is more complicated to tell.说起来更复杂。 If the app was launched by (say) ABC association, it could be that the user double-clicked an ABC file, but it could also be that they ran a batch file which did a start somefile.ABC , or anything else that eventually resolved to a ShellExecute[Ex] with an ABC file.如果应用程序是由(例如)ABC 关联启动的,则可能是用户双击了一个 ABC 文件,但也可能是他们运行了一个批处理文件,该批处理文件执行了start somefile.ABC或其他任何最终解决的问题到带有 ABC 文件的ShellExecute[Ex]

Was it a SRR or MWB file?是 SRR 还是 MWB 文件?

Assuming those are the registered extensions, they would be part of the complete filename (name + extension) received in m_lpCmdLine .假设这些是注册的扩展名,它们将是m_lpCmdLine中收到的完整文件名(名称+扩展名)的一部分。 For a single file, the filename would also be in CCommandLineInfo::m_strFileName if CWinApp::ParseCommandLine was called.对于单个文件,如果调用了CWinApp::ParseCommandLine ,文件名也将在CCommandLineInfo::m_strFileName中。

Then post / cache a message to the m_pMainDlg for it to open the stated file in the appropriate editor.然后将消息发布/缓存到 m_pMainDlg 以便它在适当的编辑器中打开所述文件。

From InitInstance you would normally pass the filename(s) to the constructor of the dialog, and the dialog itself would later post the message at the end of OnInitDialog once everything is in place.InitInstance您通常会将文件名传递给对话框的构造函数,一旦一切就绪,对话框本身稍后会在OnInitDialog的末尾发布消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对CWnd而不是CDialog使用OnNcHItTest - Using OnNcHItTest for a CWnd not CDialog 在CPropertySheet / CDialog上将ModifyStyle与WS_THICKFRAME一起使用 - Using ModifyStyle with WS_THICKFRAME on a CPropertySheet/CDialog 使用 MFC 以编程方式更改文件扩展名关联? - Changing file extension associations programatically using MFC? 使用任务栏功能的CFrameWnd SetProgressBarPosition方法,以及MFC中的CDialog - using CFrameWnd SetProgressBarPosition method of the taskbar feature, with CDialog in MFC 使用CSplitterWndEx将两个对话框(CDialog)添加到可停靠窗格(CDockablePane) - Adding two dialogs(CDialog) to a dockablepane(CDockablePane) using CSplitterWndEx 基于CDialog的应用程序启动时,如何将我的辅助对话框窗口置于顶部? - How to bring my secondary dialog window to the top when the CDialog-based app starts? MFC应用程序DialogBased使用propertyPage,CDialog的DoModal()不会打开任何对话框 - MFC application DialogBased using propertyPage, DoModal() for a CDialog don't open any Dialog 在资源管理器中打开与我们的应用程序关联的文件时,为什么会出现DDE错误? - Why am I getting a DDE error when opening a file in Explorer that associated with our application? CDialog的多个子级 - Multiple levels of children to a CDialog 如何制作一个CDialog? - How to make a CDialog?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM