OBJVWCTL.H

// ObjVwCtl.h : Declaration of the CObjVw 

#ifndef __OBJVW_H_
#define __OBJVW_H_

#include "resource.h" // main symbols
#include <commctrl.h>

#import "mshtml.dll"
#import "shdocvw.dll" exclude("tagREADYSTATE")

/////////////////////////////////////////////////////////////////////////////
// CObjVw
class ATL_NO_VTABLE CObjVw :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CObjVw,&CLSID_ObjVw>,
public CComControl<CObjVw>,
public IDispatchImpl<IObjVw, &IID_IObjVw, &LIBID_OBJVWLib>,
public IDispatchImpl<DWebBrowserEvents2, &IID_DWebBrowserEvents2, &LIBID_OBJVWLib>,
public IPersistStreamInitImpl<CObjVw>,
public IOleControlImpl<CObjVw>,
public IOleObjectImpl<CObjVw>,
public IOleInPlaceActiveObjectImpl<CObjVw>,
public IViewObjectExImpl<CObjVw>,
public ISupportErrorInfo,
public IConnectionPointContainerImpl<CObjVw>,
public IOleInPlaceObjectWindowlessImpl<CObjVw>,
public IObjectSafetyImpl<CObjVw>
{
public:
CContainedWindow m_ctlSysTreeView32;
SHDocVw::IWebBrowserPtr m_spWebBrowser;
DWORD m_dwAdviseCookie;


CObjVw() :
m_ctlSysTreeView32(_T("SysTreeView32"), this, 1)
{
m_bWindowOnly = TRUE;
m_dwAdviseCookie = 0;
}

void EnumFrames();
void RecurseWindows(MSHTML::IHTMLDocument2Ptr spDocument, LPVOID pvTreeParent = NULL);
void GetPageContents(MSHTML::IHTMLDocument2Ptr spDocument, LPVOID pvTreeParent);
bool CObjVw::GetControlInfo(IUnknownPtr spUnk, LPSTR szClassInfo);

bool InsertTreeItem(LPTSTR pszItemText, LPVOID pvTreeParent, LPVOID* ppvTree);

DECLARE_REGISTRY_RESOURCEID(IDR_OBJVW)
DECLARE_GET_CONTROLLING_UNKNOWN()

BEGIN_COM_MAP(CObjVw)
COM_INTERFACE_ENTRY2(IDispatch, IObjVw)
COM_INTERFACE_ENTRY_IID(IID_IObjVw, IObjVw)
COM_INTERFACE_ENTRY_IID(IID_DWebBrowserEvents2, DWebBrowserEvents2)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
COM_INTERFACE_ENTRY_IMPL(IOleControl)
COM_INTERFACE_ENTRY_IMPL(IOleObject)
COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
COM_INTERFACE_ENTRY_IMPL(IObjectSafety)
END_COM_MAP()

BEGIN_PROPERTY_MAP(CObjVw)
// Example entries
// PROP_ENTRY("Property Description", dispid, clsid)
// PROP_PAGE(CLSID_StockColorPage)
END_PROPERTY_MAP()


BEGIN_CONNECTION_POINT_MAP(CObjVw)
END_CONNECTION_POINT_MAP()


BEGIN_MSG_MAP(CObjVw)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
ALT_MSG_MAP(1)
// Replace this with message map entries for subclassed SysTreeView32
END_MSG_MAP()

LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
RECT rc;
GetWindowRect(&rc);
rc.right -= rc.left;
rc.bottom -= rc.top;
rc.top = rc.left = 0;

m_ctlSysTreeView32.Create(m_hWnd, rc, _T(""),
WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_HASBUTTONS);

return 0;
}
STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
{
IOleInPlaceObjectWindowlessImpl<CObjVw>::SetObjectRects(prcPos, prcClip);
int cx, cy;
cx = prcPos->right - prcPos->left;
cy = prcPos->bottom - prcPos->top;
::SetWindowPos(m_ctlSysTreeView32.m_hWnd, NULL, 0,
0, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
return S_OK;
}

STDMETHOD(SetClientSite)(IOleClientSite* pClientSite);

// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// IViewObjectEx
STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
{
ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
*pdwStatus = VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE;
return S_OK;
}

// IObjVw
public:
HRESULT OnDraw(ATL_DRAWINFO& di);

// DWebBrowserEvents2
public:
STDMETHOD(Recalc)();
STDMETHOD(StatusTextChange)(BSTR Text);
STDMETHOD(ProgressChange)(long Progress, long ProgressMax);
STDMETHOD(CommandStateChange)(long Command, VARIANT_BOOL Enable);
STDMETHOD(DownloadBegin)();
STDMETHOD(DownloadComplete)();
STDMETHOD(TitleChange)(BSTR Text);
STDMETHOD(PropertyChange)(BSTR szProperty);
STDMETHOD(BeforeNavigate2)(IDispatch* pDisp, VARIANT* URL, VARIANT* Flags,
VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers,
VARIANT_BOOL* Cancel);
STDMETHOD(NewWindow2)(IDispatch** ppDisp, VARIANT_BOOL* Cancel);
STDMETHOD(NavigateComplete2)(IDispatch* pDisp, VARIANT* URL);
STDMETHOD(DocumentComplete)(IDispatch* pDisp, VARIANT* URL);
STDMETHOD(OnQuit)();
STDMETHOD(OnVisible)(VARIANT_BOOL Visible);
STDMETHOD(OnToolBar)(VARIANT_BOOL ToolBar);
STDMETHOD(OnMenuBar)(VARIANT_BOOL MenuBar);
STDMETHOD(OnStatusBar)(VARIANT_BOOL StatusBar);
STDMETHOD(OnFullScreen)(VARIANT_BOOL FullScreen);
STDMETHOD(OnTheaterMode)(VARIANT_BOOL TheaterMode);
};

#endif //__OBJVW_H_