用VC++写浏览器

(1)用于初始化工作的函数体: CLSID const& GetClsid() { static CLSID const clsid= { 0xeab22ac3, 0x30c1, 0x11cf, { 0xa7, 0xeb, 0x0, 0x0, 0xc0, 0x5b, 0xae, 0xb } }; return clsid; } virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL) { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); } BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL) { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,pPersist, bStorage, bstrLicKey); } (2) 功能函数 //用于返回前一页 void CWebBrowser::GoBack() { InvokeHelper(0x64, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } //指向下一页 void CWebBrowser::GoForward() { InvokeHelper(0x65, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } //用于返回到主页 void CWebBrowser::GoHome() { InvokeHelper(0x66, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } //用于搜索网页 void CWebBrowser::GoSearch() { InvokeHelper(0x67, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } //用于导航 void CWebBrowser::Navigate(LPCTSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers) { static BYTE parms[] = VTS_BSTR VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT; InvokeHelper(0x68, DISPATCH_METHOD, VT_EMPTY, NULL, parms, URL, Flags, TargetFrameName, PostData, Headers); } //用于刷新页面 void CWebBrowser::Refresh() { InvokeHelper(DISPID_REFRESH, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } void CWebBrowser::Refresh2(VARIANT* Level) { static BYTE parms[] = VTS_PVARIANT; InvokeHelper(0x69, DISPATCH_METHOD, VT_EMPTY, NULL, parms, Level); } //用于停止传送文档 void CWebBrowser::Stop() { InvokeHelper(0x6a, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } //用于获得应用程序 LPDISPATCH CWebBrowser::GetApplication() { LPDISPATCH result; InvokeHelper(0xc8, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL); return result; } //用于获取上层窗口 LPDISPATCH CWebBrowser::GetParent() { LPDISPATCH result; InvokeHelper(0xc9, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL); return result; } //用于获得容器指针 LPDISPATCH CWebBrowser::GetContainer() { LPDISPATCH result; InvokeHelper(0xca, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL); return result; } //用于获得文档 LPDISPATCH CWebBrowser::GetDocument() { LPDISPATCH result; InvokeHelper(0xcb, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL); return result; } //用于获得顶层容器指针 BOOL CWebBrowser::GetTopLevelContainer() { BOOL result; InvokeHelper(0xcc, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL); return result; } //用于获得风格 CString CWebBrowser::GetType() { CString result; InvokeHelper(0xcd, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL); return result; } //用于获得和设置窗口边界 long CWebBrowser::GetLeft() { long result; InvokeHelper(0xce, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL); return result; } void CWebBrowser::SetLeft(long nNewValue) { static BYTE parms[] = VTS_I4; InvokeHelper(0xce, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, nNewValue); } long CWebBrowser::GetTop() { long result; InvokeHelper(0xcf, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL); return result; } void CWebBrowser::SetTop(long nNewValue) { static BYTE parms[] = VTS_I4; InvokeHelper(0xcf, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, nNewValue); } long CWebBrowser::GetWidth() { long result; InvokeHelper(0xd0, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL); return result; } void CWebBrowser::SetWidth(long nNewValue) { static BYTE parms[] = VTS_I4; InvokeHelper(0xd0, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, nNewValue); } long CWebBrowser::GetHeight() { long result; InvokeHelper(0xd1, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL); return result; } void CWebBrowser::SetHeight(long nNewValue) { static BYTE parms[] = VTS_I4; InvokeHelper(0xd1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, nNewValue); } CString CWebBrowser::GetLocationName() { CString result; InvokeHelper(0xd2, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL); return result; } //用于获得本地资源定位地址 CString CWebBrowser::GetLocationURL() { CString result; InvokeHelper(0xd3, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL); return result; } //用于监测程序 BOOL CWebBrowser::GetBusy() { BOOL result; InvokeHelper(0xd4, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL); return result; } (3)返回前一页、跳向下一页、重载该页、填URL地址的消息响应函数 void CMyBrowserView::OnReload() { // TODO: Add your command handler code here m_Browser.Refresh(); } void CMyBrowserView::OnForward() { // TODO: Add your command handler code here m_Browser.GoForward(); } void CMyBrowserView::OnBack() { // TODO: Add your command handler code here m_Browser.GoBack(); } void CMyBrowserView::OnStop() { // TODO: Add your command handler code here m_Browser.Stop(); } void CMyBrowserView::OnUrl() { // TODO: Add your command handler code here COleVariant varEmpty; // Default is VT_EMPTY UrlDlg *Dlg = new UrlDlg( this ); if( Dlg->DoModal() == IDOK ) m_Browser.Navigate( Dlg->m_Edit, &varEmpty, &varEmpty, &varEmpty, &varEmpty ); delete Dlg; }

你可能感兴趣的:(用VC++写浏览器)