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 92 93 94
| #include "wx/wx.h"
// Classe application :
class MyApp : public wxApp
{
public:
// Méthode virtuelle de démarrage de l'application :
virtual bool OnInit();
};
// Notre fenêtre minimale :
class MyFrame : public wxFrame
{
public:
// Constructeur :
MyFrame(const wxString& title);
bool TextChg;
wxTextCtrl *mlTextCtrl;
// 2 handler d'évènements
void OnQuit(wxCommandEvent& event);
void Onouvre(wxCommandEvent& event);
private:
// la table des évènements
DECLARE_EVENT_TABLE()
};
IMPLEMENT_APP(MyApp)
// Notre 'main' :
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App"));
frame->Show(true);
return true;
}
// IDs pour nos menus et contrôles :
enum
{
Minimal_Quit = wxID_EXIT,
Minimal_ouvre
};
// La table des évènements de notre fenêtre :
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_ouvre, MyFrame::Onouvre)
END_EVENT_TABLE()
// Le constructeur de notre classe de fenêtre :
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
// Ajoutons nos menus :
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(Minimal_Quit, _T("&Quitter\tAlt-Q"), _T("Sortir du programme"));
wxMenu *file2Menu = new wxMenu;
file2Menu->Append(Minimal_ouvre, _T("&ouvrir"), _T("ouvrir"));
// dans une barre de menu :
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, _T("&Fichier"));
menuBar->Append(file2Menu, _T("&ouvrir"));
SetMenuBar(menuBar);
// Une barre de statut :
CreateStatusBar(2);
SetStatusText(_T("Bienvenu sur notre premier projet wxWidgets avec MinGW !"));
}
// La gestion des évènements :
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void MyFrame::Onouvre(wxCommandEvent& WXUNUSED(event))
{
wxString nomfichier = wxFileSelector("Ouvrir" ,"" ,"" ,"",
"cpp files (*.cpp;*.h)|*.h;*.cpp|resources files (*.rc)|*.rc",wxOPEN);
if (!nomfichier.empty())
{
mlTextCtrl->LoadFile(nomfichier);
TextChg = false;
}
} |
Partager