[英]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:简而言之:
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.