wtimer.cpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 53 行

CPP
53
字号
#include "wtimer.hpp"

WObjectMap WEXPORT WTimer::_timerMap;
static int _timerId = 0;

extern "C" WORD _export _far _pascal timerProc( HWND /*hwin*/, UINT /*msg*/, int id, DWORD sysTime )
{
	WTimer* timer = (WTimer*)WTimer::_timerMap.findThis( id );
	ifptr( timer ) {
		timer->tick( sysTime );
	}
	return 0;
}

WEXPORT WTimer::WTimer( WObject* owner, cbt notify )
	: _owner( owner )
	, _notify( notify )
	, _id( 0 )
	, _count( 0 )
{
}

WEXPORT WTimer::~WTimer()
{
}

bool WEXPORT WTimer::start( WORD interval, int count )
{
	_count = count;
	_id = SetTimer( NIL, _timerId++, interval, (TIMERPROC) timerProc );
	_timerMap.setThis( this, _id );
	return _id != 0;
}

bool WEXPORT WTimer::stop()
{
	_timerMap.clearThis( this );
	return KillTimer( NIL, _id ) != 0;
}

void WEXPORT WTimer::tick( DWORD sysTime )
{
	if( isptr( _owner ) && isptr( _notify ) ) {
		(_owner->*_notify)( this, sysTime );
	}
	if( _count != 0 ) {
		_count -= 1;
		if( _count == 0 ) {
			stop();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?