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
|
#include "main.h"
MonApp myapp; // mon programme
TMyFrame *frame;
bool running = true;
IMPLEMENT_APP(TMyApp)
bool TMyApp::OnInit()
{
frame = new TMyFrame( "Hello Event World",
wxPoint(50,50), wxSize(450,340) );
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}
void* MyThread::Entry()
{
while(running){
myapp.action();
//Pour l'instant j'ai une variable d'état dans mon appl. et je lance
//l'évènement en fonction de ceci.
//Mais cela va changer et l'évènement sera lancé directement
// de l'appli.
if(myapp.getEventState()) frame->sendEvent();
}
// Cette instruction est indispensable si l'on veut
// pouvoir arrêter le processus en cours de route.
// Grosso-modo, à ce moment, c'est ici que la "tache"
// vérifie que personne ne lui a demandé de se stopper.
TestDestroy();
return 0;
}
TMyFrame::TMyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
long style) : wxFrame(NULL, -1, title, pos, size, style)
{
SetIcon(wxICON(monicone));
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
MonBouton = new wxButton(this,ID_CHG_TITRE,_("Chgt Titre"), wxPoint(20,20),
wxDefaultSize);
MonBouton2 = new wxButton(this,ID_APP_QUIT,_("Quitter"), wxPoint(20,60),
wxDefaultSize);
// Création du thread.
thread = new MyThread();
thread->Create();
thread->Run();
}
void TMyFrame::sendEvent()
{
wxCustomEvent my_event(this);
ProcessEvent(my_event);
}
void TMyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
running = false;
Close(true);
}
void TMyFrame::OnChgTitre(wxCommandEvent& WXUNUSED(event))
{
SetTitle(_("Nouveau Titre"));
}
void TMyFrame::OnCustEvent(wxCustomEvent& event)
{
wxMessageBox(_("Evènement réussi!"), wxOK|wxICON_INFORMATION, this);
//Puisque c'est aussi un console application j'ai encore:
int main(int argc, char **argv)
{
...
return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
}
BEGIN_EVENT_TABLE(TMyFrame, wxFrame)
EVT_BUTTON(ID_APP_QUIT, TMyFrame::OnQuit)
EVT_BUTTON(ID_CHG_TITRE, TMyFrame::OnChgTitre)
EVT_CUST(wxID_ANY, TMyFrame::OnCustEvent)
END_EVENT_TABLE() |