张志松
记录工作点滴,留下人生轨迹。(zezese@163.com)
posts - 68,  comments - 11,  trackbacks - 0

VS2003

头文件

#pragma once

#include <afxhtml.h>

class CWebBrowser : public CHtmlView
{
 DECLARE_DYNCREATE(CWebBrowser)
 DECLARE_MESSAGE_MAP()

public:

 CWebBrowser();         
 virtual ~CWebBrowser();

 BOOL IsContextMenuEnabled() const { return m_bContextMenuEnabled; }
 void EnableContextMenu(BOOL newVal = TRUE) { m_bContextMenuEnabled = newVal; }

protected:

 virtual void PostNcDestroy();
 virtual BOOL PreTranslateMessage(MSG* pMsg);

 afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
 afx_msg void OnDestroy();

protected:
 virtual void OnTitleChange(LPCTSTR lpszText);
 virtual void OnDocumentComplete(LPCTSTR lpszURL);

protected:

 BOOL m_bContextMenuEnabled;

};

实现文件


#include "stdafx.h"
#include ".\WebBrowser.h"


// CWebBrowser

IMPLEMENT_DYNCREATE(CWebBrowser, CHtmlView)

CWebBrowser::CWebBrowser()
: m_bContextMenuEnabled(TRUE)
{
}

CWebBrowser::~CWebBrowser()
{
}

BEGIN_MESSAGE_MAP(CWebBrowser, CHtmlView)
 ON_WM_DESTROY()
 ON_WM_MOUSEACTIVATE()
END_MESSAGE_MAP()


// CWebBrowser 消息处理程序

void CWebBrowser::OnTitleChange(LPCTSTR lpszText)
{
 // TODO: 在此添加专用代码和/或调用基类

 CHtmlView::OnTitleChange(lpszText);
}

void CWebBrowser::OnDocumentComplete(LPCTSTR lpszURL)
{
 // TODO: 在此添加专用代码和/或调用基类

 CHtmlView::OnDocumentComplete(lpszURL);
}


void CWebBrowser::OnDestroy()
{
 m_pBrowserApp.Release();

 m_wndBrowser.DestroyWindow();

 CWnd::OnDestroy();
}

int CWebBrowser::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
 return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
}

void CWebBrowser::PostNcDestroy()
{
//防止自删除
 //CHtmlView::PostNcDestroy();
}

BOOL CWebBrowser::PreTranslateMessage(MSG* pMsg)
{
 if (WM_RBUTTONUP == pMsg->message || WM_CONTEXTMENU == pMsg->message)
 {
  if (!IsContextMenuEnabled()) //屏蔽右键菜单和键盘菜单键
  {
   return TRUE;
  }
 }

 return CHtmlView::PreTranslateMessage(pMsg);
}

posted on 2010-12-28 12:59 张志松 阅读(2920) 评论(0)  编辑 收藏 引用 所属分类: VC/MFC

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2011年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

转载

搜索

  •  

最新评论

阅读排行榜

评论排行榜