Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / My wxButton keeps dissappearing whenever the window is moved

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. My wxButton keeps dissappearing whenever the window is moved
#7426
Posted by: 2005-11-09 11:02:38
Hi i'm having an issue where whenever i move the window my button disappears until i click on it but then when i move the window the button disappears again. Actually when i start the program nothing is there except a blank window but when i move it everything appears except the button but when i click the button it appears but when the window is moved again only the button disappears
Message2. Re: My wxButton keeps dissappearing whenever the window is moved
#7427
Posted by: 2005-11-09 11:38:43
Ok so i added wxPaintDC in my redraw function and once the controls are there they now stay there unless you minimize the window, however they still dont appear right away when the window is first made, does anyone know what is wrong with that? Here is my code:

#include "wx/wx.h"
#include "F:\wxWidgets-2.6.2\include\wx\msw\notebook.h"
#include "F:\wxWidgets-2.6.2\include\wx\msw\glCanvas.h"
#include "glut.h"

//this is the main application and what it does on startup
class MyApp: public wxApp
{
public:
    virtual bool OnInit();
   virtual void OnIdle(wxIdleEvent& event);
   virtual void OnClose(wxCloseEvent& event);
   virtual void OnPaint(wxPaintEvent& event);
   virtual void OnAbout(wxCommandEvent& event);
   DECLARE_EVENT_TABLE()
private:
   wxFrame *frame;
   wxGLCanvas *MyGLCanvas;
   wxPanel *mainpanel;
   float red;
};


//this is where all events are stored for the window
BEGIN_EVENT_TABLE(MyApp, wxApp)
    //EVT_MENU(ID_Quit, MyFrame::OnQuit)
    //EVT_MENU(ID_About, MyFrame::OnAbout)
   EVT_BUTTON(2, MyApp::OnAbout)
   EVT_PAINT(MyApp::OnPaint)
   EVT_IDLE(MyApp::OnIdle)
   EVT_CLOSE(MyApp::OnClose)
END_EVENT_TABLE()

//this gets the app goign
IMPLEMENT_APP(MyApp)

enum
{
    ID_Quit = 1,
    ID_About,

};


//creates new window
bool MyApp::OnInit()
{
 /*   frame = new wxFrame((wxWindow *)NULL, 0, "Hello World", wxPoint(50,50), wxSize(450,340) );
    frame->Show(TRUE);
    SetTopWindow(frame);
   wxPanel *first = new wxPanel(frame, 2, wxPoint(10,10), wxSize(300,300), wxTAB_TRAVERSAL, "Panel1");
   wxButton *welcome = new wxButton(first, 2, "Hello Label", wxPoint(75, 100), wxSize(100,25),wxBU_EXACTFIT,wxDefaultValidator, "WelcomeButton");
    return TRUE;
*/
  red =0;
  frame = new wxFrame((wxFrame *)NULL, 1,  "Hello GL World");
  mainpanel = new wxPanel(frame,1, wxPoint(0,0), wxSize(3000, 100), 0, "Panel1");
  wxNotebook *nb = new wxNotebook(mainpanel, 1, wxPoint(50, 50), wxSize(100,100), 0, "NoteBook 1");
  MyGLCanvas = new wxGLCanvas(nb, 1, wxPoint(0,100), wxSize(3000,200), wxSUNKEN_BORDER, _("some text"));
  //MyGLCanvas = new wxGLCanvas(frame, -1, wxPoint(0,100), wxSize(3000,200), wxSUNKEN_BORDER, _("some text"));
  nb->InsertPage(0, MyGLCanvas, "Page1");
  nb->InsertPage(1, MyGLCanvas, "Page2");
  nb->InsertPage(2, MyGLCanvas, "Page3");
  nb->InsertPage(3, MyGLCanvas, "Page4");
  wxButton *trythis = new wxButton(mainpanel, 1, "Translate + 1", wxPoint(10, 10), wxSize(100, 25), 2, wxDefaultValidator, "button1");
  frame->Show(TRUE);
  SetTopWindow(frame);
  MyGLCanvas->SetCurrent();
 
  //..or try this instead
 
  return TRUE;
 
}


void MyApp::OnPaint(wxPaintEvent& event)
{
   wxPaintDC dc(frame);
   glClearColor(0.0, 0.0, 0.0, 0.0);
    glViewport(0, 0, (GLint)200, (GLint)200);
    glColor3f(red, 1.0, 1.0);

    glBegin(GL_POLYGON);
    glVertex2f(-0.5, -0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0.5, 0.5);
    glVertex2f(0.5, -0.5);
    glEnd();
    glFlush();

    MyGLCanvas->SwapBuffers();
}

void MyApp::OnIdle(wxIdleEvent& event)
{
  
}

void MyApp::OnClose(wxCloseEvent& event)
{
  
}

void MyApp::OnAbout(wxCommandEvent& WXUNUSED(event))
{
   red+=.01;
  //wxMessageBox("This is a wxWindows Hello world sample", "About Hello World", wxOK | wxICON_INFORMATION, frame);
}


Message3. Re: My wxButton keeps dissappearing whenever the window is moved
#7428
Posted by: guidance 2005-11-09 13:07:25
Try wxSizer !
Message4. Re: My wxButton keeps dissappearing whenever the window is moved
#7430
Posted by: 2005-11-09 22:32:15
Im sorry guidance but im not sure how this would help me or what wxsizer even does...If it helps when i dont put an onpaint method in my program liek if i comment it out i dont have the problem of dissappearing controls thank you for your help
Message5. Re: My wxButton keeps dissappearing whenever the window is moved
#7431
Posted by: guidance 2005-11-09 22:59:31
You may read the wxSizer doc and check its usage in samples first. I think wxSizer is the most valuable feature of wxWidgets in GUI programming!
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-3-28  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0