접기
#include "WebBrowser2.h"
class CTryView : public CView
{
// {
CWebBrowser2 m_search;
// }
protected: // create from serialization only
CTryView();
...
// Generated message map functions
protected:
//{{AFX_MSG(CTryView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// {
afx_msg void OnDocumentComplete(LPDISPATCH lpDisp,
VARIANT FAR* URL);
DECLARE_EVENTSINK_MAP()
// }
};
IMPLEMENT_DYNCREATE(CTryView, CView)
BEGIN_MESSAGE_MAP(CTryView, CView)
//{{AFX_MSG_MAP(CTryView)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
int CTryView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
// {
DWORD dwStyle = WS_VISIBLE | WS_CHILD;
if (m_search.Create (NULL, dwStyle, CRect(0, 0, 0, 0),
this, ID_BROWSER_SEARCH) == 0) {
AfxMessageBox("Unable to create search control!\n");
return -1;
}
m_search.Navigate("http://www.google.com/", NULL, NULL, NULL, NULL);
// }
return 0;
}
void CTryView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
m_search.MoveWindow(0,0,cx,cy);
}
BEGIN_EVENTSINK_MAP(CTry_081209_02View, CView)
ON_EVENT(CTry_081209_02View, ID_WEB_BROWSE, 259 /* DocumentComplete */,
OnDocumentComplete, VTS_DISPATCH VTS_PVARIANT)
END_EVENTSINK_MAP()
void CTry_081209_02View::OnDocumentComplete(LPDISPATCH lpDisp,
VARIANT FAR* URL)
{
IUnknown* pUnk;
LPDISPATCH lpWBDisp;
HRESULT hr;
pUnk = m_webBrowser.GetControlUnknown();
ASSERT(pUnk);
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&lpWBDisp);
ASSERT(SUCCEEDED(hr));
if (lpDisp == lpWBDisp )
{
// Top-level Window object, so document has been loaded
TRACE("Web document is finished downloading\n");
}
lpWBDisp->Release();
}
접기 접기
IDD_TRY_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Try_081209"
FONT 9, "굴림"
BEGIN
DEFPUSHBUTTON "확인",IDOK,260,7,50,14
PUSHBUTTON "취소",IDCANCEL,260,23,50,14
CONTROL "",IDC_EXPLORER1,"{8856F961-340A-11D0-A96B-00C04FD705A2}",
WS_TABSTOP,7,7,226,186
END
class CTryDlg : public CDialog
{
// Construction
public:
CTryDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CTryDlg)
enum { IDD = IDD_TRY_DIALOG };
CWebBrowser2 m_webBrowser;
//}}AFX_DATA
...
// Generated message map functions
//{{AFX_MSG(CTryDlg)
...
afx_msg void OnDocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT FAR* URL);
DECLARE_EVENTSINK_MAP()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
void CTryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTryDlg)
DDX_Control(pDX, IDC_EXPLORER1, m_webBrowser);
//}}AFX_DATA_MAP
}
...
BOOL CTryDlg::OnInitDialog()
{
...
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// {
COleVariant szURL = "http://www.google.com/";
m_webBrowser.Navigate2 (szURL, NULL, NULL, NULL, NULL);
// }
return TRUE; // return TRUE unless you set the focus to a control
}
접기