void CWinAppSingle::RegisterShellFileTypesEx( BOOL bCompat /*FALSE*/, BOOL bRegister /*TRUE*/ ) { // Register all application document types: if( bRegister == TRUE ) CWinApp::RegisterShellFileTypes( bCompat ); // Now register SDI document dde open. // Loop through the document templates: POSITION pos = GetFirstDocTemplatePosition(); while( pos != NULL ) { CString strFileTypeId( _T("") ); CDocTemplate* pTemplate = GetNextDocTemplate( pos ); if( pTemplate->GetDocString( strFileTypeId, CDocTemplate::regFileTypeId ) && !strFileTypeId.IsEmpty() ) { // CDocTemplate::windowTitle is present only in the document template // for SDI applications. So, we detected SDI application and should // overregister shell file types : CString strTemp( _T("") ); if ( pTemplate->GetDocString( strTemp, CDocTemplate::windowTitle ) && !strTemp.IsEmpty() ) { // path\shell\open\ddeexec = [open("%1")] strTemp.Format( _T( "%s\\shell\\open\\%s" ), (LPCTSTR)strFileTypeId, _T( "ddeexec" ) ); #if ( _MFC_VER >= 0x0700 ) CRegKey reg( HKEY_CLASSES_ROOT ); #else CRegKey reg; reg.Attach( HKEY_CLASSES_ROOT ); #endif if( bRegister ) { if( reg.SetKeyValue( strTemp, _T( "[open(\"%1\")]" ) ) == ERROR_SUCCESS ) { strTemp += _T( "\\Application" ); OSVERSIONINFO osvi = { 0 }; osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); ::GetVersionEx( & osvi ); if( !( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 5 && osvi.dwMinorVersion >= 1 ) ) { reg.SetKeyValue( strTemp, AfxGetAppName() ); } else reg.DeleteSubKey( strTemp ); } } else // Unregister 'ddeexec' registry entry: reg.RecurseDeleteKey( strTemp ); #if ( _MFC_VER >= 0x0700 ) reg.Flush(); #else ::RegFlushKey( reg ); #endif reg.Close(); } } } // Unregister all application document types: if( bRegister == FALSE ) CWinApp::UnregisterShellFileTypes(); }