Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Resizing of child windows

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

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Resizing of child windows
#5040
Posted by: Michael12 2004-09-01 17:37:27
Hi!

I have a little problem. May be somebody can help me.

I have class wxApp. It's a main class. Inside of wxApp I declared class wxFrame- it's a frame of my window. Frame has child - wxWindow. You know frame should have window. On this window I situated static line, which is child to window. Okay. Now problem. When I try resize frame, window resize automatically. But I can't resize static line. I tried to use EVT_SIZE, but it doesn't make any result.

If I try use SetSize in wxFrame, it makes an system error. I tried SendEventSize. But it does nothing.

If somebody knows what I can do or, it will be better, has sources, please, answer me or send sources on e-mail: Michael12@inbox.ru.

Thanks beforehand.
Message2. Re: Resizing of child windows
#5041
Posted by: 2004-09-01 20:05:27
Try to use wxSizer's. I've noticed, that the wxFrame resizes its child controls automatically to the full size, so you can't then resize the child controls independetly. Perhaps the window style of wxFrame is guilt, I don't know, I'm a newbe in wxWindows too :)) A little workaround I found is to add first a wxPanel to the wxFrame as basis control and to create other controls using this wxPanel as parent. But this is not a nice solution. Try the sizers.
Message3. Re: Resizing of child windows
#5043
Posted by: upCASE 2004-09-01 22:03:27
Hi!
True, wxFrame resizes its child window and this is quite correct.
If the frame has exactly one child window, not counting the status and toolbar, this child is resized to take the entire frame client area. If two or more windows are present, they should be laid out explicitly either by manually handling wxEVT_SIZE or using sizers

The best way to go is by using sizers.
"A little workaround I found is to add first a wxPanel to the wxFrame as basis control and to create other controls using this wxPanel as parent."
I'd say that this is not just a "workaround", but quite a standard procedure. :)
Again I simply quote the docs:
A panel is a window on which controls are placed. It is usually placed within a frame. It contains minimal extra functionality over and above its parent class wxWindow; its main purpose is to be similar in appearance and functionality to a dialog, but with the flexibility of having any window as a parent.
So except from situation where you only have one child window that should get resized (like a wxTextCtrl in a wxFrame serving as a editor), you'll use a wxPanel in conection with a wxSizer to layout the controls on this panel.

The following code snippet should display a wxStaticLine in the center of a wxPanel and get resized.
MyFrame.h

#include <wx/wx.h>
#include <wx/image.h>

#ifndef MYFRAME_H
#define MYFRAME_H

#include <wx/statline.h>

class MyFrame: public wxFrame {
public:
 
    MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
protected:
    wxStaticLine* staticLine;
    wxPanel* panel;
};
#endif // MYFRAME_H

MyFrame.cpp

#include "MyFrame.h"

MyFrame::MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
{
    panel = new wxPanel(this, -1);
    staticLine = new wxStaticLine(panel, -1);

	wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
    sizer->Add(staticLine, 1, wxALIGN_CENTER_VERTICAL, 0);
    panel->SetAutoLayout(true);
    panel->SetSizer(sizer);
}

main.cpp

#include <wx/wx.h>
#include <wx/image.h>
#include "MyFrame.h"

class MyApp: public wxApp {
public:
    bool OnInit();
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    wxInitAllImageHandlers();
    MyFrame* frame = new MyFrame(NULL, -1, "wxFrame");
    SetTopWindow(frame);
    frame->Show();
    return true;
}
Hope this helps ;-)
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2022-8-10  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0