基本的 wxWidgets 计时器 [英] Basic wxWidgets Timer

查看:49
本文介绍了基本的 wxWidgets 计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 wxWidgets 的新手,我需要一些关于如何让 wxTimer 工作的示例代码.

Being new to wxWidgets I need some example code of how to get the wxTimer working.

参考 提供了 3 种使用方法,但不包含示例代码对于他们中的任何一个.最理想的是,我想让方法 2 起作用.

The reference gives 3 ways to use it but doesn't include sample code for any of them. Optimally, I'd like to get method 2 working.

推荐答案

(来自samples/widgets/gauge.cpp:)

(from the samples/widgets/gauge.cpp:)

设置事件常量

enum
{ 
    GaugePage_Reset = wxID_HIGHEST,
    GaugePage_Progress,

将事件连接到您的成员函数(使用您的事件常量)

Wire the event to your member function (using your event constant)

EVT_TIMER(GaugePage_Timer, GaugeWidgetsPage::OnProgressTimer)

然后你需要创建并启动你的计时器..

and then you'll need to create and start your timer..

static const int INTERVAL = 300; // milliseconds
m_timer = new wxTimer(this, GaugePage_Timer);
m_timer->Start(INTERVAL);

在文档中,我认为要理解的第二种方法是您的主窗口对象 ISA wxEventHandler,因此当您创建它时,计时器将自身连接到这个"(您的窗口).现在事件将发送到您的窗口,EVT_TIMER 可能是将其连接到 OnProgressTimer 函数的最有效方式.

In the documentation, the second method I think the thing to understand is that your main Window object ISA wxEventHandler, so the timer is wiring itself up to 'this' (your Window) when you create it. Now that the events are going to your window, the EVT_TIMER is probably the most efficient way to wire that up to your OnProgressTimer function.

您也需要调用该函数...

You'll need the function to call too...

void GaugeWidgetsPage::OnProgressTimer(wxTimerEvent& event)
{

应该不会比这更困难.

这篇关于基本的 wxWidgets 计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