wxTimer的应用-动态输出时间

利用wxTimer动态输出当前系统时间
 
wxTimer的应用-动态输出时间_第1张图片
 
timer.h
#ifndef TIMER_H_INCLUDED
#define TIMER_H_INCLUDED


class Netsim : public wxApp
{
public:
        virtual bool .Init();
        void ._timer(wxTimerEvent& f_event);
};


class Timer : public wxFrame
{
public:
        Timer();
        DECLARE_EVENT_TABLE()

private:
        wxTimer m_timer;
};


DECLARE_APP(Netsim)

BEGIN_EVENT_TABLE(Timer, wxFrame)
        EVT_TIMER(wxID_ANY, Netsim::on_timer)
END_EVENT_TABLE()


#endif // TIMER_H_INCLUDED
 
timer.cpp
#include <iostream>

#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "timer.h"
#include <wx/datetime.h>

IMPLEMENT_APP(Netsim)


bool Netsim::OnInit(){
        Timer* foo = new Timer();
        wxFrame* frame = new wxFrame((wxFrame*) NULL, -1, _T("Hello wxWidgets World"));
        frame->CreateStatusBar();
        frame->SetStatusText(_T("Hello World"));
        //frame->Show(TRUE);
        //SetTopWindow(frame);
        return true;
}

void Netsim::on_timer( wxTimerEvent& f_event )
{
        //获取当前系统时间
        wxString nowTime;
        wxDateTime now = wxDateTime::Now();
          //中国时区GMT+8,常数为A_WST
        nowTime=now.Format("%c", wxDateTime::A_WST).c_str();
        //动态在控制台输出当前时间
        std::cout << nowTime << std::endl;
}

Timer::Timer() : wxFrame((wxWindow *)NULL, wxID_ANY, _T("")), m_timer(this)
{
        //时间间隔1秒
        m_timer.Start(1000);
}

你可能感兴趣的:(wxTimer的应用-动态输出时间)