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 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
75 wxTimerList
.DeleteObject(this);
78 bool wxTimer::Start(int milliseconds
, bool oneShot
)
80 (void)wxTimerBase::Start(milliseconds
, oneShot
);
82 wxCHECK_MSG( m_milli
> 0, FALSE
, wxT("invalid value for timer timeour") );
84 wxTimerList
.DeleteObject(this);
87 m_id
= SetTimer(NULL
, (UINT
)(m_id
? m_id
: 1),
88 (UINT
)milliseconds
, (TIMERPROC
) wxTimerProc
);
90 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
91 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
93 m_id
= SetTimer(NULL
, (UINT
)(m_id
? m_id
: 1),
94 (UINT
)milliseconds
, wxTimerProcInst
);
99 wxTimerList
.Append(m_id
, this);
105 wxLogSysError(_("Couldn't create a timer"));
115 KillTimer(NULL
, (UINT
)m_id
);
116 wxTimerList
.DeleteObject(this);
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 void wxProcessTimer(wxTimer
& timer
)
128 // Avoid to process spurious timer events
129 if ( timer
.m_id
== 0)
132 if ( timer
.IsOneShot() )
138 UINT WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
140 wxNode
*node
= wxTimerList
.Find((long)idTimer
);
142 wxCHECK_MSG( node
, 0, wxT("bogus timer id in wxTimerProc") );
144 wxProcessTimer(*(wxTimer
*)node
->Data());
149 #endif // wxUSE_TIMER