⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emfexplorer.cpp

📁 Source code for EMFexplorer 1.0
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// CEMFexplorerApp message handlers


int CEMFexplorerApp::ExitInstance() 
{
	// Add your specialized code here and/or call the base class
	
	m_GDIPlus.SCExitInstance();
	return CWinApp::ExitInstance();
}

void CEMFexplorerApp::OnFileOpen() 
{
	CString sFilters(SC_EMFMODE_FILTERS_LOAD);
	CFileDialog dlg(TRUE, NULL, _T("*.emf"), OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,
		(LPCTSTR)sFilters);
	if (dlg.DoModal() != IDOK)
		return;

	OpenDocumentFile(dlg.GetPathName());
}

BOOL SCCanAccessClassRoot(CSingleDocTemplate* pDocTemplate)
{
	CString strFtype;
	pDocTemplate->GetDocString(strFtype, CDocTemplate::regFileTypeId);
	if (strFtype.IsEmpty())
		return FALSE;

	HKEY hTestKey = NULL;
	LONG lResult = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, 
		strFtype, 0, _T(""), 
		REG_OPTION_NON_VOLATILE, 
		KEY_ALL_ACCESS, NULL, 
		&hTestKey, NULL);
	if ((ERROR_SUCCESS == lResult) && (hTestKey != NULL))
	{
		// It's ok to call UpdateRegistry
		RegCloseKey(hTestKey);
		return TRUE;
	}
	return FALSE;
}

#define SC_REGSZ_SIZE(strg) ((_tcslen(strg)+1)*sizeof(TCHAR))

#ifndef SC_UNREGISTER
STDAPI SCRegisterMimeType(CSingleDocTemplate* pDocTemplate)
{
    HKEY        hkey = NULL;
    HKEY        hkey1 = NULL;
    BOOL        fErr = TRUE;
    TCHAR       szSubKey[513];

    // file extension for new mime type
    const TCHAR* pszMTExt = _T(".bgp");
    // text for new mime content type
    const TCHAR* pszMTContent = _T("application/bgp");
    // text for mimetype subkey
    const TCHAR* pszMTSubKey = _T("MIME\\DataBase\\Content Type\\application/bgp");
    // extension named value
    const TCHAR* pszMTExtVal = _T("Extension");
    // clsid
    const TCHAR* pszMTCLSID = _T("{BD61D528-D628-42E2-9F75-79B8535F78C1}");
    // clsid named value name
    const TCHAR* pszMTCLSIDVal = _T("CLSID");
    // content type named value name
    const TCHAR* pszMTContentVal = _T("Content Type");
    // EnableFullPage key
    const TCHAR* pszMTFullPage = _T("EnableFullPage");

    do 
    {
        // create new mime type key for our new mimetype.  Only necessary for new mime types
        if ( ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, pszMTSubKey, &hkey) )
            break;

        // add extension value to that mime type key to associate .mtp files with the 
        // application/x-mimetype mime type
        if ( ERROR_SUCCESS != RegSetValueEx(hkey, pszMTExtVal, 0, REG_SZ, 
            (const BYTE *)pszMTExt, SC_REGSZ_SIZE(pszMTExt)) )
            break;

        // Add class id to associate this object with the mime type
        if ( ERROR_SUCCESS != RegSetValueEx(hkey, pszMTCLSIDVal, 0, REG_SZ,
            (const BYTE *)pszMTCLSID, SC_REGSZ_SIZE(pszMTCLSID)) )
            break;

        RegCloseKey(hkey);

        // Register .bgp as a file extension this is only necessary for new file extensions, adding
        // a new player for .avi files for instance would not require this
        if ( ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, pszMTExt, &hkey) )
            break;

        // Add content type to associate this extension with the content type.  This is required
        // and is used when the mime type is unknown and IE looks up associations by extension
        if ( ERROR_SUCCESS != RegSetValueEx(hkey, pszMTContentVal, 0, REG_SZ,
            (const BYTE *)pszMTContent, SC_REGSZ_SIZE(pszMTContent)) )
            break;

        RegCloseKey(hkey);

        // Open the key under the control's clsid HKEY_CLASSES_ROOT\CLSID\<CLSID>
        wsprintf(szSubKey, _T("%s\\%s"), pszMTCLSIDVal, pszMTCLSID);
        if ( ERROR_SUCCESS != RegOpenKey(HKEY_CLASSES_ROOT, szSubKey, &hkey) )
            break;

        // Create the EnableFullPage and extension key under this so that we can display files
        // with the extension full frame in the browser
        wsprintf(szSubKey, _T("%s\\%s"), pszMTFullPage, pszMTExt);
        if ( ERROR_SUCCESS != RegCreateKey(hkey, szSubKey, &hkey1) )
            break;

		// If you deactivate this, you know what you're doing
