Knowledge Base Nr: 00090 HtmlCtrl.cpp - http://www.swe-kaiser.de
Downloads:
MFC: IE Browser-Control in MFC-Dialogen einsetzen
//abgeleitet von CHTMLView
//volle unterstützung von javascript, applets, links...
//einsprung in cpp-code über <a href="app:myfunc">text</a> tags
//(quelle: System Journal 3/2000)
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0, runs on Windows 98 and NT too.
//in stdafx.h includieren:
#include <afxcview.h> // MFC support for Windows 95 Common Controls
#include <afxhtml.h> // MFC support for Windows 95 Common Controls
class CHtmlCtrl : public CHtmlView {
public:
CHtmlCtrl() { }
~CHtmlCtrl() { }
BOOL CreateFromStatic(UINT nID, CWnd* pParent);
// Normally, CHtmlView destroys itself in PostNcDestroy,
// but we don't want to do that for a control since a control
// is usually implemented as a stack object in a dialog.
//
virtual void PostNcDestroy() { }
// overrides to bypass MFC doc/view frame dependencies
afx_msg void OnDestroy();
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg);
// override to trap "app:" pseudo protocol
virtual void OnBeforeNavigate2( LPCTSTR lpszURL,
DWORD nFlags,
LPCTSTR lpszTargetFrameName,
CByteArray& baPostedData,
LPCTSTR lpszHeaders,
BOOL* pbCancel );
// override to handle links to "app:mumble...". lpszWhere will be "mumble"
virtual void OnAppCmd(LPCTSTR lpszWhere);
DECLARE_MESSAGE_MAP();
DECLARE_DYNAMIC(CHtmlCtrl)
};
//////////////////
// Specialized derivation to handle "button" click
//
class CMyHtmlCtrl : public CHtmlCtrl {
virtual void OnAppCmd(LPCTSTR lpszWhere);
};
class CMyAboutBoxDlg : public CDialog
{
// Construction
public:
CMyHtmlCtrl m_page;
...
};
/////////////////
// Handle "app:ok" link by closing dialog
//
void CMyHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere)
{
if (_tcsicmp(lpszWhere,_T("ok"))==0) {
GetParent()->SendMessage(WM_COMMAND,IDOK);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyAboutBoxDlg message handlers
void CMyAboutBoxDlg::OnButton1() //naviagte2
{
m_page.Navigate2(_T("http://localhost/"));
}
void CMyAboutBoxDlg::OnButton2() //home
{
m_page.GoHome();
}
void CMyAboutBoxDlg::OnButton3() //resource
{
m_page.LoadFromResource(_T("about.htm"));
}
BOOL CMyAboutBoxDlg::OnInitDialog()
{
CDialog::OnInitDialog();
VERIFY(m_page.CreateFromStatic(IDC_HTMLVIEW, this));
m_page.LoadFromResource(_T("about.htm"));
...
}