1. Diese Seite verwendet Cookies. Wenn du dich weiterhin auf dieser Seite aufhältst, akzeptierst du unseren Einsatz von Cookies. Weitere Informationen

wx widget refresh()

Dieses Thema im Forum "Borland CBuilder und VCL" wurde erstellt von KarlPichler, 22. Mai 2014.

  1. KarlPichler

    KarlPichler Mitglied

    Hallo liebe User,

    Bin Anfänger ind C++ und probier gerade ein GUI mit wxwidget zu implementieren.
    Soweit so gut, funktioniert auch alles wie gewünscht, allerdings werden mir bei der Refresh() Methode alle Elemente die nicht gezeichnet sind, enthalten. Sprich alle Buttons, Textfelder usw. sind weg. Warum? Ich bitte um Hilfe.

    Code (C++):
    1. #include <wx/panel.h>
    2. #include <wx/stattext.h>
    3. #include <wx/radiobut.h>
    4. #include <wx/statbox.h>
    5. #include <wx/menu.h>
    6. #include <wx/statbmp.h>
    7. #include <wx/textdlg.h>
    8.  
    9. #include "wx/wx.h"
    10. #include "wx/sizer.h"
    11.  
    12. #define __MAINFRM_H__
    13.  
    14. #ifdef __BORLANDC__
    15.     #pragma hdrstop
    16. #endif
    17.  
    18. #ifndef WX_PRECOMP
    19.     #include <wx/wx.h>
    20.     #include <wx/frame.h>
    21. #else
    22.     #include <wx/wxprec.h>
    23. #endif
    24.  
    25. #undef mainFrm_STYLE
    26. #define mainFrm_STYLE wxCAPTION | wxSYSTEM_MENU | wxMINIMIZE_BOX | wxCLOSE_BOX
    27.  
    28.  
    29. int calc1();
    30. int calc2();
    31. int calc3();
    32.  
    33. int XZahl = 245;
    34.  
    35.  
    36.  
    37. class mainFrm : public wxFrame
    38. {
    39.     private:
    40.         DECLARE_EVENT_TABLE();
    41.        
    42.     public:
    43.         mainFrm(wxWindow *parent, wxWindowID id = 1, const wxString &title = wxT("main"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = mainFrm_STYLE);
    44.         virtual ~mainFrm();
    45.         void WxToggleButton1Click(wxCommandEvent& event);
    46.         void WxButton1Click(wxCommandEvent& event);
    47.         void rb_kastenholmClick(wxCommandEvent& event);
    48.         void rb_iholmClick(wxCommandEvent& event);
    49.         void rb_kreisholmClick(wxCommandEvent& event);
    50.         void WxPanel1UpdateUI(wxUpdateUIEvent& event);
    51.        
    52.         void Mnuabout1002Click(wxCommandEvent& event);
    53.         void Mnuexit1003Click(wxCommandEvent& event);
    54.        
    55.         void WxEdit1Updated(wxCommandEvent& event);
    56.        
    57.                
    58.     private:
    59.        
    60.         wxStaticText *l_erg;
    61.         wxStaticText *erg_out;
    62.         wxRadioButton *rb_kreisholm;
    63.         wxRadioButton *rb_iholm;
    64.         wxRadioButton *rb_kastenholm;
    65.         wxStaticBox *Holmgeometrie;
    66.         wxStaticBox *Holmkraefte;
    67.         wxMenuBar *WxMenuBar1;
    68.         wxMessageDialog *WxMessageDialog1;
    69.         wxTextCtrl *WxEdit1;
    70.         wxButton *WxButton1;
    71.        
    72.  
    73.  
    74.         enum
    75.         {
    76.  
    77.            
    78.             ////GUI Enum Control ID Start
    79.             ID_MNU_MEN__1001 = 1051,
    80.             ID_MNU_ABOUT_1002 = 1002,
    81.             ID_MNU_EXIT_1003 = 1003,
    82.            
    83.             ID_WXBUTTON1 = 1049,
    84.             ID_WXEDIT1 = 1001,
    85.            
    86.             ID_L_ERG = 1026,
    87.             ID_ERG_OUT = 1025,
    88.             ID_RB_KREISHOLM = 1024,
    89.             ID_RB_IHOLM = 1023,
    90.             ID_RB_KASTENHOLM = 1022,
    91.             ID_HOLMGEOMETRIE = 1011,
    92.             ID_HOLMKRAEFTE = 1010,
    93.             ////GUI Enum Control ID End
    94.             ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
    95.         };
    96.  
    97.         void OnClose(wxCloseEvent& event);
    98.         void CreateGUIControls();
    99.  
    100. };
    101.  
    102.  
    103.  
    104. BEGIN_EVENT_TABLE(mainFrm,wxFrame)  
    105.     EVT_CLOSE(mainFrm::OnClose)
    106.     EVT_RADIOBUTTON(ID_RB_KREISHOLM,mainFrm::rb_kreisholmClick)
    107.     EVT_RADIOBUTTON(ID_RB_IHOLM,mainFrm::rb_iholmClick)
    108.     EVT_RADIOBUTTON(ID_RB_KASTENHOLM,mainFrm::rb_kastenholmClick)
    109.    
    110.     EVT_TEXT(ID_WXEDIT1,mainFrm::WxEdit1Updated)
    111.  
    112.     EVT_MENU(ID_MNU_ABOUT_1002, mainFrm::Mnuabout1002Click)
    113.     EVT_MENU(ID_MNU_EXIT_1003, mainFrm::Mnuexit1003Click)
    114.    
    115.     EVT_BUTTON(ID_WXBUTTON1,mainFrm::WxButton1Click)
    116. END_EVENT_TABLE()
    117.  
    118.  
    119.  
    120.  
    121. mainFrm::mainFrm(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
    122. : wxFrame(parent, id, title, position, size, style)
    123. {
    124.     CreateGUIControls();
    125. }
    126.  
    127. mainFrm::~mainFrm()
    128. {
    129. }
    130.  
    131. void mainFrm::CreateGUIControls()
    132. {
    133.  
    134.     Holmkraefte = new wxStaticBox(this, ID_HOLMKRAEFTE, _("Holmmomente"), wxPoint(10, 10), wxSize(575, 405));
    135.     Holmgeometrie = new wxStaticBox(this, ID_HOLMGEOMETRIE, _("Holmgeometrie"), wxPoint(10, 420), wxSize(575, 150));
    136.  
    137.  
    138.     rb_kastenholm = new wxRadioButton(this, ID_RB_KASTENHOLM, _("Kastenholm"), wxPoint(70, 455), wxSize(144, 26), 0, wxDefaultValidator, _("rb_kastenholm"));
    139.     rb_iholm = new wxRadioButton(this, ID_RB_IHOLM, _("I- Holm"), wxPoint(70, 490), wxSize(144, 26), 0, wxDefaultValidator, _("rb_iholm"));
    140.     rb_kreisholm = new wxRadioButton(this, ID_RB_KREISHOLM, _("Kreisholm"), wxPoint(70, 525), wxSize(144, 26), 0, wxDefaultValidator, _("rb_kreisholm"));
    141.    
    142.    
    143.     erg_out = new wxStaticText(this, ID_ERG_OUT, _("Ergebniss"), wxPoint(285, 492), wxDefaultSize, 0, _("erg_out"));
    144.     l_erg = new wxStaticText(this, ID_L_ERG, _("Ergebniss der Berechnung"), wxPoint(285, 464), wxDefaultSize, 0, _("l_erg"));
    145.  
    146.     WxMessageDialog1 =  new wxMessageDialog(this, _("Informatik Projekt 2014 - Dimensioning of an UAV wing main spar\nLAV13\nLukas Grabner, Philipp Strobl, David Hasko, Karl Pichler"), _("About"));
    147.    
    148.     WxEdit1 = new wxTextCtrl(this, ID_WXEDIT1, _(""), wxPoint(20, 375), wxSize(150, 30), 0, wxDefaultValidator, _("WxEdit1"));
    149.  
    150.     WxButton1 = new wxButton(this, ID_WXBUTTON1, _("WxButton1"), wxPoint(190, 375), wxSize(150, 30), 0, wxDefaultValidator, _("WxButton1"));
    151.  
    152.  
    153.     WxMenuBar1 = new wxMenuBar();
    154.     wxMenu *ID_MNU_MEN__1001_Mnu_Obj = new wxMenu();
    155.     ID_MNU_MEN__1001_Mnu_Obj->Append(ID_MNU_ABOUT_1002, _("About"), _(""), wxITEM_NORMAL);
    156.     ID_MNU_MEN__1001_Mnu_Obj->Append(ID_MNU_EXIT_1003, _("Exit"), _(""), wxITEM_NORMAL);
    157.     WxMenuBar1->Append(ID_MNU_MEN__1001_Mnu_Obj, _("Menü"));
    158.     SetMenuBar(WxMenuBar1);
    159.  
    160.     SetTitle(_("Informatik Projekt 2014"));
    161.     SetBackgroundColour(wxColor(198, 198, 198));
    162.     SetSize(8,8,600,630);
    163.     Center();
    164.    
    165. }
    166.  
    167. void mainFrm::OnClose(wxCloseEvent& event)
    168. {
    169.     Destroy();
    170. }
    171.  
    172.  
    173. class BasicDrawPane : public wxPanel
    174. {
    175.     public:
    176.         BasicDrawPane(wxFrame* parent);
    177.    
    178.         void paintEvent(wxPaintEvent & evt);
    179.         void paintNow();
    180.    
    181.         void render(wxDC& dc);
    182.    
    183.        
    184.    
    185.         DECLARE_EVENT_TABLE()
    186.        
    187. };
    188. class MyApp: public wxApp
    189. {
    190.     bool OnInit();
    191.  
    192.     mainFrm *frame;
    193.     BasicDrawPane * drawPane;
    194. };
    195. IMPLEMENT_APP(MyApp)
    196. bool MyApp::OnInit()
    197. {
    198.  
    199.     wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
    200.     frame = new mainFrm(NULL);
    201.     drawPane = new BasicDrawPane( (mainFrm*) frame );
    202.     sizer->Add(drawPane, 1, wxEXPAND);
    203.     frame->SetSizer(sizer);
    204.     frame->SetAutoLayout(true);
    205.     frame->Show();
    206.     return true;
    207. }
    208. BEGIN_EVENT_TABLE(BasicDrawPane, wxPanel)
    209.     EVT_PAINT(BasicDrawPane::paintEvent)
    210. END_EVENT_TABLE()
    211.  
    212. BasicDrawPane::BasicDrawPane(wxFrame* parent) :
    213. wxPanel(parent)
    214. {
    215. }
    216. void BasicDrawPane::paintEvent(wxPaintEvent & evt)
    217. {
    218.     wxPaintDC dc(this);
    219.     render(dc);
    220. }
    221. void BasicDrawPane::paintNow()
    222. {
    223.     wxClientDC dc(this);
    224.     render(dc);
    225. }
    226.  
    227.  
    228.  
    229.  
    230. void BasicDrawPane::render(wxDC&  dc)
    231. {
    232.  
    233.     int w1, w2, w3;
    234.    
    235.     int xb= 20;
    236.     int yb= 29;
    237.    
    238.     w1 = calc1();
    239.     w2 = calc2();
    240.     w3 = calc3();
    241.    
    242.    
    243.     wxPoint points[10];
    244.     wxPoint pointsA[3];
    245.     wxPoint pointsIHolm[13];
    246.    
    247.     // ---------------------------------------------------------------------------------------------------------------------
    248.     // draw background
    249.     // ---------------------------------------------------------------------------------------------------------------------
    250.     dc.SetBrush(*wxWHITE_BRUSH);
    251.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    252.     dc.DrawRectangle( 20, 30, 555, 340 );
    253.  
    254.     dc.SetBrush(*wxWHITE_BRUSH);
    255.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    256.     dc.DrawRectangle( 30, 453, 30, 30 );
    257.    
    258.     dc.SetBrush(*wxWHITE_BRUSH);
    259.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    260.     dc.DrawRectangle( 30, 488, 30, 30 );
    261.    
    262.     dc.SetBrush(*wxWHITE_BRUSH);
    263.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    264.     dc.DrawRectangle( 30, 523, 30, 30 );  
    265.    
    266.     // ---------------------------------------------------------------------------------------------------------------------
    267.     // draw coordinat system
    268.     // ---------------------------------------------------------------------------------------------------------------------
    269.  
    270.  
    271.  
    272.     dc.SetPen( wxPen( wxColor(224,238,238), 1 ) );
    273.    
    274.     for(int iz = 0; iz < 4; iz++)
    275.     {
    276.         dc.DrawLine( (xb+ 65), (yb+198-(32*iz)), (xb+ 500), (yb+198-(32*iz)));
    277.     }
    278.    
    279.     for(int iz2 = 0; iz2 < 13; iz2++)
    280.     {
    281.         dc.DrawLine( (xb+ 97 +(32*iz2)), (yb+230), (xb+ 97+(32*iz2)), (yb+80));
    282.     }
    283.    
    284.    
    285.     dc.SetPen( wxPen( wxColor(131,139,139), 1 ) );
    286.     dc.DrawLine( (xb+ 65), (yb+230), (xb+ 520), (yb+230));
    287.     dc.DrawLine( (xb+ 65), (yb+230), (xb+ 65), (yb+70));
    288.    
    289.     int xbp1 = (xb+ 65);
    290.     int ybp1 = (yb+70);
    291.    
    292.    
    293.     pointsA[0].x = xbp1-4;  pointsA[0].y = ybp1+15;
    294.     pointsA[1].x = xbp1+4;  pointsA[1].y =ybp1+15;
    295.     pointsA[2].x = xbp1+0;  pointsA[2].y = ybp1+0;
    296.     pointsA[3].x = xbp1-4;  pointsA[3].y = ybp1+15;
    297.    
    298.     dc.DrawPolygon(4, pointsA);    
    299.    
    300.    
    301.     xbp1 = (xb+ 520);
    302.     ybp1 = (yb+230);
    303.    
    304.     pointsA[0].x = xbp1;  pointsA[0].y = ybp1;
    305.     pointsA[1].x = xbp1-15;  pointsA[1].y =ybp1+4;
    306.     pointsA[2].x = xbp1-15;  pointsA[2].y = ybp1-4;
    307.     pointsA[3].x = xbp1;  pointsA[3].y = ybp1;
    308.    
    309.     dc.DrawPolygon(4, pointsA);      
    310.    
    311.    
    312.     // ---------------------------------------------------------------------------------------------------------------------
    313.     // draw lines
    314.     // ---------------------------------------------------------------------------------------------------------------------
    315.    
    316.    
    317.     int xbrl = (xb+ 65);
    318.     int ybrl = (yb+230);
    319.    
    320.    
    321.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    322.     dc.DrawLine( xbrl, ybrl, xbrl, (ybrl-w1));
    323.    
    324.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    325.     dc.DrawLine( (xbrl+430), ybrl, (xbrl+430), (ybrl-w2) );
    326.  
    327.     dc.SetPen( wxPen( wxColor(190, 24, 17), 1 ) );
    328.     dc.DrawLine( XZahl, ybrl, XZahl, (ybrl-w3) );
    329.  
    330.     dc.SetPen( wxPen( wxColor(0,0,0), 4 ) );
    331.     dc.DrawLine( xbrl, (ybrl-w1), XZahl, (ybrl-w3) );
    332.    
    333.     dc.SetPen( wxPen( wxColor(0,0,0), 4 ) );
    334.     dc.DrawLine( XZahl, (ybrl-w3), (xbrl+430), (ybrl-w2) );
    335.    
    336.    
    337.    
    338.     // ---------------------------------------------------------------------------------------------------------------------
    339.     // draw plane
    340.     // ---------------------------------------------------------------------------------------------------------------------
    341.  
    342.  
    343.     dc.SetBrush (wxBrush(wxColor(209,238,238)) );
    344.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    345.  
    346.     points[0].x = xb;  points[0].y = (yb+20);
    347.     points[1].x = (xb+ 80);   points[1].y =(yb+20);
    348.     points[2].x = (xb+ 80);  points[2].y = (yb+45);
    349.     points[3].x = (xb+ 20);   points[3].y = (yb+65);
    350.     points[4].x = (xb+ 60);  points[4].y = (yb+240);
    351.    
    352.     points[5].x = (xb+ 500);  points[5].y = (yb+240);
    353.     points[6].x = (xb+ 500);  points[6].y = (yb+300);
    354.     points[7].x = (xb+ 60);   points[7].y = (yb+300);
    355.     points[8].x = (xb+ 40);  points[8].y = (yb+340);
    356.     points[9].x = xb;  points[9].y = (yb+340);
    357.  
    358.     dc.DrawPolygon(10, points);
    359.  
    360.  
    361.     // ---------------------------------------------------------------------------------------------------------------------
    362.     // draw holm shapes
    363.     // ---------------------------------------------------------------------------------------------------------------------
    364.  
    365.     dc.SetBrush (wxBrush(wxColor(209,238,238)) );
    366.     dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    367.    
    368.     dc.DrawRectangle( 33, 456, 24, 24 );
    369.  
    370.  
    371.     pointsIHolm[0].x = 33;  pointsIHolm[0].y = 461+30;
    372.     pointsIHolm[1].x = 56;  pointsIHolm[1].y = 461+30;
    373.     pointsIHolm[2].x = 56;  pointsIHolm[2].y = 465+30;
    374.     pointsIHolm[3].x = 48;  pointsIHolm[3].y = 465+30;
    375.     pointsIHolm[4].x = 48;  pointsIHolm[4].y = 480+30;
    376.     pointsIHolm[5].x = 56;  pointsIHolm[5].y = 480+30;
    377.     pointsIHolm[6].x = 56;  pointsIHolm[6].y = 484+30;
    378.     pointsIHolm[7].x = 33;  pointsIHolm[7].y = 484+30;
    379.     pointsIHolm[8].x = 33;  pointsIHolm[8].y = 480+30;
    380.     pointsIHolm[9].x = 41;  pointsIHolm[9].y = 480+30;
    381.     pointsIHolm[10].x = 41;  pointsIHolm[10].y = 465+30;
    382.     pointsIHolm[11].x = 33;  pointsIHolm[11].y = 465+30;
    383.     pointsIHolm[12].x = 33;  pointsIHolm[12].y = 461+30;
    384.    
    385.     dc.DrawPolygon(13, pointsIHolm);  
    386.    
    387.     dc.DrawCircle(45,538,11);
    388. }
    389.  
    390. // ---------------------------------------------------------------------------------------------------------------------
    391. // ---------------------------------------------------------------------------------------------------------------------
    392. //  events
    393. // ---------------------------------------------------------------------------------------------------------------------
    394. // ---------------------------------------------------------------------------------------------------------------------
    395.  
    396. /*
    397. * rb_kastenholmClick
    398. */
    399. void mainFrm::rb_kastenholmClick(wxCommandEvent& event)
    400. {
    401.     erg_out->SetLabel("Wahl1");
    402. }
    403.  
    404. /*
    405. * rb_iholmClick
    406. */
    407. void mainFrm::rb_iholmClick(wxCommandEvent& event)
    408. {
    409.     erg_out->SetLabel("Wahl2");
    410. }
    411.  
    412. /*
    413. * rb_kreisholmClick
    414. */
    415. void mainFrm::rb_kreisholmClick(wxCommandEvent& event)
    416. {
    417.     erg_out->SetLabel("Wahl3");
    418. }
    419.  
    420. /*
    421. * Mnuabout1002Click
    422. */
    423. void mainFrm::Mnuabout1002Click(wxCommandEvent& event)
    424. {
    425.     this->WxMessageDialog1->ShowModal();
    426. }
    427.  
    428. /*
    429. * Mnuexit1003Click
    430. */
    431. void mainFrm::Mnuexit1003Click(wxCommandEvent& event)
    432. {
    433.     Close(true);
    434.     Destroy();
    435. }
    436.  
    437. void mainFrm::WxEdit1Updated(wxCommandEvent& event)
    438. {
    439.     wxString cad;
    440.     cad = WxEdit1->GetValue();
    441.    
    442.     XZahl = atoi(cad);
    443.     //XZahl = 100;
    444.     erg_out->SetLabel(cad);
    445.  
    446. }
    447.  
    448. void mainFrm::WxButton1Click(wxCommandEvent& event)
    449. {
    450.       Refresh();
    451.       //CreateGUIControls();  
    452. }
    453.  
    454. // ---------------------------------------------------------------------------------------------------------------------
    455. // ---------------------------------------------------------------------------------------------------------------------
    456. // end events
    457. // ---------------------------------------------------------------------------------------------------------------------
    458. // ---------------------------------------------------------------------------------------------------------------------
    459.  
    460.  
    461. // ---------------------------------------------------------------------------------------------------------------------
    462. // ---------------------------------------------------------------------------------------------------------------------
    463. // calculation functions
    464. // ---------------------------------------------------------------------------------------------------------------------
    465. // ---------------------------------------------------------------------------------------------------------------------
    466. int calc1()
    467. {
    468.     int i1 = 100;
    469.     return i1;    
    470. }
    471.  
    472. int calc2()
    473. {
    474.     int i1 = 20;
    475.     return i1;    
    476. }
    477.  
    478. int calc3()
    479. {
    480.     int i1 = 50;
    481.     return i1;    
    482. }
    483.  
    484. // ---------------------------------------------------------------------------------------------------------------------
    485. // ---------------------------------------------------------------------------------------------------------------------
    486. // end calculation functions
    487. // ---------------------------------------------------------------------------------------------------------------------
    488. // ---------------------------------------------------------------------------------------------------------------------
    Oder hat jemand vl. ein schönes template wo ein Zeichenpanel und Buttons usw. enthalten sind?

    Danke für eure hilfe.
    LG
     
  2. ComFreek

    ComFreek Mod | @comfreek Moderator

    Hallo,

    ich habe schon eine lange Zeit wxWidgets nicht mehr genutzt. Aber was soll denn das Refresh() bewirken? Wozu rufst du es auf?

    Kennst du wxFormBuilder oder vergleichbare GUI-Designer für wxWidgets? Die ersparen dir eine Menge Handarbeit.
     
  3. KarlPichler

    KarlPichler Mitglied

    Das Refresh sollte die Zeichengrafik aktualisieren. Sprich wenn ich einen Wert ändere sollte sich auch die Grafik verändern.
    Nach dem ein neuer Wert eingegeben wurde und der Button geklickt wurde wird das Refresh ausgeführt welches mir das ganze fenster neu zeichnet oder?
    Es wird auch neu gezeichnet allerdings fehlen dann die Buttons, Textfelder, usw. und ich habe keine Erklärung.

    Ja ich habe es auch mit dem GUI Designer von WexDev probiert, allerdings hab ich da keine Ahnung wie ich in eine Paint Methode komme!
    Hast du da vl. ein Beispiel?
     
  4. ComFreek

    ComFreek Mod | @comfreek Moderator

    Das Problem ist, dass du mit Refresh() die Methode von mainfrm aufrufst und nicht die von deinem BasicDrawPane.

    1. Probiere, eine entsprechende Methode für dein BasicDrawPane aufzurufen, z. B. paintNow()

    2. Allerdings befürchte ich, dass dies nicht so gut ist, weil wxWidgets selbst eine Message Queue für Paint-Ereignisse hat, soweit ich weiß. Vielleicht hilft dir der Aufruf Update() nach Refresh() weiter, siehe hier.

    Ein Beispiel habe ich nicht parat, wie gesagt, programmiere ich nicht mehr mit wxWidgets (allerdings nicht aus dem Grund, weil es schlecht ist o. ä.)
     
  5. KarlPichler

    KarlPichler Mitglied

    nope funktioniert nicht. Anderer Lösungsvorschlag? Wenn ich CreateGUIControl() ausführe zeichnet er das ganze Fenster neu, allerdings hüpft dieses herum.