在自定义浏览器控件中使用IE默认右键菜单中的部分项及其功能,去除那些烦人的垃圾项和查看源代码等项,方法如下:IDocHostUIHandler_MY::ShowContextMenu(DWORD dwID,POINT __RPC_FAR *ppt,
IUnknown __RPC_FAR *pcmdtReserved,
IDispatch __RPC_FAR *pdispReserved)
{
HWND hwnd;
CComPtr<IOleCommandTarget> spCT;
CComPtr<IOleWindow> spWnd;
HRESULT hr = pcmdtReserved->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);
hr = pcmdtReserved->QueryInterface(IID_IOleWindow, (void**)&spWnd);
hr = spWnd->GetWindow(&hwnd);
HINSTANCE hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL"));
if (hinstSHDOCLC == NULL)
{
// 载入模块错误 -- 采用浏览器控件的默认处理
return E_NOTIMPL;
}
HMENU hMenu=LoadMenu(hinstSHDOCLC,MAKEINTRESOURCE(24641));
hMenu=GetSubMenu(hMenu,dwID);
int num=GetMenuItemCount(hMenu);
UINT id;
for(int i=num-1;i>-1;i--)//删除所有其他菜单 {
id=GetMenuItemID(hMenu,i);
if(id==16 || id==15 || id==26 || id==31 || id==2270 || id==17) continue;//保留剪切,复制,粘贴,全选,图片另存为,删除
if(id>2379 && id<2387) break;//垂直滚动条:滚动至此,上,下,向上翻页,向下翻页,向上滚动,向下滚动
if(id>2386 && id<2393) break;//水平滚动条
DeleteMenu(hMenu, id, MF_BYCOMMAND);
}
if(GetMenuItemCount(hMenu)>0)
{
//显示快捷菜单
int iSelection = ::TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
ppt->x,ppt->y,0,hwnd,(RECT*)NULL);
//发送选定的快捷菜单项目指令到外壳
LRESULT lr = ::SendMessage(hwnd, WM_COMMAND, iSelection, NULL);
}
FreeLibrary(hinstSHDOCLC);
return S_OK;
}