1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
void CMonApp::RegisterShellFileTypes(BOOL bCompat)
{
ASSERT(!m_templateList.IsEmpty()); // must have some doc templates
const TCHAR SHELL_OPEN[] = _T("%s\\shell\\open\\%s");
const TCHAR SHELL_PRINT[] = _T("%s\\shell\\print\\%s");
const TCHAR SHELL_PRINTTO[] = _T("%s\\shell\\printto\\%s");
const TCHAR DEFAULT_ICON[] = _T("%s\\DefaultIcon");
const TCHAR SHELL_NEW[] = _T("%s\\ShellNew");
const TCHAR ICON_INDEX[] = _T(",%d");
const TCHAR COMMAND[] = _T("command");
const TCHAR OPEN_ARG[] = _T(" \"%1\"");
const TCHAR PRINT_ARG[] = _T(" /p \"%1\"");
const TCHAR PRINTTO_ARG[] = _T(" /pt \"%1\" \"%2\" \"%3\" \"%4\"");
const TCHAR DDE_ARG[] = _T(" /dde");
const TCHAR DDE_EXEC[] = _T("ddeexec");
const TCHAR DDE_OPEN[] = _T("[open(\"%1\")]");
const TCHAR DDE_PRINT[] = _T("[print(\"%1\")]");
const TCHAR DDE_PTINTTO[] = _T("[printto(\"%1\",\"%2\",\"%3\",\"%4\")]");
const TCHAR SHELL_NEW_NAME[] = _T("NullFile");
const TCHAR SHELL_NEW_VALUE[] = _T("");
CString strTemp;
TCHAR strPathName[256];
GetModuleFileName(NULL,strPathName,255);
POSITION pos = GetFirstDocTemplatePosition();
for (int nTemplateIndex = 1; pos != NULL; nTemplateIndex++)
{
//CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
CDocTemplate* pTemplate = GetNextDocTemplate(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(ICON_INDEX, nTemplateIndex);
DestroyIcon(hIcon);
}
else
{
strIconIndex.Format(ICON_INDEX, 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 (!SetRegKey(strFileTypeId, strFileTypeName))
continue; // just skip it
if (bCompat)
{
// path\DefaultIcon = path,1
strTemp.Format(DEFAULT_ICON, (LPCTSTR)strFileTypeId);
if (!SetRegKey(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(SHELL_OPEN, (LPCTSTR)strFileTypeId,
(LPCTSTR)DDE_EXEC);
if (!SetRegKey(strTemp, DDE_OPEN))
continue; // just skip it
if (bCompat)
{
// path\shell\print\ddeexec = [print("%1")]
strTemp.Format(SHELL_PRINT, (LPCTSTR)strFileTypeId,
(LPCTSTR)DDE_EXEC);
if (!SetRegKey(strTemp, DDE_PRINT))
continue; // just skip it
// path\shell\printto\ddeexec = [printto("%1","%2","%3","%4")]
strTemp.Format(SHELL_PRINTTO, (LPCTSTR)strFileTypeId,
(LPCTSTR)DDE_EXEC);
if (!SetRegKey(strTemp, DDE_PTINTTO))
continue; // just skip it
// path\shell\open\command = path /dde
// path\shell\print\command = path /dde
// path\shell\printto\command = path /dde
strOpenCommandLine += DDE_ARG;
strPrintCommandLine += DDE_ARG;
strPrintToCommandLine += DDE_ARG;
}
else
{
strOpenCommandLine += OPEN_ARG;
}
}
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 += OPEN_ARG;
if (bCompat)
{
strPrintCommandLine += PRINT_ARG;
strPrintToCommandLine += PRINTTO_ARG;
}
}
// path\shell\open\command = path filename
strTemp.Format(SHELL_OPEN, (LPCTSTR)strFileTypeId,
(LPCTSTR)COMMAND);
if (!SetRegKey(strTemp, strOpenCommandLine))
continue; // just skip it
if (bCompat)
{
// path\shell\print\command = path /p filename
strTemp.Format(SHELL_PRINT, (LPCTSTR)strFileTypeId,
(LPCTSTR)COMMAND);
if (!SetRegKey(strTemp, strPrintCommandLine))
continue; // just skip it
// path\shell\printto\command = path /pt filename printer driver port
strTemp.Format(SHELL_PRINTTO, (LPCTSTR)strFileTypeId,
(LPCTSTR)COMMAND);
if (!SetRegKey(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 (!SetRegKey(strFilterExt, strFileTypeId))
continue;
if (bCompat)
{
strTemp.Format(SHELL_NEW, (LPCTSTR)strFilterExt);
(void)SetRegKey(strTemp, SHELL_NEW_VALUE, SHELL_NEW_NAME);
}
}
}
}
}
} |
Partager