[!if=(FreeThreadedMarshaler, "TRUE")]
	[!set(NeedsGetControllingUnknown, "TRUE")]
[!endif]
// [!HeaderName] : Declaration of the [!ClassName]
[!crlf]

#ifndef __[!UpperShortName]_H_
#define __[!UpperShortName]_H_
[!crlf]

#include "resource.h"       // main symbols

[!crlf]
[!crlf]
/////////////////////////////////////////////////////////////////////////////
// [!ClassName]

class ATL_NO_VTABLE [!ClassName] :
[!if=(ThreadingModel, "Single")]
	public CComObjectRootEx<CComSingleThreadModel>,
[!endif]
[!if=(ThreadingModel, "Apartment")]
	public CComObjectRootEx<CComSingleThreadModel>,
[!endif]
[!if=(ThreadingModel, "Both")]
	public CComObjectRootEx<CComMultiThreadModel>,
[!endif]
[!if=(ThreadingModel, "Free")]
	public CComObjectRootEx<CComMultiThreadModel>,
[!endif]
	public CComCoClass<[!ClassName],&CLSID_[!CoClassName]>,
	public CComControl<[!ClassName]>,
[!if=(StockPropEnabled, "TRUE")]
	public CStockPropImpl<[!ClassName], [!InterfaceName], &IID_[!InterfaceName], &LIBID_[!LibName]>,
[!else]
	[!if=(Dual, "TRUE")]public IDispatchImpl<[!InterfaceName], &IID_[!InterfaceName], &LIBID_[!LibName]>,[!else]public [!InterfaceName],[!endif]
[!endif]
	public IPersistStreamInitImpl<[!ClassName]>,
	public IOleControlImpl<[!ClassName]>,
	public IOleObjectImpl<[!ClassName]>,
	public IOleInPlaceActiveObjectImpl<[!ClassName]>,
	public IViewObjectExImpl<[!ClassName]>,
[!if=(ErrorInfoEnabled, "TRUE")]
	public ISupportErrorInfo,
[!endif]
[!if=(ConnectionPointsEnabled, "TRUE")]
	public IConnectionPointContainerImpl<[!ClassName]>,
[!endif]
	public IOleInPlaceObjectWindowlessImpl<[!ClassName]>
{
public:
[!if!=(SubclassWindow, "")]
	CContainedWindow m_ctl[!SubclassWindow];
	[!crlf]
[!endif]

	[!ClassName]()[!if!=(SubclassWindow, "")] :	
		m_ctl[!SubclassWindow](_T("[!SubclassWindow]"), this, 1)[!endif]
	{
[!if=(FreeThreadedMarshaler, "TRUE")]		m_pUnkMarshaler = NULL; [!endif] [!if!=(SubclassWindow, "")]	[!set(WindowedOnlyEnabled,"TRUE")][!endif]
[!if=(WindowedOnlyEnabled, "TRUE")]		m_bWindowOnly = TRUE; [!endif]
	}
[!crlf]

[!if=(NeedsGetControllingUnknown, "TRUE")]
DECLARE_GET_CONTROLLING_UNKNOWN()
[!endif]
DECLARE_REGISTRY_RESOURCEID(IDR_[!UpperShortName])

[!if=(Aggregatable, "NO")]
DECLARE_NOT_AGGREGATABLE([!ClassName])
[!endif]
[!if=(Aggregatable, "ONLY")]
DECLARE_ONLY_AGGREGATABLE([!ClassName])
[!endif]

[!crlf]
BEGIN_COM_MAP([!ClassName]) 
[!if=(Dual, "TRUE")]
	COM_INTERFACE_ENTRY(IDispatch)
[!endif]
	COM_INTERFACE_ENTRY([!InterfaceName])
	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)
[!if=(ErrorInfoEnabled, "TRUE")]
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
[!endif]
[!if=(ConnectionPointsEnabled, "TRUE")]
	COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
[!endif]
[!if=(FreeThreadedMarshaler, "TRUE")]
	COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
[!endif]
END_COM_MAP()

[!crlf]
BEGIN_PROPERTY_MAP([!ClassName])
	// Example entries
	// PROP_ENTRY("Property Description", dispid, clsid)
	// PROP_PAGE(CLSID_StockColorPage)
END_PROPERTY_MAP()
[!crlf]

[!if=(ConnectionPointsEnabled, "TRUE")]
[!crlf]
BEGIN_CONNECTION_POINT_MAP([!ClassName])
END_CONNECTION_POINT_MAP()
[!crlf]
[!endif]

[!crlf]
BEGIN_MSG_MAP([!ClassName])
	MESSAGE_HANDLER(WM_PAINT, OnPaint)
	MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
	MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
