1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#define TIMER_ID 10100
#define MNU_QUIT 10200
class MyApp : public wxApp
{
public:
virtual bool OnInit();
wxTimer myTimer;
};
class MyFrame : public wxFrame
{
DECLARE_EVENT_TABLE()
public:
MyFrame(const wxString& title, const wxPoint& pos,
const wxSize& size,
long style = wxDEFAULT_FRAME_STYLE);
void OnQuit(wxCommandEvent& event);
void OnKeyDown(wxKeyEvent &event);
void OnTimer(wxTimerEvent& event);
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
EVT_MENU(MNU_QUIT, MyFrame::OnQuit)
EVT_KEY_DOWN(MyFrame::OnKeyDown)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("Minimal wxWindows App"),
wxPoint(50, 50), wxSize(450, 340));
frame->Show(TRUE);
new wxLogWindow(frame, _T("Debug"));
wxGetApp().myTimer.SetOwner(frame, TIMER_ID);
wxGetApp().myTimer.Start(50);
return TRUE;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos,
const wxSize& size, long style) :
wxFrame(NULL, -1, title, pos, size, style)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append(MNU_QUIT, _T("E&xit\tAlt-X"), _T("Quit this program"));
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(menuFile, _T("&File"));
SetMenuBar(menuBar);
CreateStatusBar(2);
SetStatusText(_T("Welcome to wxWindows!"));
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)){Close(TRUE);}
void MyFrame::OnKeyDown(wxKeyEvent &event)
{
switch (event.GetKeyCode())
{
case WXK_SPACE:
wxLogMessage("espace tapé : Timer stoppé");
wxGetApp().myTimer.Stop();
break;
default:
event.Skip();
}
}
void MyFrame::OnTimer(wxTimerEvent& event)
{
wxLogMessage("OnTimer");
} |
Partager