bonjour,
voilà, je suis bloqué avec l'utilisation du clavier sous wxwidget:
j'ai crée un évènement qui est sencé fermer le programme a l'appui d'une touche.
Et si je pouvait aussi avoir quelques conseils concernant le code car je suis débutant.
Voici mon code:
FirstApp.h:
FirstApp.cpp
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 #ifndef FIRSTAPP_H #define FIRSTAPP_H #include <wx/app.h> #include <wx/image.h> class FirstApp : public wxApp { public: virtual bool OnInit(); }; #endif // FIRSTAPP_H
FirstMain.h
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
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 #ifdef WX_PRECOMP #include "wx_pch.h" #endif #ifdef __BORLANDC__ #pragma hdrstop #endif //__BORLANDC__ #include "FirstApp.h" #include "FirstMain.h" IMPLEMENT_APP(FirstApp); bool FirstApp::OnInit() { wxImage::AddHandler( new wxPNGHandler ); #if defined(__WXMSW__) FirstFrame *frame = new FirstFrame("Le Monde de Stargate",wxPoint(0, 0), wxSize(1024, 780+25), wxMINIMIZE_BOX | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN); #elif defined(__WXMAC__) FirstFrame *frame = new FirstFrame("Le Monde de Stargate",wxPoint(0, 0), wxSize(1024, 780+25), wxMINIMIZE_BOX | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN); #elif defined(__UNIX__) FirstFrame *frame = new FirstFrame("Le Monde de Stargate",wxPoint(0, 0), wxSize(1024, 780), wxMINIMIZE_BOX | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN); #endif frame->Centre(); frame->Show(true); return true; }
FirstMain.cpp
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
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 #ifndef FIRSTMAIN_H #define FIRSTMAIN_H #ifndef WX_PRECOMP #include <wx/wx.h> #endif #include "FirstApp.h" class FirstFrame: public wxFrame { public: FirstFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); ~FirstFrame(); private: wxImage image2(); wxBitmap imagetemp(); wxBitmap image (); enum { idMenuQuit = 1000, }; void OnChar(wxKeyEvent& event); void OnPaint(wxPaintEvent& evt); void OnClose(wxCloseEvent& event); void OnQuit(wxCommandEvent& event); DECLARE_EVENT_TABLE() }; #endif // FIRSTMAIN_H
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
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
95
96
97
98 #ifdef WX_PRECOMP #include "wx_pch.h" #endif #ifdef __BORLANDC__ #pragma hdrstop #endif //__BORLANDC__ #include "FirstMain.h" //helper functions enum wxbuildinfoformat { short_f, long_f }; bool CarteAff = true; wxString wxbuildinfo(wxbuildinfoformat format) { wxString wxbuild(wxVERSION_STRING); if (format == long_f ) { #if defined(__WXMSW__) wxbuild << _T("-Windows"); #elif defined(__WXMAC__) wxbuild << _T("-Mac"); #elif defined(__UNIX__) wxbuild << _T("-Linux"); #endif #if wxUSE_UNICODE wxbuild << _T("-Unicode build"); #else wxbuild << _T("-ANSI build"); #endif // wxUSE_UNICODE } return wxbuild; } BEGIN_EVENT_TABLE(FirstFrame, wxFrame) EVT_KEY_DOWN(FirstFrame::OnChar) EVT_PAINT(FirstFrame::OnPaint) EVT_CLOSE(FirstFrame::OnClose) EVT_MENU(idMenuQuit, FirstFrame::OnQuit) END_EVENT_TABLE() FirstFrame::FirstFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(NULL, -1, title, pos, size, style) { this->SetFocus(); } FirstFrame::~FirstFrame() { } void FirstFrame::OnPaint(wxPaintEvent& evt) { if (CarteAff == true) { wxImage Tile0temp ("Tiles0.png", wxBITMAP_TYPE_PNG , -1); wxBitmap Tile0(Tile0temp, -1); wxPaintDC MonDc(this); for (int x = 0 ; x < 32 ; x++) { for (int y = 0 ; y < 25 ; y++) { wxBitmap carre = Tile0.GetSubBitmap(wxRect(32, 0, 32, 32)); MonDc.DrawBitmap(carre, x*32, y*32, true); } } wxImage image2b("sprites.png", wxBITMAP_TYPE_PNG , -1); wxBitmap imagetempb(image2b, -1); wxBitmap imageb = imagetempb.GetSubBitmap(wxRect(0, 0, 32, 64)); MonDc.DrawBitmap(imageb, 0, 0, true); CarteAff = false; } } void FirstFrame::OnChar(wxKeyEvent &event) { Destroy(); } void FirstFrame::OnClose(wxCloseEvent &event) { Destroy(); } void FirstFrame::OnQuit(wxCommandEvent &event) { Destroy(); }
Partager