最简单的例子:
class MyFrame : public wxFrame
{
public:
...
void OnTimer(wxTimerEvent& event);
private:
wxTimer m_timer; //定义 wxTimer对象
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_TIMER(TIMER_ID, MyFrame::OnTimer) //绑定事件处理函数
END_EVENT_TABLE()
MyFrame::MyFrame()
: m_timer(this, TIMER_ID) //绑定此对象到this并指定TIMER_ID
{
m_timer.Start(1000); // 设置1秒间隔,并启动它
}
void MyFrame::OnTimer(wxTimerEvent& event)
{
// 在下面写需要执行的代码
}