IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Code::Blocks Discussion :

Affichage dynamique wxStaticText


Sujet :

Code::Blocks

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2015
    Messages : 4
    Points : 4
    Points
    4
    Par défaut Affichage dynamique wxStaticText
    Bonjour,

    J'essaie de créer un projet en language C++ qui me premettra d'afficher dynamiquement dans une fenetre des informations provenant du port serie.
    Mon problème se situe au niveau de l affichage de ces informations.
    Pour mes besoins, je crée une nouvelle "thread" avec une fonction qui va écouter constamment le port serie .. jusque la, pas de problème.
    Mais je ne trouve pas le moyen de faire appel a mon objet "StaticText1" pour lui donner la nouvelle valeur de son Label ( SetLabel ) de facon dynamique !

    Pourriez-vous m'orienter ?
    J ai essayer un tas de chose tel que :

    - un appel direct a l'objet
    - créer une methode dans le fichier DynamicWindowMain en lui passant les valeurs voulue pour l affichage

    .. et de facon différentes mais j ai du louper quelque chose !?

    Afin d'etre plus clair, je joins un exemple grandement simplifié ..

    Je travail sous debian LXDE sur un système embarquer ( le projet joins est compilé pour ARM )
    J utilise Code::Blocks 10.05 avec wxWidgets et wxSmith

    DynamicWindowMain.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
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
     
     
    /***************************************************************
     * Name:      DynamicWindowMain.cpp
     * Purpose:   Code for Application Frame
     * Author:    AXSPark ()
     * Created:   2016-07-29
     * Copyright: AXSPark ()
     * License:
     **************************************************************/
     
    #include "DynamicWindowMain.h"
    #include <wx/msgdlg.h>
     
    //(*InternalHeaders(DynamicWindowFrame)
    #include <wx/intl.h>
    #include <wx/string.h>
    #include "DynamicData.h"
    //*)
     
    //helper functions
    enum wxbuildinfoformat {
        short_f, long_f };
     
    wxString wxbuildinfo(wxbuildinfoformat format)
    {
        wxString wxbuild(wxVERSION_STRING);
     
        if (format == long_f )
        {
    #if defined(__WXMSW__)
            wxbuild << _T("-Windows");
    #elif defined(__UNIX__)
            wxbuild << _T("-Linux");
    #endif
     
    #if wxUSE_UNICODE
            wxbuild << _T("-Unicode build");
    #else
            wxbuild << _T("-ANSI build");
    #endif // wxUSE_UNICODE
        }
     
        return wxbuild;
    }
     
    //(*IdInit(DynamicWindowFrame)
    const long DynamicWindowFrame::ID_STATICTEXT1 = wxNewId();
    const long DynamicWindowFrame::idMenuQuit = wxNewId();
    const long DynamicWindowFrame::idMenuAbout = wxNewId();
    const long DynamicWindowFrame::ID_STATUSBAR1 = wxNewId();
    //*)
     
    BEGIN_EVENT_TABLE(DynamicWindowFrame,wxFrame)
        //(*EventTable(DynamicWindowFrame)
        //*)
    END_EVENT_TABLE()
     
    DynamicWindowFrame::DynamicWindowFrame(wxWindow* parent,wxWindowID id)
    {
        //(*Initialize(DynamicWindowFrame)
        wxMenuItem* MenuItem2;
        wxMenuItem* MenuItem1;
        wxBoxSizer* BoxSizer2;
        wxMenu* Menu1;
        wxBoxSizer* BoxSizer1;
        wxMenuBar* MenuBar1;
        wxMenu* Menu2;
     
        Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
        BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
        BoxSizer2 = new wxBoxSizer(wxVERTICAL);
        StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
        BoxSizer2->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
        BoxSizer1->Add(BoxSizer2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
        SetSizer(BoxSizer1);
        MenuBar1 = new wxMenuBar();
        Menu1 = new wxMenu();
        MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
        Menu1->Append(MenuItem1);
        MenuBar1->Append(Menu1, _("&File"));
        Menu2 = new wxMenu();
        MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
        Menu2->Append(MenuItem2);
        MenuBar1->Append(Menu2, _("Help"));
        SetMenuBar(MenuBar1);
        StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
        int __wxStatusBarWidths_1[1] = { -1 };
        int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
        StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
        StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
        SetStatusBar(StatusBar1);
        BoxSizer1->Fit(this);
        BoxSizer1->SetSizeHints(this);
     
        Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&DynamicWindowFrame::OnQuit);
        Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&DynamicWindowFrame::OnAbout);
        //*)
     
     
    // CREATION DE LA NOUVELLE "thread"
    // NECESSITE L AJOUTE DE L OPTION "-pthread" DANS LES OPTIONS DU COMPILATEUR ET LE "linker settings"
     
        pthread_t thread_id;
        pthread_create(&thread_id,NULL, &DynamicData::DataToDisplay,NULL);
    }
     
    DynamicWindowFrame::~DynamicWindowFrame()
    {
        //(*Destroy(DynamicWindowFrame)
        //*)
    }
     
    void DynamicWindowFrame::OnQuit(wxCommandEvent& event)
    {
        Close();
    }
     
    void DynamicWindowFrame::OnAbout(wxCommandEvent& event)
    {
        wxString msg = wxbuildinfo(long_f);
        wxMessageBox(msg, _("Welcome to..."));
    }
    DynamicWindowMain.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
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
    /***************************************************************
     * Name:      DynamicWindowMain.h
     * Purpose:   Defines Application Frame
     * Author:    AXSPark ()
     * Created:   2016-07-29
     * Copyright: AXSPark ()
     * License:
     **************************************************************/
     
    #ifndef DYNAMICWINDOWMAIN_H
    #define DYNAMICWINDOWMAIN_H
     
    //(*Headers(DynamicWindowFrame)
    #include <wx/sizer.h>
    #include <wx/stattext.h>
    #include <wx/menu.h>
    #include <wx/frame.h>
    #include <wx/statusbr.h>
    //*)
     
    class DynamicWindowFrame: public wxFrame
    {
        public:
     
            DynamicWindowFrame(wxWindow* parent,wxWindowID id = -1);
            virtual ~DynamicWindowFrame();
            wxStaticText* StaticText1;
     
        private:
     
            //(*Handlers(DynamicWindowFrame)
            void OnQuit(wxCommandEvent& event);
            void OnAbout(wxCommandEvent& event);
            //*)
     
            //(*Identifiers(DynamicWindowFrame)
            static const long ID_STATICTEXT1;
            static const long idMenuQuit;
            static const long idMenuAbout;
            static const long ID_STATUSBAR1;
            //*)
     
            //(*Declarations(DynamicWindowFrame)
            wxStatusBar* StatusBar1;
            //*)
     
            DECLARE_EVENT_TABLE()
    };
     
    #endif // DYNAMICWINDOWMAIN_H
    DynamicData.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
     
    #include "DynamicData.h"
    #include "DynamicWindowMain.h"
     
    void *DynamicData::DataToDisplay(void *argv)
    {
        // BOUCLE REMPLACANT LA FONCTION DE RÉCUPÉRATION DES DONNÉES DU PORT SERIE
        for(int iData = 0;iData<10;iData++)
        {
            // "SET" DU LABEL DE "StaticText1" (wxStaticText) DE STATUS PUBLIC
     
             /*   DynamicWindowFrame FrameDyn;
                FrameDyn.StaticText1->SetLabel(iData);*/
                sleep(1);
                printf("%d\n",iData);
        }
     
        return 0;
    }
    DynamicData.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    #ifndef DYNAMICDATA_H_INCLUDED
    #define DYNAMICDATA_H_INCLUDED
     
    class DynamicData
    {
        public :
           static void *DataToDisplay(void *argv);
    };
     
    #endif // DYNAMICDATA_H_INCLUDED
    Merci
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Problème d'affichage dynamique d'une liste
    Par bor1s dans le forum ASP
    Réponses: 2
    Dernier message: 18/11/2005, 16h18
  2. Probleme d'affichage dynamique de ma base
    Par kudawoo2002 dans le forum ASP
    Réponses: 3
    Dernier message: 18/11/2005, 09h22
  3. Réponses: 1
    Dernier message: 08/07/2005, 02h46
  4. [VB.NET] - affichage dynamique dans un tableau
    Par karibouxe dans le forum ASP.NET
    Réponses: 8
    Dernier message: 20/06/2005, 15h07
  5. affichage dynamique en fonction des données en base
    Par jengo dans le forum Bases de données
    Réponses: 1
    Dernier message: 28/10/2004, 10h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo