Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic wxWidgets Timer

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.

like image 556
DShook Avatar asked Jan 24 '23 20:01

DShook


1 Answers

(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.

like image 73
Jim Carroll Avatar answered Feb 07 '23 21:02

Jim Carroll