Timer

定时器可以重复地调用一段代码。这个调用的间隔由毫秒指定。定时器不同于其他的图形部件,它没有图形接口。这里有一个创建定时器的例子

class wvl_test: public wvl::form
{
public:
    wvl_test()
    {
        timer_.make_event<wvl::event::tick>(wvl::bind_mem_fun(this, &wvl_test::on_tick));
        timer_.interval(2000);
        this->show();
    }
private:   
    void on_tick()
    {  wvl::message_box.show("TICK");   }
private:
    wvl::timer timer_;     
};

定时器没有叫  create ()的成员函数,它在你安装一个事件之后就开始工作,并且它默认的间隔是1000毫秒。您可以调用成员函数 interval ()来改变这个间隔。像上面代码所示,它的间隔被设置成2秒。

除了  make_event (), 这里还有一个叫 make_tick 的函数用来安装事件
timer_.make_tick(wvl::bind_mem_fun(this, &wvl_test::on_tick));

成员函数
template<typename _Event_Policy, typename _Function> void make_event(const _Function&) const 安装事件
template<typename _Function>
void make_tick(const _Function&) const
同上
bool enabled() const 判断定时器是否可用 
bool enabled(bool) 启用和禁用定时器
unsigned interval() const 返回当前定时器的间隔时间
unsigned interval(unsigned) 设置间隔时间

Return to Index