1. 禁用右键菜单:
把OnCreate方法修改如下。
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CAxWindow wnd(m_hWnd);
wnd.ModifyStyle(0, WS_HSCROLL | WS_VSCROLL);
HRESULT hr = wnd.CreateControl(IDH_HTMLCTRL);
if (SUCCEEDED(hr))
{
CComObject<CHTMLCtrlUI> *pObject = NULL;
hr = CComObject<CHTMLCtrlUI>::CreateInstance(&pObject);
if (SUCCEEDED(hr) && pObject != NULL)
hr = wnd.SetExternalDispatch(static_cast<IHTMLCtrlUI*>(pObject));
}
//禁用菜单
CComPtr<IUnknown> spUnk;
AtlAxGetHost(m_hWnd, &spUnk);
CComQIPtr<IAxWinAmbientDispatch> spAmbient(spUnk);
spAmbient->put_AllowContextMenu(VARIANT_FALSE);
if (SUCCEEDED(hr))
hr = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_spBrowser);
return SUCCEEDED(hr) ? 0 : -1;
}