Пример #1
0
//
//   FUNCTION: UnregisterShellExtContextMenuHandler
//
//   PURPOSE: Unregister the context menu handler.
//
//   PARAMETERS:
//   * pszFileType - The file type that the context menu handler is
//     associated with. For example, '*' means all file types; '.txt' means
//     all .txt files. The parameter must not be NULL.
//   * clsid - Class ID of the component
//
//   NOTE: The function removes the {<CLSID>} key under
//   HKCR\<File Type>\shellex\ContextMenuHandlers in the registry.
//
HRESULT UnregisterShellExtContextMenuHandler(
    PCWSTR pszFileType, const CLSID& clsid)
{
    if (pszFileType == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // If pszFileType starts with '.', try to read the default value of the
    // HKCR\<File Type> key which contains the ProgID to which the file type
    // is linked.
    if (*pszFileType == L'.')
    {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal,
            sizeof(szDefaultVal));

        // If the key exists and its default value is not empty, use the
        // ProgID as the file type.
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
        {
            pszFileType = szDefaultVal;
        }
    }

    // Remove the HKCR\<File Type>\shellex\DragDropHandlers\{<CLSID>} key.
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
                     #ifdef CATCHCOPY_ROOT_MODE
                         L"%s\\shellex\\DragDropHandlers\\%s"
                     #else
                         L"Software\\Classes\\%s\\shellex\\DragDropHandlers\\%s"
                     #endif
                         , pszFileType, szCLSID);
    if (SUCCEEDED(hr))
    {
        hr = HRESULT_FROM_WIN32(RecursiveDeleteKey(
                            #ifdef CATCHCOPY_ROOT_MODE
                                HKEY_CLASSES_ROOT
                            #else
                                HKEY_CURRENT_USER
                            #endif
                                    , szSubkey));
    }

    return hr;
}
Пример #2
0
HRESULT
RegisterShellExtContextMenuHandler(
    PCWSTR pszFileType,
    const CLSID& clsid,
    PCWSTR pszFriendlyName
    )
{
    if (pszFileType == NULL)
        return E_INVALIDARG;

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // If pszFileType starts with '.', try to read the default value of the 
    // HKCR\<File Type> key which contains the ProgID to which the file type 
    // is linked.
    if (*pszFileType == L'.') {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(
            pszFileType, NULL, szDefaultVal, sizeof(szDefaultVal)
        );

        // If the key exists and its default value is not empty, use the 
        // ProgID as the file type.
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0') {
            pszFileType = szDefaultVal;
        }
    }

    // Create the key HKCR\<File Type>\shellex\ContextMenuHandlers\{<CLSID>}
    hr = StringCchPrintf(
        szSubkey,
        ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\ContextMenuHandlers\\%s",
        pszFileType,
        szCLSID
    );

    if (SUCCEEDED(hr)) {
        // Set the default value of the key.
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName);
    }

    return hr;
}
Пример #3
0
HRESULT
UnregisterShellExtContextMenuHandler(
    PCWSTR pszFileType,
    const CLSID& clsid
    )
{
    if (pszFileType == NULL)
        return E_INVALIDARG;

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // If pszFileType starts with '.', try to read the default value of the 
    // HKCR\<File Type> key which contains the ProgID to which the file type 
    // is linked.
    if (*pszFileType == L'.') {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, 
        sizeof(szDefaultVal));

        // If the key exists and its default value is not empty, use the 
        // ProgID as the file type.
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
            pszFileType = szDefaultVal;
    }

    // Remove the HKCR\<File Type>\shellex\ContextMenuHandlers\{<CLSID>} key.
    hr = StringCchPrintf(
        szSubkey,
        ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\ContextMenuHandlers\\%s",
        pszFileType,
        szCLSID
    );

    if (SUCCEEDED(hr))
        hr = HRESULT_FROM_WIN32(RegDeleteTree(HKEY_CLASSES_ROOT, szSubkey));

    return hr;
}
Пример #4
0
HRESULT RegisterShellExtContextMenuHandler(
    PCWSTR pszFileType, const CLSID& clsid, PCWSTR pszFriendlyName)
{
    if (pszFileType == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    //如果文件的类型是以'.'开头的,然后在注册表的HKCR\<File Type>下获取该文件类型的对应的Program ID来关联该文件
    if (*pszFileType == L'.')
    {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, 
            sizeof(szDefaultVal));

        // 如果该键存在且不为空, 使用ProgID 为该文件类型
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
        {
            pszFileType = szDefaultVal;
        }
    }

    // 创建键  HKCR\<File Type>\shellex\ContextMenuHandlers\{<CLSID>}
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, szCLSID);
    if (SUCCEEDED(hr))
    {
        // 为该键设置默认值.
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName);
    }

    return hr;
}
Пример #5
0
//
//   函数名称: RegisterShellExtInfotipHandler
//
//   作用: 注册shell 信息提示处理方法.
//
//   参数:
//   * pszFileType - 要处理文件的类型,如“*”代表所有的文件类型, 
//                   “.txt”代表.txt文件类型。参数不能为空
//   * clsid - 组件的类ID。
//
//   注意: 该方法在注册表中创建了以下注册信息。
//
//   HKCR
//   {
//      NoRemove <File Type>
//      {
//          NoRemove shellex
//          {
//              {00021500-0000-0000-C000-000000000046} = s '{<CLSID>}'
//          }
//      }
//   }
//
HRESULT RegisterShellExtInfotipHandler(PCWSTR pszFileType, const CLSID& clsid)
{
    if (pszFileType == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szCLSID[MAX_PATH];
    StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID));

    wchar_t szSubkey[MAX_PATH];

    // 如果 pszFileType以‘.’开始,就试着去找包含ProgID的HKCR\<FIle Type>的默认值
    if (*pszFileType == L'.')
    {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, 
            sizeof(szDefaultVal));

        // 如果key存在并且默认值不空,就用ProgID作为文件的类型
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
        {
            pszFileType = szDefaultVal;
        }
    }

    //创建注册项 
    // HKCR\<File Type>\shellex\{00021500-0000-0000-C000-000000000046}
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\{00021500-0000-0000-C000-000000000046}", pszFileType);
    if (SUCCEEDED(hr))
    {
        //设置注册项的默认值.
        hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, szCLSID);
    }

    return hr;
}
Пример #6
0
HRESULT OCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(
	PCWSTR pszFileType, PCWSTR pszFriendlyName)
{
	if (pszFileType == NULL)
	{
		return E_INVALIDARG;
	}

	HRESULT hr;
	
	wchar_t szSubkey[MAX_PATH];

	// If pszFileType starts with '.', try to read the default value of the 
	// HKCR\<File Type> key which contains the ProgID to which the file type 
	// is linked.
	if (*pszFileType == L'.')
	{
		wchar_t szDefaultVal[260];
		hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal,
			sizeof(szDefaultVal));

		// If the key exists and its default value is not empty, use the 
		// ProgID as the file type.
		if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
		{
			pszFileType = szDefaultVal;
		}
	}

	// Remove the HKCR\<File Type>\shellex\ContextMenuHandlers\{friendlyName} key.
	hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey),
		L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, pszFriendlyName);
	if (SUCCEEDED(hr))
	{
		hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey));
	}

	return hr;
}
Пример #7
0
//
//   函数名称: UnregisterShellExtInfotipHandler
//
//   作用:删除shell 信息提示处理方法。
//
//   参数:
//   * pszFileType - 要处理文件的类型,如“*”代表所有的文件类型, 
//                   “.txt”代表.txt文件类型。参数不能为空。
//   
//
//   注意:该函数删除了注册项:
//   HKCR\<File Type>\shellex\{00021500-0000-0000-C000-000000000046}.
//
HRESULT UnregisterShellExtInfotipHandler(PCWSTR pszFileType)
{
    if (pszFileType == NULL)
    {
        return E_INVALIDARG;
    }

    HRESULT hr;

    wchar_t szSubkey[MAX_PATH];

    // 如果 pszFileType以‘.’开始,就试着去找包含ProgID的HKCR\<FIle Type>的默认值
    if (*pszFileType == L'.')
    {
        wchar_t szDefaultVal[260];
        hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, 
            sizeof(szDefaultVal));

        // 如果key存在并且默认值不空,就用ProgID作为文件的类型
        if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0')
        {
            pszFileType = szDefaultVal;
        }
    }

    // 删除注册项:
    // HKCR\<File Type>\shellex\{00021500-0000-0000-C000-000000000046}
    hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), 
        L"%s\\shellex\\{00021500-0000-0000-C000-000000000046}", pszFileType);
    if (SUCCEEDED(hr))
    {
        hr = HRESULT_FROM_WIN32(RegDeleteTree(HKEY_CLASSES_ROOT, szSubkey));
    }

    return hr;
}