www.gusucode.com > VC++简易的IE浏览器源码-源码程序 > VC++简易的IE浏览器源码-源码程序\code\HVIEWERVIEW.cpp
// HViewerView.cpp : implementation of the CHViewerView class // Download by http://www.NewXing.com #include "stdafx.h" #include "HViewer.h" #include "HViewerDoc.h" #include "HViewerView.h" #include "MainFrm.h" //自行加入 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CHViewerView IMPLEMENT_DYNCREATE(CHViewerView, CHtmlView) BEGIN_MESSAGE_MAP(CHViewerView, CHtmlView) //{{AFX_MSG_MAP(CHViewerView) ON_COMMAND(ID_STOP, OnStop) ON_COMMAND(ID_RELOAD, OnReload) ON_COMMAND(ID_FORWARD, OnForward) ON_COMMAND(ID_HOME, OnHome) ON_COMMAND(ID_BACK, OnBack) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CHtmlView::OnFilePrint) ON_COMMAND(IDOK, OnOpenNewUrl) //回应IDC_URL_EDIT控件中使用者按下键盘上Enter键所发出的讯息 END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CHViewerView construction/destruction CHViewerView::CHViewerView() { // TODO: add construction code here } CHViewerView::~CHViewerView() { } BOOL CHViewerView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CHtmlView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CHViewerView drawing void CHViewerView::OnDraw(CDC* pDC) { CHViewerDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } void CHViewerView::OnInitialUpdate() { CHtmlView::OnInitialUpdate(); // TODO: This code navigates to a popular spot on the web. // change the code to go where you'd like. Navigate2(_T("http://www.microsoft.com/visualc/"),NULL,NULL); } ///////////////////////////////////////////////////////////////////////////// // CHViewerView printing ///////////////////////////////////////////////////////////////////////////// // CHViewerView diagnostics #ifdef _DEBUG void CHViewerView::AssertValid() const { CHtmlView::AssertValid(); } void CHViewerView::Dump(CDumpContext& dc) const { CHtmlView::Dump(dc); } CHViewerDoc* CHViewerView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHViewerDoc))); return (CHViewerDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CHViewerView message handlers //回应显示连结的Edit Box完成输入后使用者按下键盘上Enter按键的讯息 void CHViewerView::OnOpenNewUrl() { CString HttpAdd; CEdit * HttpAddCtrl = //取得指向显示连结位置之Edit Box的控件指针 ((CMainFrame *) AfxGetMainWnd())->GetHttpAddCtrl(); HttpAddCtrl->GetWindowText(HttpAdd); //设定目前欲开启的URL位置 Navigate2(HttpAdd); //开启URL位置 } //回应工具栏上ID_STOP按钮的讯息 void CHViewerView::OnStop() { // TODO: Add your command handler code here Stop(); //中断目前正在开启的位置 } //回应工具栏上ID_RELOAD按钮的讯息 void CHViewerView::OnReload() { // TODO: Add your command handler code here Refresh(); //重新载入目前开启的位置 } //回应工具栏上ID_FORWARD按钮的讯息 void CHViewerView::OnForward() { // TODO: Add your command handler code here GoForward(); //到下一个开启的URL位置 } //回应工具栏上ID_HOME按钮的讯息 void CHViewerView::OnHome() { // TODO: Add your command handler code here GoHome(); //到设定为Home的URL位置 } //回应工具栏上ID_BACK按钮的讯息 void CHViewerView::OnBack() { // TODO: Add your command handler code here GoBack(); //到上一个开启的URL位置 } //当网页下载完成后,将呼叫此函数 void CHViewerView::OnDocumentComplete(LPCTSTR lpszURL) { // TODO: Add your specialized code here and/or call the base class CEdit * HttpAddCtrl = //取得指向显示连结位置之Edit Box的控件指针 ((CMainFrame *) AfxGetMainWnd())->GetHttpAddCtrl(); HttpAddCtrl->SetWindowText(lpszURL); //设定显示连结位置之Edit Box的内容 CHtmlView::OnDocumentComplete(lpszURL); }