|
////////////////////////////////////////////////////////////////////////////////
// IE4 Object Automation Controller Example, in ATL
// Copyright (c) by Andrew Nosenko (andien@geocities.com), 1998
// http://www.geocities.com/~andien/atlaux.htm
#define STRICT
#define _WIN32_WINNT 0x0400
#define _ATL_APARTMENT_THREADED
// Standard headers
#include <windows.h>
#include <WindowsX.h>
#undef SubclassWindow
#include <Richedit.h>
#include <InetSDK.h>
#include <ExDispid.h>
#include <ExDisp.h>
#include <ax_id.h> // redefine all above IID_* via __uuidof()
#include <AtlAux.h>
#include <ax_sp.h> // smart pointers
// ATL
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <atlwin.h>
#include <AtlAux.h> // second pass: ATL goodies
#include <atlimpl.cpp>
#include <atlwin.cpp>
#pragma hdrstop
////////////////////////////////////////////////////////////////////////////////
// application
CComModule _Module;
#include "AuxLog.h" // Log Window
#include "WBSink.h" // IE4 sink base class
class CSink:
public CComObjectRoot,
public CLogWindow,
public IUnknown,
public DWebBrowserEvents2Sink
{
public:
// ATL
COM_MAP_NO_ENTRIES() // just IUnknown...
// CLogWindow
void OnDestoryLogWindow() {
PostQuitMessage(0);
}
// IE events to handle...
STDMETHOD_(void, StatusTextChange)(BSTR Text) {
Log(_T("StatusTextChange: %ls\n"), Text);
}
STDMETHOD_(void, ProgressChange)(long Progress, long ProgressMax) {
Log(_T("ProgressChange: %d of %d\n"), Progress, ProgressMax);
}
STDMETHOD_(void, TitleChange)(BSTR Text) {
Log(_T("TitleChange: %ls\n"), Text);
}
STDMETHOD_(void, PropertyChange)(BSTR szProperty) {
Log(_T("PropertyChange: %ls\n"), szProperty);
}
STDMETHOD_(void, OnVisible)(VARIANT_BOOL Visible) {
Log(_T("OnVisible\n"));
}
STDMETHOD_(void, OnQuit)() {
Log(_T("OnQuit\n"));
//PostQuitMessage(0);
}
STDMETHOD_(void, NavigateComplete2)(IDispatch* pDisp, VARIANT * URL ) {
Log(_T("NavigateComplete2: %ls\n"), V_BSTR(URL));
}
STDMETHOD_(void, DocumentComplete)(IDispatch* pDisp, VARIANT * URL ) {
Log(_T("DocumentComplete: %ls\n"), V_BSTR(URL));
}
};
struct CComInit {
CComInit() {
VERIFY_HR( CoInitialize(NULL) );
_Module.Init(NULL, GetModuleHandle(NULL)); }
~CComInit() {
_Module.Term();
CoUninitialize(); }
};
int WINAPI _tWinMain(HINSTANCE hinst, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow) {
CComInit comInit;
USES_CONVERSION;
CAuxObjectStack<CSink> sink; // live on the stack
_S( sink.CreateLogWindow(_T("Log Window - by Andrew Nosenko")
/*, CLogWindow::topmost | CLogWindow::noclose*/) );
sink.Log(_T("Creating and navigating IE4 instance...\n\n"));
IWebBrowser2Ptr browser;
_S( browser.CreateInstance(CLSID_InternetExplorer) );
_S( sink.Advise(browser) );
_S( browser->put_MenuBar(V_TRUE) );
_S( browser->put_StatusBar(V_TRUE) );
_S( browser->put_ToolBar(V_TRUE) );
_S( browser->put_AddressBar(V_TRUE) );
_S( browser->put_Visible(V_TRUE) );
VARIANT vtOpt;
vtOpt.vt = VT_ERROR;
vtOpt.scode = DISP_E_PARAMNOTFOUND;
_S( browser->Navigate2(
&CComVariant(L"http://www.microsoft.com/"),
&vtOpt, &vtOpt, &vtOpt, &vtOpt) );
MSG msg;
while ( GetMessage(&msg, 0, 0, 0) ) {
DispatchMessage(&msg);
}
// at this point browser might be gone down, hence the safe RPC errors...
_HR( sink.Unadvise(browser) );
return S_OK;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.