Basic wxWidgets Timer

守給你的承諾、 提交于 2020-01-13 05:52:08

问题


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

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.


回答1:


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

Set up your event constants

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);

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)
{

It shouldn't be any more difficult than that.



来源:https://stackoverflow.com/questions/571523/basic-wxwidgets-timer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!