Bonjour ,

Je dois creer un programme avec la bibiothèque WxWidgets.

J'ai creer deux boite de dialogue : Creer Noeud, Creer Fleche

J'aimerai que Creer Fleche renvoi les caractères afin que je puisse les stockés dans deux variables et les afficher dans la boite de dialogue principale : index.cpp.

J'aimerai faire comme creer Noeud qui utilise des Radio bouton mais avec des caractères.

index.h

Code : 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
 
#ifndef IndexH
#define IndexH
//------------------------------------------------------------------------------
class TMyApp : public wxApp
{
public:
    virtual bool OnInit();
};
//------------------------------------------------------------------------------
class TMyFrame : public wxFrame
{
public:
    TMyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
                                           long style = wxDEFAULT_FRAME_STYLE);
    void OnQuit(wxCommandEvent& event);
    void OnChgTitre(wxCommandEvent& event);
    void OnMenuInfoAbout(wxCommandEvent &event);
    void newfleche(wxCommandEvent &event);
 
private:
    wxMenu *menuFichier;
    wxMenu *menuInsertion;
    wxMenuBar *menuBarre;
 
    int Chiffre;
   char carac; //mémorise le chiffre sélectionné
    wxStaticText *Label;
    void OnDialog(wxCommandEvent& event);
 
DECLARE_EVENT_TABLE()
};
 
enum
{
    App_Quit = 1,
    Chgt_Titre,
    Creer_Noeud,
    Creer_Fleche
};
//------------------------------------------------------------------------------
#endif //IndexH
index.cpp

Code : 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
99
100
101
102
103
104
105
 
#include "wx/wxprec.h"
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
//------------------------------------------------------------------------------
#include "index.h"
#include "Noeud.h"
#include "fleche.h"
BEGIN_EVENT_TABLE(TMyFrame, wxFrame)
    EVT_MENU(App_Quit,  TMyFrame::OnQuit)
    EVT_MENU(Chgt_Titre, TMyFrame::OnChgTitre)
    EVT_MENU(Creer_Noeud, TMyFrame::OnMenuInfoAbout)
    EVT_MENU(Creer_Fleche, TMyFrame::newfleche)
END_EVENT_TABLE()
IMPLEMENT_APP(TMyApp)
//------------------------------------------------------------------------------
bool TMyApp::OnInit()
{
    TMyFrame *frame = new TMyFrame("Reseau de distribution",
                                           wxPoint(150, 150), wxSize(480, 360));
    frame->Show(true);
    return true;
}
//------------------------------------------------------------------------------
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));
    menuFichier = new wxMenu;
    menuFichier->Append(Chgt_Titre,"Changer le titre.");
    menuFichier->AppendSeparator();
    menuFichier->Append(App_Quit,"Quitter l'application.");
 
    menuInsertion = new wxMenu;
    menuInsertion->Append(Creer_Noeud,"Creer Noeud");
    menuFichier->AppendSeparator();
    menuInsertion->Append(Creer_Fleche,"Creer Fleche");   
 
    menuBarre = new wxMenuBar();
    menuBarre->Append(menuFichier,("&Fichier"));
    menuBarre->Append(menuInsertion,("&Insertion"));
 
    SetMenuBar(menuBarre);
 
  Label = new wxStaticText(this,-1,"N° Sélectionné : Aucun",wxDefaultPosition,
                           wxSize(-1, 60),wxALIGN_CENTRE | wxST_NO_AUTORESIZE );
    Label->SetFont(wxFont(12, wxSWISS , wxNORMAL, wxBOLD, false, "Arial"));
    wxBoxSizer *Psizer = new wxBoxSizer( wxVERTICAL );
    Psizer->Add(-1,60);
    Psizer->Add(Label,0, wxEXPAND );
    SetSizer(Psizer);
    Chiffre = 0;
 
 
}
//------------------------------------------------------------------------------
void TMyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    Close(true);
}
//------------------------------------------------------------------------------
void TMyFrame::OnChgTitre(wxCommandEvent& WXUNUSED(event))
{
    SetTitle("Nouveau Titre");
}
 
//------------------------------------------------------------------------------
void TMyFrame::OnMenuInfoAbout(wxCommandEvent& WXUNUSED(event))
{
     Dialog dialog(NULL,-1,"Titre",Chiffre);
     if ( dialog.ShowModal() == wxID_OK )
         {
            wxString st = "Aucun";
            Chiffre = dialog.GetValue();
              switch(Chiffre)
               {
                 case 1 : st = "Un";
                          break;
                 case 2 : st = "Deux";
                          break;         
 
                }
            Label->SetLabel("N° Sélectionné : " + st);
         }
}
//------------------------------------------------------------------------------
void TMyFrame::newfleche(wxCommandEvent& WXUNUSED(event))
{
     FlecheDialog dialog(NULL,-1,"Titre",carac);
     if ( dialog.ShowModal() == wxID_OK )
         {
            wxString st = "Aucun";
            carac = dialog.GetValue();
 
              st = carac;
 
 
            Label->SetLabel("N° Sélectionné : " + st);
         }
}
Noeud.h

Code : 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
 
#ifndef NoeudH
#define NoeudH
class Dialog : public wxDialog
{
public:
    Dialog(wxWindow* parent, wxWindowID id, const wxString& title, int nb = 0);
    virtual ~Dialog() { }
    int GetValue();
    void SetValue(int);
 
protected:
  DECLARE_EVENT_TABLE()    
private:
    wxRadioButton *RadioBouton1;
    wxRadioButton *RadioBouton2;
    wxStaticText *m_pInfoText;
    wxSizer *m_pTextSizer;
    wxButton *m_pOkButton;
};
 
 
#endif
Noeud.cpp

