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()下,也还是这样。
#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()下,也还是这样。
解决方案 »
- VC++的项目怎么调用delphi写的动态库
- 请教一个关于CEdit显示滚动的问题,在线等~~~
- 高手请进来帮我看看我写的线程函数是不是有问题,急!!!!!!!!
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); 有谁跟踪过这段代码,知道这个HBRUSH hbr是怎么返回的吗?
- 怎么用ATL向导为一个ATL对象添加另外一个新的接口?
- 简
- 大家帮忙看看,程序编译问题
- 如何从DLL文件中导出LIB文件?
- 小弟有个课件《操作系统作业调度模拟(C语言实现)》能否帮忙实现!!!
- 如何取得 Web Browser 控件的 html 文件内容?
- CWaveFile Opne Write 都是无法解析的外部符号
- 求救:C++/MFC如何在代码中更改按钮控件的属性
STDMETHODIMP CSimpleShlExt::QueryContextMenu (
HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd,
UINT uidLastCmd, UINT uFlags )
{
return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, uCmdID);
}
中的uCmdID改为你插入的菜单数就可以了