void CDocManager::RegisterShellFileTypes(BOOL bCompat) { ASSERT(!m_templateList.IsEmpty()); // must have some doc templates CString strPathName, strTemp; AfxGetModuleShortFileName(AfxGetInstanceHandle(), strPathName); POSITION pos = m_templateList.GetHeadPosition(); //针对每种文档模板进行注册 for (int nTemplateIndex = 1; pos != NULL; nTemplateIndex++) { CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos); CString strOpenCommandLine = strPathName; CString strPrintCommandLine = strPathName; CString strPrintToCommandLine = strPathName; CString strDefaultIconCommandLine = strPathName; if (bCompat) { CString strIconIndex; HICON hIcon = ::ExtractIcon(AfxGetInstanceHandle(), strPathName, nTemplateIndex); if (hIcon != NULL) { strIconIndex.Format(_afxIconIndexFmt, nTemplateIndex); DestroyIcon(hIcon); } else { strIconIndex.Format(_afxIconIndexFmt, DEFAULT_ICON_INDEX); } strDefaultIconCommandLine += strIconIndex; } CString strFilterExt, strFileTypeId, strFileTypeName; if (pTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId) && !strFileTypeId.IsEmpty()) { // enough info to register it if (!pTemplate->GetDocString(strFileTypeName, CDocTemplate::regFileTypeName)) strFileTypeName = strFileTypeId; // use id name ASSERT(strFileTypeId.Find(' ') == -1); // no spaces allowed // first register the type ID of our server if (!_AfxSetRegKey(strFileTypeId, strFileTypeName)) continue; // just skip it if (bCompat) { // path/DefaultIcon = path,1 strTemp.Format(_afxDefaultIconFmt, (LPCTSTR)strFileTypeId); if (!_AfxSetRegKey(strTemp, strDefaultIconCommandLine)) continue; // just skip it } // If MDI Application if (!pTemplate->GetDocString(strTemp, CDocTemplate::windowTitle) || strTemp.IsEmpty()) { // path/shell/open/ddeexec = [open("%1")] strTemp.Format(_afxShellOpenFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxDDEExec); if (!_AfxSetRegKey(strTemp, _afxDDEOpen)) continue; // just skip it if (bCompat) { // path/shell/print/ddeexec = [print("%1")] strTemp.Format(_afxShellPrintFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxDDEExec); if (!_AfxSetRegKey(strTemp, _afxDDEPrint)) continue; // just skip it // path/shell/printto/ddeexec = [printto("%1","%2","%3","%4")] strTemp.Format(_afxShellPrintToFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxDDEExec); if (!_AfxSetRegKey(strTemp, _afxDDEPrintTo)) continue; // just skip it // path/shell/open/command = path /dde // path/shell/print/command = path /dde // path/shell/printto/command = path /dde strOpenCommandLine += _afxDDEArg; strPrintCommandLine += _afxDDEArg; strPrintToCommandLine += _afxDDEArg; } else { strOpenCommandLine += _afxOpenArg; } } else { // path/shell/open/command = path filename // path/shell/print/command = path /p filename // path/shell/printto/command = path /pt filename printer driver port strOpenCommandLine += _afxOpenArg; if (bCompat) { strPrintCommandLine += _afxPrintArg; strPrintToCommandLine += _afxPrintToArg; } } // path/shell/open/command = path filename strTemp.Format(_afxShellOpenFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxCommand); if (!_AfxSetRegKey(strTemp, strOpenCommandLine)) continue; // just skip it if (bCompat) { // path/shell/print/command = path /p filename strTemp.Format(_afxShellPrintFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxCommand); if (!_AfxSetRegKey(strTemp, strPrintCommandLine)) continue; // just skip it // path/shell/printto/command = path /pt filename printer driver port strTemp.Format(_afxShellPrintToFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxCommand); if (!_AfxSetRegKey(strTemp, strPrintToCommandLine)) continue; // just skip it } pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt); if (!strFilterExt.IsEmpty()) { ASSERT(strFilterExt[0] == '.'); LONG lSize = _MAX_PATH * 2; LONG lResult = ::RegQueryValue(HKEY_CLASSES_ROOT, strFilterExt, strTemp.GetBuffer(lSize), &lSize); strTemp.ReleaseBuffer(); if (lResult != ERROR_SUCCESS || strTemp.IsEmpty() || strTemp == strFileTypeId) { // no association for that suffix if (!_AfxSetRegKey(strFilterExt, strFileTypeId)) continue; if (bCompat) { strTemp.Format(_afxShellNewFmt, (LPCTSTR)strFilterExt); (void)_AfxSetRegKey(strTemp, _afxShellNewValue, _afxShellNewValueName); } } } } } } |