利用wxTimer动态输出当前系统时间
 
 
timer.h
InBlock.gif#ifndef TIMER_H_INCLUDED
InBlock.gif#define TIMER_H_INCLUDED
InBlock.gif
InBlock.gif
InBlock.gif class Netsim : public wxApp
InBlock.gif{
InBlock.gif public:
InBlock.gif         virtual bool .Init();
InBlock.gif         void ._timer(wxTimerEvent& f_event);
InBlock.gif};
InBlock.gif
InBlock.gif
InBlock.gif class Timer : public wxFrame
InBlock.gif{
InBlock.gif public:
InBlock.gif        Timer();
InBlock.gif        DECLARE_EVENT_TABLE()
InBlock.gif
InBlock.gif private:
InBlock.gif        wxTimer m_timer;
InBlock.gif};
InBlock.gif
InBlock.gif
InBlock.gifDECLARE_APP(Netsim)
InBlock.gif
InBlock.gifBEGIN_EVENT_TABLE(Timer, wxFrame)
InBlock.gif        EVT_TIMER(wxID_ANY, Netsim::on_timer)
InBlock.gifEND_EVENT_TABLE()
InBlock.gif
InBlock.gif
InBlock.gif#endif // TIMER_H_INCLUDED
 
timer.cpp
InBlock.gif#include <iostream>
InBlock.gif
InBlock.gif#include "wx/wxprec.h"
InBlock.gif
InBlock.gif#ifndef WX_PRECOMP
InBlock.gif#include "wx/wx.h"
InBlock.gif#endif
InBlock.gif#include "timer.h"
InBlock.gif#include <wx/datetime.h>
InBlock.gif
InBlock.gifIMPLEMENT_APP(Netsim)
InBlock.gif
InBlock.gif
InBlock.gif bool Netsim::OnInit(){
InBlock.gif        Timer* foo = new Timer();
InBlock.gif        wxFrame* frame = new wxFrame((wxFrame*) NULL, -1, _T( "Hello wxWidgets World"));
InBlock.gif        frame->CreateStatusBar();
InBlock.gif        frame->SetStatusText(_T( "Hello World"));
InBlock.gif         //frame->Show(TRUE);
InBlock.gif         //SetTopWindow(frame);
InBlock.gif         return true;
InBlock.gif}
InBlock.gif
InBlock.gif void Netsim::on_timer( wxTimerEvent& f_event )
InBlock.gif{
InBlock.gif         //获取当前系统时间
InBlock.gif        wxString nowTime;
InBlock.gif        wxDateTime now = wxDateTime::Now();
          //中国时区GMT+8,常数为A_WST
InBlock.gif        nowTime=now.Format( "%c", wxDateTime::A_WST).c_str();
InBlock.gif         //动态在控制台输出当前时间
InBlock.gif        std::cout << nowTime << std::endl;
InBlock.gif}
InBlock.gif
InBlock.gifTimer::Timer() : wxFrame((wxWindow *)NULL, wxID_ANY, _T("")), m_timer( this)
InBlock.gif{
InBlock.gif         //时间间隔1秒
InBlock.gif        m_timer.Start(1000);
InBlock.gif}