Click here to Skip to main content
15,895,709 members
Articles / Desktop Programming / MFC

How to customize the context menus of a WebBrowser control via the IDocHostUIHandler interface.

Rate me:
Please Sign up or sign in to vote.
4.93/5 (46 votes)
27 Oct 2003CPOL24 min read 543.7K   12.4K   132  
This article describes how we can customize the contextual menus of the WebBrowser control, by implementing the IDocHostUIHandler.
// WebBrowserView.h : interface of the CWebBrowserView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_WEBBROWSERVIEW_H__2AAC70ED_5757_4FC2_B818_CC83E07E7904__INCLUDED_)
#define AFX_WEBBROWSERVIEW_H__2AAC70ED_5757_4FC2_B818_CC83E07E7904__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CWebCtrlInterFace;

class CWebBrowserView : public CHtmlView
{
protected: // create from serialization only
	CWebBrowserView();
	DECLARE_DYNCREATE(CWebBrowserView)

// Attributes
public:
	CWebBrowserDoc* GetDocument();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CWebBrowserView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual void OnInitialUpdate(); // called first time after construct
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CWebBrowserView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	CWebCtrlInterFace	*m_iClientSite;
	BOOL				m_SHDOCLC_DLL_Found;

// Generated message map functions
protected:
	//{{AFX_MSG(CWebBrowserView)
	afx_msg void On_CMM_NoContextMenu();
	afx_msg void OnUpdate_CMM_NoContextMenu(CCmdUI* pCmdUI);
	afx_msg void On_CMM_NoViewSource();
	afx_msg void OnUpdate_CMM_NoViewSource(CCmdUI* pCmdUI);
	afx_msg void On_CMM_TextSelectionMenu();
	afx_msg void OnUpdate_CMM_TextSelectionMenu(CCmdUI* pCmdUI);
	afx_msg void On_CMM_FullSupport();
	afx_msg void OnUpdate_CMM_FullSupport(CCmdUI* pCmdUI);
	afx_msg void On_CMM_CustomMenu();
	afx_msg void OnUpdate_CMM_CustomMenu(CCmdUI* pCmdUI);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnNcDestroy();
};

#ifndef _DEBUG  // debug version in WebBrowserView.cpp
inline CWebBrowserDoc* CWebBrowserView::GetDocument()
   { return (CWebBrowserDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_WEBBROWSERVIEW_H__2AAC70ED_5757_4FC2_B818_CC83E07E7904__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Greece Greece
I live in Greece with my wife and our two daughters. I am a professional software developer since 1999, using mostly C/C++ in my work.

My main expertise are: C/C++, STL, software optimization, generic programming and debugging. I am also very experienced in client–server programming, communications, concurrent programming, software security and cryptography. Finally, in my early professional years, I have worked a lot on cross-platform programming (Mac+Win).

I am familiar with the MFC, wxWidgets and Cplat GUI frameworks and the Python, Java, Pascal, Fortran, Prolog and Rexx programming languages.

Comments and Discussions