]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "timer.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/window.h"
34 #include "wx/hashmap.h"
38 #include "wx/msw/private.h"
41 extern "C" WXDLLIMPEXP_BASE HWND
42 wxCreateHiddenWindow(LPCTSTR
*pclassname
, LPCTSTR classname
, WNDPROC wndproc
);
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // define a hash containing all the timers: it is indexed by timer id and
49 // contains the corresponding timer
50 WX_DECLARE_HASH_MAP(unsigned long, wxTimer
*, wxIntegerHash
, wxIntegerEqual
,
53 static wxTimerMap g_timerMap
;
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 void WINAPI
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
85 bool wxTimer::Start(int milliseconds
, bool oneShot
)
87 (void)wxTimerBase::Start(milliseconds
, oneShot
);
89 wxCHECK_MSG( m_milli
> 0, false, wxT("invalid value for timer timeour") );
93 NULL
, // don't use window
94 1, // id ignored with NULL hwnd anyhow
95 (UINT
)m_milli
, // delay
96 (TIMERPROC
)wxTimerProc
// timer proc to call
101 wxLogSysError(_("Couldn't create a timer"));
106 // check that SetTimer() didn't reuse an existing id: according to the MSDN
107 // this can happen and this would be catastrophic to us as we rely on ids
108 // uniquely identifying the timers because we use them as keys in the hash
109 if ( g_timerMap
.find(m_id
) != g_timerMap
.end() )
111 wxLogError(_("Timer creation failed."));
113 ::KillTimer(NULL
, m_id
);
119 g_timerMap
[m_id
] = this;
128 ::KillTimer(NULL
, m_id
);
130 g_timerMap
.erase(m_id
);
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
140 void wxProcessTimer(wxTimer
& timer
)
142 wxASSERT_MSG( timer
.m_id
!= 0, _T("bogus timer id") );
144 if ( timer
.IsOneShot() )
150 void WINAPI
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
152 wxTimerMap::iterator node
= g_timerMap
.find(idTimer
);
154 wxCHECK_RET( node
!= g_timerMap
.end(), wxT("bogus timer id in wxTimerProc") );
156 wxProcessTimer(*(node
->second
));
159 #endif // wxUSE_TIMER