views:

1260

answers:

1

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.

+5  A: 

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

Jim Carroll
thanks, this reference lead me to find out that I was declaring the timer wrong. You need to declare a wxTimer pointer and then access it that way.
DShook
Enjoy! I really enjoy wxWidgets programming. There's tons of hidden functionality within... serving html pages from within .zip files, using a stack of eventHandlers to handle application state using window.pushEventHandler() It's brilliant, and clean.
Jim Carroll