// AtlTimerProp.h : Declaration of the CAtlTimerProp

#ifndef __ATLTIMERPROP_H_
#define __ATLTIMERPROP_H_

#include "resource.h"       // main symbols
#include "atltimer.h"
#include "atltimerctrl.h"

EXTERN_C const CLSID CLSID_AtlTimerProp;

/////////////////////////////////////////////////////////////////////////////
// CAtlTimerProp
class ATL_NO_VTABLE CAtlTimerProp :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CAtlTimerProp, &CLSID_AtlTimerProp>,
	public IPropertyPageImpl<CAtlTimerProp>,
	public CDialogImpl<CAtlTimerProp>
{
public:
	CAtlTimerProp() 
	{
		m_dwTitleID = IDS_TITLEAtlTimerProp;
		m_dwHelpFileID = IDS_HELPFILEAtlTimerProp;
		m_dwDocStringID = IDS_DOCSTRINGAtlTimerProp;
	}

	enum {IDD = IDD_ATLTIMERPROP};

DECLARE_REGISTRY_RESOURCEID(IDR_ATLTIMERPROP)
DECLARE_NOT_AGGREGATABLE(CAtlTimerProp)

BEGIN_COM_MAP(CAtlTimerProp) 
	COM_INTERFACE_ENTRY_IMPL(IPropertyPage)
END_COM_MAP()

BEGIN_MSG_MAP(CAtlTimerProp)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_HANDLER(IDC_CHECK1, BN_CLICKED, OnShowSecondsClicked)
	CHAIN_MSG_MAP(IPropertyPageImpl<CAtlTimerProp>)
END_MSG_MAP()

	LRESULT OnInitDialog (UINT uMsg, WPARAM wParm, LPARAM lParam, BOOL& bHandled)
	{
		CComQIPtr<IAtlTimerCtrl, &IID_IAtlTimerCtrl> pTimer (m_ppUnk [0]) ;
		BOOL bCheck ;
		pTimer->get_ShowSeconds (&bCheck) ;

		CheckDlgButton (IDC_CHECK1, bCheck) ;
		return 1 ;
	}

	LRESULT OnShowSecondsClicked (WORD wNotify, WORD wID, HWND hWnd, BOOL& bHandled)
	{
		SetDirty (TRUE) ;
		return 0 ;
	}

	STDMETHOD(Apply)(void)
	{
		ATLTRACE(_T("CAtlTimerProp::Apply\n"));
	
		BOOL bShowSeconds = IsDlgButtonChecked (IDC_CHECK1) ;
		
		for (UINT i = 0; i < m_nObjects; i++)
		{
			CComQIPtr<IAtlTimerCtrl, &IID_IAtlTimerCtrl> pTimer (m_ppUnk [0]) ;
			pTimer->put_ShowSeconds (bShowSeconds) ;
		}
		m_bDirty = FALSE;
		return S_OK;
	}
};

#endif //__ATLTIMERPROP_H_
