Click here to Skip to main content
12,999,417 members (50,018 online)
Click here to Skip to main content


83 bookmarked
Posted 17 Mar 2000

ATL/AUX Library

, 17 Mar 2000
A set of VC++ helpers and patterns to help automate some routine coding tasks.
// IE4 Object Automation Controller Example, in ATL
// Copyright (c) by Andrew Nosenko (, 1998

#define STRICT
#define _WIN32_WINNT 0x0400

// 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
// ATL
  COM_MAP_NO_ENTRIES() // just IUnknown...

// CLogWindow
  void OnDestoryLogWindow() {

// 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) {
  STDMETHOD_(void, OnQuit)() { 
  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() { 
    CoUninitialize(); }

int WINAPI _tWinMain(HINSTANCE hinst, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow) {
  CComInit comInit;

  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;
  _S( browser->Navigate2(
    &vtOpt, &vtOpt, &vtOpt, &vtOpt) );

  MSG msg;
  while ( GetMessage(&msg, 0, 0, 0) ) {

  // 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 article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Andrew Nosenko
Australia Australia
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 18 Mar 2000
Article Copyright 2000 by Andrew Nosenko
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid