使用 DDE 注册文件关联与 CDialog 应用程序?
Using DDE registered file associations with CDialog app?
我知道 SDI 和 MDI 项目在设计上有文件类型的概念,您可以从文件资源管理器中双击。例如:
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;
}
但我有一个 CDialog
项目,其中有两个编辑器。假设我的安装程序已经注册了两个所需的文件类型关联,那么如何让我的基于 CDialog
的应用程序检测打开的文件并将其定向到相关编辑器?
这是在 InitInstance
完成的吗?
简而言之:
- 用户是否双击文件?
- 它是 SRR 还是 MWB 文件?
- 然后 post/将消息缓存到
m_pMainDlg
以便它在适当的编辑器中打开指定的文件。
如何处理前两个要点?
Is this done in InitInstance
?
是的,您可以使用ParseCommandLine
或直接处理m_lpCmdLine
。
Did the user double-click a file?
真的重要吗?说起来就更复杂了。如果该应用程序是由(比如说)ABC 协会启动的,则可能是用户双击了一个 ABC 文件,但也可能是他们 运行 执行 start somefile.ABC
的批处理文件,或者最终通过 ABC 文件解析为 ShellExecute[Ex]
的任何其他内容。
Was it a SRR or MWB file?
假设这些是已注册的扩展名,它们将是 m_lpCmdLine
中收到的完整文件名(名称 + 扩展名)的一部分。对于单个文件,如果调用 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.
从 InitInstance
开始,您通常会将文件名传递给对话框的构造函数,对话框本身稍后会 post OnInitDialog
末尾的消息一次一切就绪。
我知道 SDI 和 MDI 项目在设计上有文件类型的概念,您可以从文件资源管理器中双击。例如:
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;
}
但我有一个 CDialog
项目,其中有两个编辑器。假设我的安装程序已经注册了两个所需的文件类型关联,那么如何让我的基于 CDialog
的应用程序检测打开的文件并将其定向到相关编辑器?
这是在 InitInstance
完成的吗?
简而言之:
- 用户是否双击文件?
- 它是 SRR 还是 MWB 文件?
- 然后 post/将消息缓存到
m_pMainDlg
以便它在适当的编辑器中打开指定的文件。
如何处理前两个要点?
Is this done in
InitInstance
?
是的,您可以使用ParseCommandLine
或直接处理m_lpCmdLine
。
Did the user double-click a file?
真的重要吗?说起来就更复杂了。如果该应用程序是由(比如说)ABC 协会启动的,则可能是用户双击了一个 ABC 文件,但也可能是他们 运行 执行 start somefile.ABC
的批处理文件,或者最终通过 ABC 文件解析为 ShellExecute[Ex]
的任何其他内容。
Was it a SRR or MWB file?
假设这些是已注册的扩展名,它们将是 m_lpCmdLine
中收到的完整文件名(名称 + 扩展名)的一部分。对于单个文件,如果调用 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.
从 InitInstance
开始,您通常会将文件名传递给对话框的构造函数,对话框本身稍后会 post OnInitDialog
末尾的消息一次一切就绪。