1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "timer.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/window.h"
37 #include "wx/msw/private.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 wxList
wxTimerList(wxKEY_INTEGER
);
44 UINT WINAPI _EXPORT
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
53 #define _EXPORT _export
56 // should probably be in wx/msw/private.h
58 #define MakeProcInstance(proc, hinst) proc
61 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
63 // ============================================================================
65 // ============================================================================
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
80 wxTimerList
.DeleteObject(this);
83 bool wxTimer::Start(int milliseconds
, bool oneShot
)
85 (void)wxTimerBase::Start(milliseconds
, oneShot
);
87 wxCHECK_MSG( m_milli
> 0, FALSE
, wxT("invalid value for timer timeour") );
89 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
90 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
92 m_id
= ::SetTimer(NULL
, (UINT
)(m_id
? m_id
: 1),
93 (UINT
)m_milli
, wxTimerProcInst
);
97 wxTimerList
.Append(m_id
, this);
103 wxLogSysError(_("Couldn't create a timer"));
113 ::KillTimer(NULL
, (UINT
)m_id
);
115 wxTimerList
.DeleteObject(this);
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 void wxProcessTimer(wxTimer
& timer
)
127 // Avoid to process spurious timer events
128 if ( timer
.m_id
== 0)
131 if ( timer
.IsOneShot() )
137 UINT WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
139 wxNode
*node
= wxTimerList
.Find((long)idTimer
);
141 wxCHECK_MSG( node
, 0, wxT("bogus timer id in wxTimerProc") );
143 wxProcessTimer(*(wxTimer
*)node
->Data());
148 #endif // wxUSE_TIMER