Page 1 of 1

the problem of resize event

Posted: Mon Feb 13, 2006 4:20 pm
by chenzhengxi
I wrote a very simple program.one frame,one menu,one button
but the sentence SetMenuBar( menuBar ) cannot exist with the
EVT_SIZE(MyFrame::OnSize)
void MyFrame::OnSize(wxSizeEvent& event)
{
if(myButton)
{
wxSize size = GetClientSize();
myButton->SetSize(0,0,size.x,size.y);
}
event.Skip();
}
why?
when I run the application,it show a memory err.

Posted: Mon Feb 13, 2006 4:57 pm
by phlox81
Hm, is myButton a valid pointer ?
You might wanna use a sizer, and set wxEXPAND for
the sizeritem which contains the wxButton.

Posted: Mon Feb 13, 2006 6:18 pm
by chenzhengxi
oh,no
I do follow you,the problem continue
And i debug it,it break at the function SetMenuBar(...);
if I romove it ,the program run ok.

Posted: Mon Feb 13, 2006 6:45 pm
by chenzhengxi
:D
the problem is the button point invalidation.
I donot understand
My button point has been defined in the head file.
I change the construct function from
//////////////////////
myFrame::myFrame(wxWindow *pParent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: wxFrame(pParent, id, title, pos, size, style, name)
{
CreateGUIControls();
}
//////////////////////
to
//////////////////////
myFrame::myFrame(wxWindow *pParent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: wxFrame(pParent, id, title, pos, size, style, name),myButton(NULL)
{
CreateGUIControls();
}
//////////////////////
all is ok
what different between them?
and all the initializtion code is in CreateGUIControls()

Posted: Mon Feb 13, 2006 7:23 pm
by phlox81
chenzhengxi wrote: //////////////////////
all is ok
what different between them?
and all the initializtion code is in CreateGUIControls()
if myButton is NULL, if(myButton) fails.

Posted: Mon Feb 13, 2006 9:36 pm
by chenzhengxi
I forget the constructor function is a special function.
:D
thx very much.