OSDN Git Service

cd86e9e8c1097e8de730cb2417fe3f719cb5d789
[wintimer/wintimer.git] / wintimer / timer.cpp
1 /*
2   ==============================================================================
3
4    This file is part of the mini timer
5    Copyright 2005-11 by Satoshi Fujiwara.
6
7    mini timer can be redistributed and/or modified under the terms of the
8    GNU General Public License, as published by the Free Software Foundation;
9    either version 2 of the License, or (at your option) any later version.
10
11    mini timer is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with mini timer; if not, visit www.gnu.org/licenses or write to the
18    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
19    Boston, MA 02111-1307 USA
20
21   ==============================================================================
22 */
23
24 #include "StdAfx.h"
25 #include "sf_windows.h"
26 #include "timer.h"
27
28 namespace sf {
29 timer::timer(sf::base_window& window,uint32_t timeout) : window_(window),timeout_(timeout),timer_id_(0)
30 {
31
32 }
33 void timer::start(){
34   if(!::SetTimer(reinterpret_cast<HWND>(window_.raw_handle()),(UINT_PTR)&timer_id_,timeout_,NULL)){
35     throw timer::exception();
36   };
37 };
38
39 void timer::stop()
40 {
41   if(timer_id_)
42   {
43     ::KillTimer(reinterpret_cast<HWND>(window_.raw_handle()),(UINT_PTR)&timer_id_);
44     timer_id_ = 0;
45   }
46 };
47
48 }