// AtlTimerCtrl.h : Declaration of the CAtlTimerCtrl

#ifndef __ATLTIMERCTRL_H_
#define __ATLTIMERCTRL_H_

#include "resource.h"       // main symbols
#include "cpatltimer.h"

/////////////////////////////////////////////////////////////////////////////
// CAtlTimerCtrl
class ATL_NO_VTABLE CAtlTimerCtrl : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CAtlTimerCtrl, &CLSID_AtlTimerCtrl>,
	public CComControl<CAtlTimerCtrl>,
	public CStockPropImpl<CAtlTimerCtrl, IAtlTimerCtrl, &IID_IAtlTimerCtrl, &LIBID_ATLTIMERLib>,
	public IProvideClassInfo2Impl<&CLSID_AtlTimerCtrl, &DIID__IAtlTimerCtrlEvents, &LIBID_ATLTIMERLib>,
	public IPersistStreamInitImpl<CAtlTimerCtrl>,
	public IPersistStorageImpl<CAtlTimerCtrl>,
	public IQuickActivateImpl<CAtlTimerCtrl>,
	public IOleControlImpl<CAtlTimerCtrl>,
	public IOleObjectImpl<CAtlTimerCtrl>,
	public IOleInPlaceActiveObjectImpl<CAtlTimerCtrl>,
	public IViewObjectExImpl<CAtlTimerCtrl>,
	public IOleInPlaceObjectWindowlessImpl<CAtlTimerCtrl>,
	public IDataObjectImpl<CAtlTimerCtrl>,
	public IConnectionPointContainerImpl<CAtlTimerCtrl>,
	public CProxy_IAtlTimerCtrlEvents <CAtlTimerCtrl>,
	public ISpecifyPropertyPagesImpl<CAtlTimerCtrl>
{
public:

	BOOL m_bShowSeconds ;
	UINT m_TimerId ;
	DWORD m_Expiration ;

	CAtlTimerCtrl()
	{
		m_Expiration = 0 ;
		m_bShowSeconds = TRUE ;
		m_clrBackColor = RGB(255,255,255) ;
	}

DECLARE_REGISTRY_RESOURCEID(IDR_ATLTIMERCTRL)
DECLARE_NOT_AGGREGATABLE(CAtlTimerCtrl)

BEGIN_COM_MAP(CAtlTimerCtrl)
	COM_INTERFACE_ENTRY(IAtlTimerCtrl)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
	COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
	COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
	COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
	COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
	COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
	COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
	COM_INTERFACE_ENTRY_IMPL(IOleControl)
	COM_INTERFACE_ENTRY_IMPL(IOleObject)
	COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
	COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
	COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
	COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
	COM_INTERFACE_ENTRY_IMPL(IDataObject)
	COM_INTERFACE_ENTRY(IProvideClassInfo)
	COM_INTERFACE_ENTRY(IProvideClassInfo2)
	COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()

BEGIN_PROPERTY_MAP(CAtlTimerCtrl)
	PROP_ENTRY("BackColor", DISPID_BACKCOLOR, CLSID_StockColorPage)
	PROP_ENTRY("ShowSeconds", 1, CLSID_AtlTimerProp)
END_PROPERTY_MAP()



BEGIN_CONNECTION_POINT_MAP(CAtlTimerCtrl)
	CONNECTION_POINT_ENTRY(DIID__IAtlTimerCtrlEvents)
END_CONNECTION_POINT_MAP()


	LRESULT OnCreate (UINT nMsg, WPARAM wParam, 
                   LPARAM lParam, BOOL& bHandled);
	LRESULT OnDestroy (UINT nMsg, WPARAM wParam, 
                   LPARAM lParam, BOOL& bHandled);
	LRESULT OnTimer (UINT nMsg, WPARAM wParam, 
                   LPARAM lParam, BOOL& bHandled);

BEGIN_MSG_MAP(CAtlTimerCtrl)
	MESSAGE_HANDLER(WM_PAINT, OnPaint)
	MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
	MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
	MESSAGE_HANDLER(WM_CREATE, OnCreate)
	MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
	MESSAGE_HANDLER(WM_TIMER, OnTimer)
END_MSG_MAP()


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

// IAtlTimerCtrl
public:
	STDMETHOD(SetAlarm)(long SecondsToWait);
	STDMETHOD(get_ShowSeconds)(/*[out, retval]*/ BOOL *pVal);
	STDMETHOD(put_ShowSeconds)(/*[in]*/ BOOL newVal);
	HRESULT OnDraw(ATL_DRAWINFO& di);

	OLE_COLOR m_clrBackColor;
};

#endif //__ATLTIMERCTRL_H_