[!if!=(SubclassWindow, "")]
	MESSAGE_HANDLER(WM_CREATE, OnCreate)
ALT_MSG_MAP(1)
	// Replace this with message map entries for subclassed [!SubclassWindow]
[!endif]
END_MSG_MAP()

[!crlf]
[!if!=(SubclassWindow, "")]
	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_ctl[!SubclassWindow].Create(m_hWnd, rc);
		return 0;
	}
	STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
	{
		IOleInPlaceObjectWindowlessImpl<[!ClassName]>::SetObjectRects(prcPos, prcClip);
		int cx, cy;
		cx = prcPos->right - prcPos->left;
		cy = prcPos->bottom - prcPos->top;
		::SetWindowPos(m_ctl[!SubclassWindow].m_hWnd, NULL, 0,
			0, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
		return S_OK;
	}
[!endif]

[!if=(FreeThreadedMarshaler, "TRUE")]
[!crlf]
	HRESULT FinalConstruct()
	{
		return CoCreateFreeThreadedMarshaler(
			GetControllingUnknown(), &m_pUnkMarshaler.p);
	}

[!crlf]
	void FinalRelease()
	{
		m_pUnkMarshaler.Release();
	}

[!crlf]
	CComPtr<IUnknown> m_pUnkMarshaler;
[!endif]

[!if=(ErrorInfoEnabled, "TRUE")]
[!crlf]
// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
[!endif]
[!crlf]
// IViewObjectEx
	STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
	{
		ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
[!if=(Opaque, "TRUE")]
[!if=(SolidBackground, "TRUE")]
		*pdwStatus = VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE;
[!else]
		*pdwStatus = VIEWSTATUS_OPAQUE;
[!endif]
[!else]
		*pdwStatus = 0;
[!endif]
		return S_OK;
	}
[!crlf]
// [!InterfaceName]
public:
[!if=(NormalizeDCEnabled, "TRUE")]
	HRESULT OnDraw(ATL_DRAWINFO& di);
[!else]
	HRESULT OnDrawAdvanced(ATL_DRAWINFO& di);
[!endif]
[!crlf]
[!if=(SP_FONT, "TRUE")]	CComPtr<IFontDisp> m_pFont;[!endif]
[!if=(SP_MOUSEICON, "TRUE")]	CComPtr<IPictureDisp> m_pMouseIcon;[!endif]
[!if=(SP_PICTURE, "TRUE")]	CComPtr<IPictureDisp> m_pPicture;[!endif]
[!if=(SP_BACKCOLOR, "TRUE")]	OLE_COLOR m_clrBackColor;[!endif]
[!if=(SP_BORDERCOLOR, "TRUE")]	OLE_COLOR m_clrBorderColor;[!endif]
[!if=(SP_FILLCOLOR, "TRUE")]	OLE_COLOR m_clrFillColor;[!endif]
[!if=(SP_FORECOLOR, "TRUE")]	OLE_COLOR m_clrForeColor;[!endif]
[!if=(SP_TEXT, "TRUE")]	CComBSTR m_bstrText;[!endif]
[!if=(SP_CAPTION, "TRUE")]	CComBSTR m_bstrCaption;[!endif]
[!if=(SP_VALID, "TRUE")]	BOOL m_bValid;[!endif]
[!if=(SP_TABSTOP, "TRUE")]	BOOL m_bTabStop;[!endif]
[!if=(SP_BORDERVISIBLE, "TRUE")]	BOOL m_bBorderVisible;[!endif]
[!if=(SP_BACKSTYLE, "TRUE")]	long m_nBackStyle;[!endif]
[!if=(SP_BORDERSTYLE, "TRUE")]	long m_nBorderStyle;[!endif]
[!if=(SP_BORDERWIDTH, "TRUE")]	long m_nBorderWidth;[!endif]
[!if=(SP_DRAWMODE, "TRUE")]	long m_nDrawMode;[!endif]
[!if=(SP_DRAWSTYLE, "TRUE")]	long m_nDrawStyle;[!endif]
[!if=(SP_DRAWWIDTH, "TRUE")]	long m_nDrawWidth;[!endif]
[!if=(SP_FILLSTYLE, "TRUE")]	long m_nFillStyle;[!endif]
[!if=(SP_APPEARANCE, "TRUE")]	long m_nAppearance;[!endif]
[!if=(SP_MOUSEPOINTER, "TRUE")]	long m_nMousePointer;[!endif]
[!if=(SP_READYSTATE, "TRUE")]	long m_nReadyState;[!endif]
};

[!crlf]
#endif //__[!UpperShortName]_H_