Code : 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
 
// For compilers that supports precompilation , includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
#include "Noeud.h"
 
Dialog::Dialog(wxWindow* parent, wxWindowID id, const wxString& titre, int nb)
                  : wxDialog(parent,id,titre,wxDefaultPosition,wxSize(240, 200))
{
 
  wxBoxSizer *dialogSizer = new wxBoxSizer(wxVERTICAL);
  wxFlexGridSizer *controlSizer = new wxFlexGridSizer(2, 2, 10, 10);
 
  RadioBouton1 = new wxRadioButton(this,-1,"Un");  
  RadioBouton2 = new wxRadioButton(this,-1,"Deux"); 
 
wxButton *MonBouton1 = new wxButton(this,wxID_OK,"Ok");
wxButton *MonBouton2 = new wxButton(this,wxID_CANCEL,"Annuler");
  controlSizer->Add(new wxStaticText(this, -1, "Nom"), 0, wxALIGN_CENTRE_VERTICAL);
  controlSizer->Add(new wxTextCtrl(this, -1), 0, wxALIGN_CENTRE_VERTICAL);
  controlSizer->Add(new wxStaticText(this, -1, "Consommation"), 0, wxALIGN_CENTRE_VERTICAL);
  controlSizer->Add(new wxTextCtrl(this, -1), 0, wxALIGN_CENTRE_VERTICAL);
 
  controlSizer->Add(RadioBouton1, 0, wxALIGN_CENTRE_VERTICAL);
  controlSizer->Add(RadioBouton2, 0, wxALIGN_CENTRE_VERTICAL);
controlSizer->Add(MonBouton1,0,wxALIGN_CENTRE_VERTICAL);
controlSizer->Add(MonBouton2,0,wxALIGN_CENTRE_VERTICAL);
 
  wxBoxSizer *buttonSizer = new wxBoxSizer(wxVERTICAL);
  dialogSizer->Add(controlSizer);
//  dialogSizer->Add(20, 20);
  dialogSizer->Add(buttonSizer); //, 0, wxALIGN_CENTRE);
  SetSizer(dialogSizer);
  SetAutoLayout(TRUE);
  Layout();
  SetValue(nb);
}
BEGIN_EVENT_TABLE(Dialog, wxDialog)
END_EVENT_TABLE()
//------------------------------------------------------------------------------
int Dialog::GetValue()
{
      int x = 0;
      if( RadioBouton1->GetValue() ) x = 1;
      if( RadioBouton2->GetValue() ) x = 2;
      return x;
}
//------------------------------------------------------------------------------
void Dialog::SetValue(int x)
{
      switch(x)
       {
        case 1 : RadioBouton1->SetValue(true);
                 break;
        case 2 : RadioBouton2->SetValue(true);
                 break;
               }
}
fleche.h

Code : 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
 
#ifndef FlecheH
#define FlecheH
class FlecheDialog : public wxDialog
{
public:
    FlecheDialog(wxWindow* parent, wxWindowID id, const wxString& title, char carac);
    virtual ~FlecheDialog() { }
    char GetValue();
 
 
protected:
  DECLARE_EVENT_TABLE()    
private:
 
    wxStaticText *Nom;
    wxTextCtrl *Valeur;
    wxStaticText *m_pInfoText;
    wxSizer *m_pTextSizer;
    wxButton *m_pOkButton;
};
 
 
#endif
fleche.cpp

Code : 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
 
 
// For compilers that supports precompilation , includes "wx/wx.h"
#include "wx/wxprec.h"
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
#include "fleche.h"
 
FlecheDialog::FlecheDialog(wxWindow* parent, wxWindowID id, const wxString& titre, char carac)
                  : wxDialog(parent,id,titre,wxDefaultPosition,wxSize(240, 200))
{
 
  wxBoxSizer *dialogSizer = new wxBoxSizer(wxVERTICAL);
  wxFlexGridSizer *controlSizer = new wxFlexGridSizer(2, 2, 10, 10);
 
  Nom = new wxStaticText(this,-1,"Nom"); 
  Valeur =  new wxTextCtrl(this, -1);
 
 
 
wxButton *MonBouton1 = new wxButton(this,wxID_OK,"Ok");
wxButton *MonBouton2 = new wxButton(this,wxID_CANCEL,"Annuler");
 
   controlSizer->Add(Nom, 0, wxALIGN_CENTRE_VERTICAL);
  controlSizer->Add(Valeur, 0, wxALIGN_CENTRE_VERTICAL);
 
controlSizer->Add(MonBouton1,0,wxALIGN_CENTRE_VERTICAL);
controlSizer->Add(MonBouton2,0,wxALIGN_CENTRE_VERTICAL);
 
  wxBoxSizer *buttonSizer = new wxBoxSizer(wxVERTICAL);
  dialogSizer->Add(controlSizer);
//  dialogSizer->Add(20, 20);
  dialogSizer->Add(buttonSizer); //, 0, wxALIGN_CENTRE);
  SetSizer(dialogSizer);
  SetAutoLayout(TRUE);
  Layout();
 
}
BEGIN_EVENT_TABLE(FlecheDialog, wxDialog)
END_EVENT_TABLE()
 
//------------------------------------------------------------------------------
char FlecheDialog::GetValue()
{
      char x ;
 
      return x;
}
//------------------------------------------------------------------------------

Merci