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. 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. 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?
Is this done in InitInstance?
In short:
- Did the user double-click a file?
- Was it a SRR or MWB file?
- Then post / cache a message to the
m_pMainDlgfor it to open the stated file in the appropriate editor.
How do I do the first two bullet points?
Yes, you can use
ParseCommandLineor handlem_lpCmdLinedirectly.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 aShellExecute[Ex]with an ABC file.Assuming those are the registered extensions, they would be part of the complete filename (name + extension) received in
m_lpCmdLine. For a single file, the filename would also be inCCommandLineInfo::m_strFileNameifCWinApp::ParseCommandLinewas called.From
InitInstanceyou would normally pass the filename(s) to the constructor of the dialog, and the dialog itself would later post the message at the end ofOnInitDialogonce everything is in place.