我的方法: BOOL CAboutDlg::OnInitDialog() { VERIFY(CDialog::OnInitDialog()); VERIFY(m_page.CreateFromStatic(IDC_HTMLVIEW, this)); m_page.LoadFromResource("ABOUT.HTM"); return TRUE; } //其中 CMyHtmlCtrl m_page;CHtmlCtrl继承自CHtmlView#include "StdAfx.h" #include "HtmlCtrl.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endifIMPLEMENT_DYNAMIC(CHtmlCtrl, CHtmlView) BEGIN_MESSAGE_MAP(CHtmlCtrl, CHtmlView) ON_WM_DESTROY() ON_WM_MOUSEACTIVATE() END_MESSAGE_MAP()////////////////// // Create control in same position as an existing static control with // the same ID (could be any kind of control, really) // BOOL CHtmlCtrl::CreateFromStatic(UINT nID, CWnd* pParent) { CStatic wndStatic; if (!wndStatic.SubclassDlgItem(nID, pParent)) return FALSE; // Get static control rect, convert to parent's client coords. CRect rc; wndStatic.GetWindowRect(&rc); pParent->ScreenToClient(&rc); wndStatic.DestroyWindow(); // create HTML control (CHtmlView) return Create(NULL, // class name NULL, // title (WS_CHILD | WS_VISIBLE ), // style rc, // rectangle pParent, // parent nID, // control ID NULL); // frame/doc context not used }//////////////// // Override to avoid CView stuff that assumes a frame. // void CHtmlCtrl::OnDestroy() { // This is probably unecessary since ~CHtmlView does it, but // safer to mimic CHtmlView::OnDestroy. if (m_pBrowserApp) { m_pBrowserApp->Release(); m_pBrowserApp = NULL; } CWnd::OnDestroy(); // bypass CView doc/frame stuff }//////////////// // Override to avoid CView stuff that assumes a frame. // int CHtmlCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg) { // bypass CView doc/frame stuff return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, msg); }////////////////// // Override navigation handler to pass to "app:" links to virtual handler. // Cancels the navigation in the browser, since app: is a pseudo-protocol. // void CHtmlCtrl::OnBeforeNavigate2( LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel ) { const char APP_PROTOCOL[] = "app:"; int len = _tcslen(APP_PROTOCOL); if (_tcsnicmp(lpszURL, APP_PROTOCOL, len)==0) { OnAppCmd(lpszURL + len); *pbCancel = TRUE; } }////////////////// // Called when the browser attempts to navigate to "app:foo" // with "foo" as lpszWhere. Override to handle app commands. // void CHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere) { // default: do nothing }//MyHtmlCtrl继承自CHtmlCtrl #include "HtmlCtrl.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif#define WM_ICON_NOTIFY WM_USER+100 //任务拦图标消息 ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CMyHtmlCtrl : public CHtmlCtrl { virtual void OnAppCmd(LPCTSTR lpszWhere); };///////////////// // Handle "app:ok" link by closing dialog // void CMyHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere) { if (_tcsicmp(lpszWhere,_T("ok"))==0) { GetParent()->SendMessage(WM_COMMAND,IDOK); } }
包含文件urlmon.h,定义函数
/////
#include "urlmon.h"
typedef HRESULT STDAPICALLTYPE SHOWHTMLDIALOGFN
(HWND hwndParent, IMoniker
*pmk, VARIANT *pvarArgIn, TCHAR* pchOptions,
VARIANT *pvArgOut);
////////函数显示对话框,成功返回TRUE,失败返回FALSE
BOOL ShowHtml()
{
HINSTANCE hinstMSHTML = LoadLibrary
(TEXT("MSHTML.DLL")); //装载动态连
接库
WCHAR url[]=L"HTTP://www.ccw.com.cn";
//此地址名称可直接用html文件名代替 if(hinstMSHTML)//装载动态连接库成功
{
SHOWHTMLDIALOGFN *pfnShowHTMLDialog; pfnShowHTMLDialog = (SHOWHTMLDIALOGFN*)
GetProcAddress(hinstMSHTML,
TEXT ("ShowHTMLDialog")); if(pfnShowHTMLDialog)
{
IMoniker *moniker=NULL; //
if( FAILED(CreateURLMoniker(NULL,
(LPWSTR)url,&moniker ) ))
{
FreeLibrary(hinstMSHTML);
return FALSE;
} //调用ShowHTMLDialog函数显示URL上的HTML文件
pfnShowHTMLDialog(m_hWnd,moniker,NULL,NULL,NULL); if(moniker!=NULL)
moniker->Release(); //显示成功,返回TRUE
return TRUE; }
else //GetProcessAddress失败
return FALSE; FreeLibrary(hinstMSHTML);
}
else //装载动态连接库失败
return FALSE;
}这种方法和我做的不一样,我是用htmlview的,但我不知道怎么说清楚
BOOL CAboutDlg::OnInitDialog()
{
VERIFY(CDialog::OnInitDialog());
VERIFY(m_page.CreateFromStatic(IDC_HTMLVIEW, this));
m_page.LoadFromResource("ABOUT.HTM");
return TRUE;
}
//其中 CMyHtmlCtrl m_page;CHtmlCtrl继承自CHtmlView#include "StdAfx.h"
#include "HtmlCtrl.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifIMPLEMENT_DYNAMIC(CHtmlCtrl, CHtmlView)
BEGIN_MESSAGE_MAP(CHtmlCtrl, CHtmlView)
ON_WM_DESTROY()
ON_WM_MOUSEACTIVATE()
END_MESSAGE_MAP()//////////////////
// Create control in same position as an existing static control with
// the same ID (could be any kind of control, really)
//
BOOL CHtmlCtrl::CreateFromStatic(UINT nID, CWnd* pParent)
{
CStatic wndStatic;
if (!wndStatic.SubclassDlgItem(nID, pParent))
return FALSE; // Get static control rect, convert to parent's client coords.
CRect rc;
wndStatic.GetWindowRect(&rc);
pParent->ScreenToClient(&rc);
wndStatic.DestroyWindow(); // create HTML control (CHtmlView)
return Create(NULL, // class name
NULL, // title
(WS_CHILD | WS_VISIBLE ), // style
rc, // rectangle
pParent, // parent
nID, // control ID
NULL); // frame/doc context not used
}////////////////
// Override to avoid CView stuff that assumes a frame.
//
void CHtmlCtrl::OnDestroy()
{
// This is probably unecessary since ~CHtmlView does it, but
// safer to mimic CHtmlView::OnDestroy.
if (m_pBrowserApp) {
m_pBrowserApp->Release();
m_pBrowserApp = NULL;
}
CWnd::OnDestroy(); // bypass CView doc/frame stuff
}////////////////
// Override to avoid CView stuff that assumes a frame.
//
int CHtmlCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg)
{
// bypass CView doc/frame stuff
return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, msg);
}//////////////////
// Override navigation handler to pass to "app:" links to virtual handler.
// Cancels the navigation in the browser, since app: is a pseudo-protocol.
//
void CHtmlCtrl::OnBeforeNavigate2( LPCTSTR lpszURL,
DWORD nFlags,
LPCTSTR lpszTargetFrameName,
CByteArray& baPostedData,
LPCTSTR lpszHeaders,
BOOL* pbCancel )
{
const char APP_PROTOCOL[] = "app:";
int len = _tcslen(APP_PROTOCOL);
if (_tcsnicmp(lpszURL, APP_PROTOCOL, len)==0) {
OnAppCmd(lpszURL + len);
*pbCancel = TRUE;
}
}//////////////////
// Called when the browser attempts to navigate to "app:foo"
// with "foo" as lpszWhere. Override to handle app commands.
//
void CHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere)
{
// default: do nothing
}//MyHtmlCtrl继承自CHtmlCtrl
#include "HtmlCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif#define WM_ICON_NOTIFY WM_USER+100 //任务拦图标消息
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CMyHtmlCtrl : public CHtmlCtrl {
virtual void OnAppCmd(LPCTSTR lpszWhere);
};/////////////////
// Handle "app:ok" link by closing dialog
//
void CMyHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere)
{
if (_tcsicmp(lpszWhere,_T("ok"))==0) {
GetParent()->SendMessage(WM_COMMAND,IDOK);
}
}