#if 1
		// Make the object 'not insertable'
        if ( ERROR_SUCCESS != RegDeleteKey(hkey, _T("Insertable")) )
            break;
		RegCloseKey(hkey1);
		hkey1 = NULL;
        if ( ERROR_SUCCESS != RegCreateKey(hkey, _T("NotInsertable"), &hkey1) )
            break;

		if (pDocTemplate)
		{
			// under EMFexplorer.Document, add "NotInsertable"
			CString strFtype;
			pDocTemplate->GetDocString(strFtype, CDocTemplate::regFileTypeId);
			if (!strFtype.IsEmpty())
			{
				HKEY        hkey2 = NULL;
				strFtype += _T("\\NotInsertable");
				if ( ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, strFtype, &hkey2) )
					break;
				RegCloseKey(hkey2);
			}
		}
#endif

        fErr = FALSE;
    } while (FALSE);

    if ( hkey )
        RegCloseKey(hkey);

    if ( hkey1 )
        RegCloseKey(hkey1);

    if ( fErr )
        MessageBox(0, _T("Cannot register 'application/bgp' mime type"), _T("Registration Error"), MB_OK);

	return NOERROR;
}

#else

// Warning: this will only remove additional keys we added,
// not what is stored by RegisterShellTypes.
STDAPI SCUnRegisterMimeType(CSingleDocTemplate* pDocTemplate)
{
    HKEY        hkey = NULL;
    HKEY        hkey1 = NULL;
    BOOL        fErr = TRUE;
    TCHAR       szSubKey[513];

    // file extension for new mime type
    const TCHAR* pszMTExt = _T(".bgp");
    // text for new mime content type
    const TCHAR* pszMTContent = _T("application/bgp");
    // text for mimetype subkey
    const TCHAR* pszMTSubKey = _T("MIME\\DataBase\\Content Type\\application/bgp");
    // extension named value
    const TCHAR* pszMTExtVal = _T("Extension");
    // clsid
    const TCHAR* pszMTCLSID = _T("{BD61D528-D628-42E2-9F75-79B8535F78C1}");
    // clsid named value name
    const TCHAR* pszMTCLSIDVal = _T("CLSID");
    // content type named value name
    const TCHAR* pszMTContentVal = _T("Content Type");
    // EnableFullPage key
    const TCHAR* pszMTFullPage = _T("EnableFullPage");

    do 
    {
        // our new mimetype key.
        if ( ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, pszMTSubKey, &hkey) )
            break;

        // del extension value to that mime type
		RegDeleteKey(hkey, pszMTExtVal);
        // del class id to dissociate this object from the mime type
		RegDeleteKey(hkey, pszMTCLSIDVal);

        RegCloseKey(hkey);
		RegDeleteKey(HKEY_CLASSES_ROOT, pszMTSubKey);

        // UnRegister .bgp as a file extension
        if ( ERROR_SUCCESS != RegCreateKey(HKEY_CLASSES_ROOT, pszMTExt, &hkey) )
            break;

        // del content type to dissociate this extension from the content type.
		RegDeleteKey(hkey, pszMTContentVal);

        RegCloseKey(hkey);
		RegDeleteKey(HKEY_CLASSES_ROOT, pszMTExt);

        // Open the key under the control's clsid HKEY_CLASSES_ROOT\CLSID\<CLSID>
        wsprintf(szSubKey, _T("%s\\%s"), pszMTCLSIDVal, pszMTCLSID);
        if ( ERROR_SUCCESS != RegOpenKey(HKEY_CLASSES_ROOT, szSubKey, &hkey) )
            break;

        // del the EnableFullPage and extension key under it
        wsprintf(szSubKey, _T("%s\\%s"), pszMTFullPage, pszMTExt);
		RegDeleteKey(hkey, szSubKey);
		RegDeleteKey(hkey, pszMTFullPage);

		// If you deactivate this, you know what you're doing
#if 1
		// Make the object 'not insertable'
        RegDeleteKey(hkey, _T("Insertable"));
        RegDeleteKey(hkey, _T("NotInsertable"));
		RegCloseKey(hkey);
        wsprintf(szSubKey, _T("%s\\%s"), pszMTCLSIDVal, pszMTCLSID);
		// wont work if it contains keys we did not installed (auxUsertype, DefaultIcon, etc...)
		RegDeleteKey(HKEY_CLASSES_ROOT, szSubKey);


		if (pDocTemplate)
		{
			// under EMFexplorer.Document, add "NotInsertable"
			CString strFtype;
			pDocTemplate->GetDocString(strFtype, CDocTemplate::regFileTypeId);
			if (!strFtype.IsEmpty())
			{
				strFtype += _T("\\NotInsertable");
				RegDeleteKey(HKEY_CLASSES_ROOT, strFtype);
			}
		}
#endif

        fErr = FALSE;
    } while (FALSE);

    if ( fErr )
        MessageBox(0, _T("Cannot unregister 'application/bgp' mime type"), _T("UnRegistration Error"), MB_OK);

	return NOERROR;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -