简体   繁体   中英

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. 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_pMainDlg for it to open the stated file in the appropriate editor.

How do I do the first two bullet points?

Is this done in InitInstance ?

Yes, you can use ParseCommandLine or handle m_lpCmdLine directly.

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.

Was it a SRR or MWB 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 in CCommandLineInfo::m_strFileName if CWinApp::ParseCommandLine was called.

Then post / cache a message to the m_pMainDlg for it to open the stated file in the appropriate editor.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM