ATL创建HTML Control右键菜单处理

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 *pObject = NULL;
		hr = CComObject::CreateInstance(&pObject);
		if (SUCCEEDED(hr) && pObject != NULL)
			hr = wnd.SetExternalDispatch(static_cast(pObject));
	}
    //禁用菜单
    CComPtr spUnk;
    AtlAxGetHost(m_hWnd, &spUnk);
    CComQIPtr spAmbient(spUnk);
    spAmbient->put_AllowContextMenu(VARIANT_FALSE);

	if (SUCCEEDED(hr))
		hr = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_spBrowser);

	return SUCCEEDED(hr) ? 0 : -1;
}


你可能感兴趣的:(C++)