home *** CD-ROM | disk | FTP | other *** search
- // timerctl.cpp : Implementation of the CTimerCtrl OLE control class.
-
- #include "stdafx.h"
- #include "timer.h"
- #include "timerctl.h"
- #include "timerppg.h"
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- const short ID_TIMER = 1;
-
-
- IMPLEMENT_DYNCREATE(CTimerCtrl, COleControl)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Message map
-
- BEGIN_MESSAGE_MAP(CTimerCtrl, COleControl)
- //{{AFX_MSG_MAP(CTimerCtrl)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_WM_ERASEBKGND()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Dispatch map
-
- BEGIN_DISPATCH_MAP(CTimerCtrl, COleControl)
- //{{AFX_DISPATCH_MAP(CTimerCtrl)
- DISP_PROPERTY_NOTIFY(CTimerCtrl, "Interval", m_interval, OnIntervalChanged, VT_I2)
- DISP_STOCKPROP_ENABLED()
- //}}AFX_DISPATCH_MAP
- DISP_FUNCTION_ID(CTimerCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
- END_DISPATCH_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Event map
-
- BEGIN_EVENT_MAP(CTimerCtrl, COleControl)
- //{{AFX_EVENT_MAP(CTimerCtrl)
- EVENT_CUSTOM("Timer", FireTimer, VTS_NONE)
- //}}AFX_EVENT_MAP
- END_EVENT_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Property pages
-
- // TODO: Add more property pages as needed. Remember to increase the count!
- BEGIN_PROPPAGEIDS(CTimerCtrl, 1)
- PROPPAGEID(CTimerPropPage::guid)
- END_PROPPAGEIDS(CTimerCtrl)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Initialize class factory and guid
-
- IMPLEMENT_OLECREATE_EX(CTimerCtrl, "TIMER.TimerCtrl.1",
- 0x56e0b3b0, 0x1784, 0x11ce, 0x96, 0xf, 0x52, 0x41, 0x53, 0x48, 0x0, 0x5)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Type library ID and version
-
- IMPLEMENT_OLETYPELIB(CTimerCtrl, _tlid, _wVerMajor, _wVerMinor)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Interface IDs
-
- const IID BASED_CODE IID_DTimer =
- { 0x56e0b3b1, 0x1784, 0x11ce, { 0x96, 0xf, 0x52, 0x41, 0x53, 0x48, 0x0, 0x5 } };
- const IID BASED_CODE IID_DTimerEvents =
- { 0x56e0b3b2, 0x1784, 0x11ce, { 0x96, 0xf, 0x52, 0x41, 0x53, 0x48, 0x0, 0x5 } };
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Control type information
-
- static const DWORD BASED_CODE _dwTimerOleMisc =
- OLEMISC_INVISIBLEATRUNTIME |
- OLEMISC_ACTIVATEWHENVISIBLE |
- OLEMISC_SETCLIENTSITEFIRST |
- OLEMISC_INSIDEOUT |
- OLEMISC_CANTLINKINSIDE |
- OLEMISC_RECOMPOSEONRESIZE;
-
- IMPLEMENT_OLECTLTYPE(CTimerCtrl, IDS_TIMER, _dwTimerOleMisc)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::CTimerCtrlFactory::UpdateRegistry -
- // Adds or removes system registry entries for CTimerCtrl
-
- BOOL CTimerCtrl::CTimerCtrlFactory::UpdateRegistry(BOOL bRegister)
- {
- if (bRegister)
- return AfxOleRegisterControlClass(
- AfxGetInstanceHandle(),
- m_clsid,
- m_lpszProgID,
- IDS_TIMER,
- IDB_TIMER,
- FALSE, // Not insertable
- _dwTimerOleMisc,
- _tlid,
- _wVerMajor,
- _wVerMinor);
- else
- return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Licensing strings
-
- static const TCHAR BASED_CODE _szLicFileName[] = _T("TIMER.LIC");
-
- static const TCHAR BASED_CODE _szLicString[] =
- _T("Copyright (c) 1994 Edward B. Toupin");
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::CTimerCtrlFactory::VerifyUserLicense -
- // Checks for existence of a user license
-
- BOOL CTimerCtrl::CTimerCtrlFactory::VerifyUserLicense()
- {
- return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
- _szLicString);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::CTimerCtrlFactory::GetLicenseKey -
- // Returns a runtime licensing key
-
- BOOL CTimerCtrl::CTimerCtrlFactory::GetLicenseKey(DWORD dwReserved,
- BSTR FAR* pbstrKey)
- {
- if (pbstrKey == NULL)
- return FALSE;
-
- *pbstrKey = SysAllocString(_szLicString);
- return (*pbstrKey != NULL);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::CTimerCtrl - Constructor
-
- CTimerCtrl::CTimerCtrl()
- {
- InitializeIIDs(&IID_DTimer, &IID_DTimerEvents);
-
- // TODO: Initialize your control's instance data here.
- SetInitialSize(24, 22);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::~CTimerCtrl - Destructor
-
- CTimerCtrl::~CTimerCtrl()
- {
- // TODO: Cleanup your control's instance data here.
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::OnDraw - Drawing function
-
- void CTimerCtrl::OnDraw(
- CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
- {
- // TODO: Replace the following code with your own drawing code.
- CBitmap bitmap;
- BITMAP bmp;
- CPictureHolder picHolder;
- CRect rcSrcBounds;
-
- // Load clock bitmap
- bitmap.LoadBitmap(IDB_CLOCK);
- bitmap.GetObject(sizeof(BITMAP), &bmp);
- rcSrcBounds.right = bmp.bmWidth;
- rcSrcBounds.bottom = bmp.bmHeight;
-
- // Create picture and render
- picHolder.CreateFromBitmap((HBITMAP)bitmap.m_hObject, NULL, FALSE);
- picHolder.Render(pdc, rcBounds, rcSrcBounds);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::DoPropExchange - Persistence support
-
- void CTimerCtrl::DoPropExchange(CPropExchange* pPX)
- {
- ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
- COleControl::DoPropExchange(pPX);
-
- // TODO: Call PX_ functions for each persistent custom property.
- PX_Short(pPX, _T("Interval"), m_interval, DEFAULT_INTERVAL);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::OnResetState - Reset control to default state
-
- void CTimerCtrl::OnResetState()
- {
- COleControl::OnResetState(); // Resets defaults found in DoPropExchange
-
- // TODO: Reset any other control state here.
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl::AboutBox - Display an "About" box to the user
-
- void CTimerCtrl::AboutBox()
- {
- CDialog dlgAbout(IDD_ABOUTBOX_TIMER);
- dlgAbout.DoModal();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimeCtrl::OnSetClientSite - Force creation of window
-
- void CTimerCtrl::OnSetClientSite()
- {
- RecreateControlWindow();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimerCtrl message handlers
-
- int CTimerCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (COleControl::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // TODO: Add your specialized creation code here
-
- // Start timer if in user mode and if enabled
- if (AmbientUserMode() && GetEnabled())
- StartTimer();
-
- return 0;
- }
-
- void CTimerCtrl::OnDestroy()
- {
- StopTimer();
-
- COleControl::OnDestroy();
-
- // TODO: Add your message handler code here
-
- }
-
- BOOL CTimerCtrl::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
-
- return COleControl::OnEraseBkgnd(pDC);
- }
-
- void CTimerCtrl::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- FireTimer();
- COleControl::OnTimer(nIDEvent);
- }
-
- void CTimerCtrl::OnIntervalChanged()
- {
- // TODO: Add notification handler code
- if (GetEnabled() && AmbientUserMode())
- {
- StopTimer();
- StartTimer();
- }
-
- MessageBox("OnIntervalChange");
-
- SetModifiedFlag();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimeCtrl::OnEnabledChanged - Start/stop the timer when the enable state
- // has changed.
-
- void CTimerCtrl::OnEnabledChanged()
- {
- if (AmbientUserMode())
- {
- if (GetEnabled())
- {
- if (GetHwnd() != NULL)
- StartTimer();
- }
- else
- StopTimer();
- }
-
- MessageBox("OnEnabledChange");
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimeCtrl::OnAmbientPropertyChange - Start the timer if user mode ambient
- // property has changed and if timer is enabled. Stop the timer if user
- // mode ambient property has changed and if timer is enabled.
-
- void CTimerCtrl::OnAmbientPropertyChange(DISPID dispid)
- {
- if (dispid == DISPID_AMBIENT_USERMODE)
- {
- // Start or stop the timer
- if (GetEnabled())
- {
- if (AmbientUserMode())
- StartTimer();
- else
- StopTimer();
- }
-
- InvalidateControl();
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimeCtrl::StartTimer - Start the timer.
-
- void CTimerCtrl::StartTimer()
- {
- SetTimer(ID_TIMER, m_interval, NULL);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CTimeCtrl::StopTimer - Stop the timer.
-
- void CTimerCtrl::StopTimer()
- {
- KillTimer(ID_TIMER);
- }
-
-