Code:
// ex08bView.cpp : implementation of the CEx08bView class
//
#include "stdafx.h"
#include "ex08b.h"
#include "ex08bDoc.h"
#include "ex08bView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx08bView
const char CEx08bView::s_engineGoogle[] =
"http://Google.com/";
IMPLEMENT_DYNCREATE(CEx08bView, CView)
BEGIN_MESSAGE_MAP(CEx08bView, CView)
//{{AFX_MSG_MAP(CEx08bView)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEx08bView construction/destruction
CEx08bView::CEx08bView()
{
// TODO: add construction code here
}
CEx08bView::~CEx08bView()
{
}
BOOL CEx08bView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEx08bView drawing
void CEx08bView::OnDraw(CDC* pDC)
{
CEx08bDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CEx08bView diagnostics
#ifdef _DEBUG
void CEx08bView::AssertValid() const
{
CView::AssertValid();
}
void CEx08bView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CEx08bDoc* CEx08bView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx08bDoc)));
return (CEx08bDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx08bView message handlers
int CEx08bView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
DWORD dwStyle = WS_VISIBLE | WS_CHILD;
if (m_search.Create(NULL, dwStyle, CRect(0, 0, 100, 100),
this, ID_BROWSER_SEARCH) == 0) {
AfxMessageBox("Unable to create search control!\n");
return -1;
}
m_search.Navigate(s_engineGoogle, NULL, NULL, NULL, NULL);
if (m_target.Create(NULL, dwStyle, CRect(0, 0, 100, 100),
this, ID_BROWSER_TARGET) == 0) {
AfxMessageBox("Unable to create target control!\n");
return -1;
}
m_target.GoHome(); // as defined in IE3 options
return 0;
}
void CEx08bView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
CRect rectClient;
GetClientRect(rectClient);
CRect rectBrowse(rectClient);
rectBrowse.right = rectClient.right / 2;
CRect rectSearch(rectClient);
rectSearch.left = rectClient.right / 2;
m_target.SetWidth(rectBrowse.right - rectBrowse.left);
m_target.SetHeight(rectBrowse.bottom - rectBrowse.top);
m_target.UpdateWindow();
m_search.SetLeft(rectSearch.left);
m_search.SetWidth(rectSearch.right - rectSearch.left);
m_search.SetHeight(rectSearch.bottom - rectSearch.top);
m_search.UpdateWindow();
}
BEGIN_EVENTSINK_MAP(CEx08bView, CView)
ON_EVENT(CEx08bView, ID_BROWSER_SEARCH, 100, OnBeforeNavigateExplorer1, VTS_BSTR VTS_I4 VTS_BSTR VTS_PVARIANT VTS_BSTR VTS_PBOOL)
ON_EVENT(CEx08bView, ID_BROWSER_TARGET, 113, OnTitleChangeExplorer2, VTS_BSTR)
END_EVENTSINK_MAP()
void CEx08bView::OnBeforeNavigateExplorer1(LPCTSTR URL,
long Flags, LPCTSTR TargetFrameName,
VARIANT FAR* PostData, LPCTSTR Headers, BOOL FAR* Cancel)
{
TRACE("CEx08bView::OnBeforeNavigateExplorer1 -- URL = %s\n", URL);
if (!strnicmp(URL, s_engineGoogle, strlen(s_engineGoogle))) {
return;
}
m_target.Navigate(URL, NULL, NULL, PostData, NULL);
*Cancel = TRUE;
}
void CEx08bView::OnTitleChangeExplorer2(LPCTSTR Text)
{
// Careful! Event could fire before we're ready.
CWnd* pWnd = AfxGetApp()->m_pMainWnd;
if (pWnd != NULL) {
if (::IsWindow(pWnd->m_hWnd)) {
pWnd->SetWindowText(Text);
}
}
}
Code:
// ex08bView.h : interface of the CEx08bView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_EX08BVIEW_H__13D86A41_5BC8_11D0_8FD1_00C04FC2A0C2__INCLUDED_)
#define AFX_EX08BVIEW_H__13D86A41_5BC8_11D0_8FD1_00C04FC2A0C2__INCLUDED_
#include "webbrowser.h" // Added by ClassView
class CEx08bView : public CView
{
private:
static const char s_engineGoogle[];
protected: // create from serialization only
CEx08bView();
DECLARE_DYNCREATE(CEx08bView)
// Attributes
public:
CEx08bDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEx08bView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CEx08bView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CEx08bView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
protected:
afx_msg void OnBeforeNavigateExplorer1(LPCTSTR URL,
long Flags, LPCTSTR TargetFrameName,
VARIANT FAR* PostData, LPCTSTR Headers, BOOL FAR* Cancel);
afx_msg void OnTitleChangeExplorer2(LPCTSTR Text);
DECLARE_EVENTSINK_MAP()
private:
CWebBrowser m_target;
CWebBrowser m_search;
};
#ifndef _DEBUG // debug version in ex08bView.cpp
inline CEx08bDoc* CEx08bView::GetDocument()
{ return (CEx08bDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EX08BVIEW_H__13D86A41_5BC8_11D0_8FD1_00C04FC2A0C2__INCLUDED_)
i didnt know what files to show here, so i put the view.cpp and the view.h code.this opens a window with a slitter bar in the middle,search engine on the right, when you search, it shows it on the left, but you can change the default opening page to whatever you want it to be.im using msvc++ 6, and i have to include webbrowser.h to get this to work