-
Notifications
You must be signed in to change notification settings - Fork 7
/
CCallbackTimer.cpp
135 lines (114 loc) · 2.41 KB
/
CCallbackTimer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//////////////////////////////////////////////////////////////////////////////
//
// CCallbackTimer.cpp
// Win32::Daemon Perl extension callback timer class source file
//
// Copyright (c) 1998-2008 Dave Roth
// Courtesy of Roth Consulting
// http://www.roth.net/
//
// This file may be copied or modified only under the terms of either
// the Artistic License or the GNU General Public License, which may
// be found in the Perl 5.0 source kit.
//
// 2008.03.24 :Date
// 20080324 :Version
//////////////////////////////////////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
#ifdef __BORLANDC__
typedef wchar_t wctype_t; /* in tchar.h, but unavailable unless _UNICODE */
#endif
#include <windows.h>
#include "CCallbackTimer.hpp"
CCallbackTimer::CCallbackTimer()
{
m_TimerID = 0;
m_TimerValue = 0;
m_MessageID = 0;
}
CCallbackTimer::~CCallbackTimer()
{
Stop();
}
BOOL CCallbackTimer::Start()
{
//
// Only consider starting if we are already in a stopped
// state AND the callback timer value is not 0.
//
if( 0 == m_TimerID && 0 < m_TimerValue )
{
m_TimerID = ::SetTimer( NULL, m_MessageID, m_TimerValue, (TIMERPROC) NULL );
}
return( (BOOL) 0 != m_TimerID );
}
BOOL CCallbackTimer::Stop()
{
if( m_TimerID )
{
if( 0 != ::KillTimer( 0, m_TimerID ) )
{
m_TimerID = 0;
}
}
return( (BOOL) 0 == m_TimerID );
}
BOOL CCallbackTimer::QueryState()
{
return( (BOOL) 0 != m_TimerID );
}
UINT CCallbackTimer::SetMessageID( UINT iNewMessageID )
{
BOOL fRunningState = QueryState();
//
// Let's only accept positive values. :)
//
Stop();
m_MessageID = iNewMessageID;
//
// Only start again if we were previously in the
// started state.
//
if( fRunningState )
{
Start();
}
return( m_MessageID );
}
UINT CCallbackTimer::GetMessageID()
{
return( m_MessageID );
}
int CCallbackTimer::GetTimerValue()
{
return( (int) m_TimerValue );
}
int CCallbackTimer::SetTimerValue( int iNewTimerValue )
{
BOOL fRunningState = QueryState();
//
// Let's only accept positive values. :)
//
if( -1 < iNewTimerValue )
{
Stop();
m_TimerValue = (UINT)iNewTimerValue;
//
// Only start again if we were previously in the
// started state.
//
if( fRunningState )
{
Start();
}
}
return( (int) m_TimerValue );
}
int CCallbackTimer::operator=( const int iRightHandValue )
{
if( 0 <= iRightHandValue )
{
SetTimerValue( iRightHandValue );
}
return( (int) m_TimerValue );
}