问题
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