客户端程显示一个网页,可以使用的是CHTMLView这个类.关于这个类的使用可以参考ChtmlView控件显示HTML.这里仅作简单说明
- BOOL CHTMLCtrl::CreateFromStatic(CStatic* pStaticWnd, CWnd* pParent)
- {
- ASSERT(NULL!=pStaticWnd && NULL!=pStaticWnd->GetSafeHwnd());
- ASSERT(NULL!=pParent && NULL!=pParent->GetSafeHwnd());
- CRect rc;
- pStaticWnd->GetClientRect(&rc);
- int nID = pStaticWnd->GetDlgCtrlID();
- LPCTSTR lpClassName = AfxRegisterWndClass(NULL);
- return Create(lpClassName, _T(""), WS_CHILD|WS_VISIBLE, rc, pParent, nID, NULL);
- }
- int CHTMLCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
- {
- // TODO: Add your message handler code here and/or call default
- return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
- //Do not call it.
- // return CHtmlView::OnMouseActivate(pDesktopWnd, nHitTest, message);
- }
- BOOL CHomePage::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CRect rc;
- GetClientRect(&rc);
- CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_HTML);
- pStatic->MoveWindow(&rc);
- m_pHTMLPage = new CHTMLCtrl;
- CHTMLCtrl* pHTMLCtrl = (CHTMLCtrl*)m_pHTMLPage;
- pHTMLCtrl->CreateFromStatic(pStatic, this);
- pHTMLCtrl->Navigate(_T("http://www.osssk1.com"));
- return TRUE;
- }
- void CHTMLCtrl::OnNavigateError(LPCTSTR lpszURL, LPCTSTR lpszFrame,
- DWORD dwError,BOOL *pbCancel)
- {
- if (200!=dwError && 0==_tcscmp(_T("http://www.osssk1.com/"), lpszURL))
- {
- // Navigate to local html file.
- GetParent()->PostMessage(WM_NAVI_LOCAL_URL, 0, 0);
- return;
- }
- return CHtmlView::OnNavigateError(lpszURL, lpszFrame, dwError, pbCancel);
- }
- BOOL CHomePage::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
- {
- // TODO: Add your specialized code here and/or call the base class
- if (WM_NAVI_LOCAL_URL == message)
- {
- CHTMLCtrl* pHTMLCtrl = (CHTMLCtrl*)m_pHTMLPage;
- pHTMLCtrl->Navigate(_T("e:\\index.html"));
- return TRUE;
- }
- return CDialog::OnWndMsg(message, wParam, lParam, pResult);
- }