vc++ 6.0上编译的主要实现代码如下:#include "stdafx.h"
#include "resource.h"
#include "SimpleExt.h"
#include "SimpleShlExt.h"
#include <oleidl.h>
// CSimpleShlExtSTDMETHODIMP CSimpleShlExt::Initialize (
    LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID )
{
MessageBox(NULL,"Initialize","外面",MB_OK);
return S_OK;
}STDMETHODIMP CSimpleShlExt::QueryContextMenu (
    HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd,
    UINT uidLastCmd, UINT uFlags )
{
    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if ( uFlags & CMF_DEFAULTONLY )
        return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 );         UINT uCmdID = uidFirstCmd;
char *szMenuText_Popup = "自定义菜单";
char *szMenuText_1 = "AAA";
char *szMenuText_2 = "自定义菜单2...";
char *szMenuText_3 = "自定义菜单3...";
char *szMenuText_4 = "自定义菜单4..."; InsertMenu(hmenu, uMenuIndex, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); 
 uMenuIndex++;  HMENU hSubMenu = CreateMenu();  if(hSubMenu)
 {
  InsertMenu(hSubMenu, 0, MF_STRING  | MF_BYPOSITION, uCmdID++, szMenuText_1);   InsertMenu(hSubMenu, 1, MF_STRING  | MF_BYPOSITION, uCmdID++, szMenuText_2);   InsertMenu(hSubMenu, 2, MF_STRING  | MF_BYPOSITION, uCmdID++, szMenuText_3);   InsertMenu(hSubMenu, 3, MF_STRING  | MF_BYPOSITION, uCmdID++, szMenuText_4);
 }  InsertMenu(hmenu, uMenuIndex, MF_STRING | MF_POPUP | MF_BYPOSITION, (UINT_PTR)hSubMenu, szMenuText_Popup);
 //(UINT_PTR)hSubMenu当参数uFlags设置为MF_POPUP时,指定下拉式菜单或子菜单的句柄。 
 uMenuIndex++;  InsertMenu(hmenu, uMenuIndex, MF_SEPARATOR | MF_BYPOSITION,0, NULL);  uMenuIndex++;  return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, uCmdID );
}STDMETHODIMP CSimpleShlExt::GetCommandString (
    UINT idCmd, UINT uFlags, UINT* pwReserved, LPSTR pszName, UINT cchMax )
{
USES_CONVERSION;    // Check idCmd, it must be 0 since we have only one menu item.
    if ( 0 != idCmd )
        return E_INVALIDARG;    // If Explorer is asking for a help string, copy our string into the
    // supplied buffer.
    if ( uFlags & GCS_HELPTEXT )
        {
        LPCTSTR szText = _T("This is the simple shell extension's help");        if ( uFlags & GCS_UNICODE )
            {
            // We need to cast pszName to a Unicode string, and then use the
            // Unicode string copy API.
            lstrcpynW ( (LPWSTR) pszName, T2CW(szText), cchMax );
            }
        else
            {
            // Use the ANSI string copy API to return the help string.
            lstrcpynA ( pszName, T2CA(szText), cchMax );
            }        return S_OK;
        }    return E_INVALIDARG;
}STDMETHODIMP CSimpleShlExt::InvokeCommand ( LPCMINVOKECOMMANDINFO pCmdInfo )
{
    // If lpVerb really points to a string, ignore this function call and bail out.
    if ( 0 != HIWORD( pCmdInfo->lpVerb ) )
        return E_INVALIDARG;    // Get the command index - the only valid one is 0.
    switch ( LOWORD( pCmdInfo->lpVerb) )
        {
        case 0:
            {
            return S_OK;
            }
        break;        default:
            return E_INVALIDARG;
        break;
        }
}
注册表方面是这样写的:HKCR
{
    NoRemove CLSID
    {
        ForceRemove {5E2121EE-0300-11D4-8D3B-444553540000} = s 'SimpleShlExt Class'
        {
            InprocServer32 = s '%MODULE%'
            {
                val ThreadingModel = s 'Apartment'
            }
        }
    }
    
NoRemove Directory
    {
        NoRemove Background
        {
            NoRemove shellex
            {
NoRemove ContextMenuHandlers
{
ForceRemove SimpleShlExt = s '{5E2121EE-0300-11D4-8D3B-444553540000}'
}
            }
        }
    }
}    当我在桌面上按右键时,MessageBox正确的提示了Initialize,然后也把菜单插入了右键菜单,但当我复制了一个文件,按下粘贴时,又弹出了了Initialize的提示,想问问这个什么原因?是不是说按下粘贴是也会调用shell 扩展的Initialize(),而已我试过把MessageBox的提示写在QueryContextMenu()下,也还是这样。