error 1406: cannot create a top-level child window

1,268 views
Skip to first unread message

Eran Ifrah

unread,
Nov 7, 2005, 12:36:24 PM11/7/05
to wx-u...@lists.wxwidgets.org
Hi,

I am trying to create a custom control, so, I derived a class from wxPanel
However, whenever I am trying to display it, (the 'new' and the
construction is OK), in the MyApp calls frame->Show() I get the
following error:

"Can't create window of class wxWindowClassNR (error 1406: cannot create
a top-level child window.)"

This is the basic declaration of my class
============ My class ==============================
class USTabCtrlBar :
public wxPanel
{
DECLARE_DYNAMIC_CLASS( USTabCtrlBar )
DECLARE_EVENT_TABLE()
USTabCtrlBar(void);
~USTabCtrlBar(void);
USTabCtrlBar(wxWindow* parent, wxWindowID id = wxID_ANY, const
wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL|wxSIMPLE_BORDER, const wxString& name =
"USTabCtrlBar");

virtual void Create(wxWindow* parent, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition, const wxSize& size =
wxDefaultSize, long style = wxTAB_TRAVERSAL|wxSIMPLE_BORDER, const
wxString& name = "USTabCtrlBar");

private:
wxPanel *m_buttonsPanel;
wxPanel *m_pagesPanel;
wxPanel *m_captionPanel;
wxBoxSizer *m_sizer;
bool m_controlCreated;
};
==================================================
Btw, I am using wx 2.6 on windows.
Can anyone suggest a solution to this?

Eran

Kevin Hock

unread,
Nov 7, 2005, 12:51:37 PM11/7/05
to wx-u...@lists.wxwidgets.org
What are you placing on your panel? The error indicates that you are
placing a top-level window (e.g. wxFrame, wxDialog) as a child of a non
top-level window (perhaps your wxPanel class). The problem is apparently
with wxWindowsClassNR, not USTabCtrlBar.

HTH,

Kevin

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
> For additional commands, e-mail: wx-use...@lists.wxwidgets.org
>
>

Eran Ifrah

unread,
Nov 7, 2005, 2:06:35 PM11/7/05
to wx-u...@lists.wxwidgets.org
Kevin Hock wrote:

In my class I have 2 panels, which are created in the Create() function
(no errors in this function):

void USTabCtrlBar::Create(wxWindow* parent, wxWindowID id, const
wxPoint& pos, const wxSize& size, long style, const wxString& name)
{
wxSize sz = size;
if(sz.GetHeight() < 200 && sz.GetWidth() < 200)
sz = wxSize(200, 200);
wxPanel::wxPanel(parent, id, pos, size, style, name);

m_buttonsPanel = new wxPanel(this, IDC_BUTTONS_PANEL, wxPoint(0, 0),
wxSize(sz.GetWidth(), 20));
m_buttonsPanel->SetBackgroundColour(BackgroudButtonsColor);

m_pagesPanel = new wxPanel(this, wxID_ANY, wxPoint(0, 20),
wxSize(sz.GetWidth(), sz.GetHeight()-20));

m_sizer = new wxBoxSizer(wxVERTICAL);
m_sizer->Add(m_buttonsPanel);
m_sizer->Add(m_pagesPanel);
SetSizerAndFit(m_sizer);
m_controlCreated = true;
}

And In the main frame I am doing to following:
void USMainFrame::InitSolutionBar(void)
{
:
m_wndSolutionBar = new wxDockWindow(...);
USTabCtrlBar *b = new USTabCtrlBar(m_wndSolutionBar, wxID_ANY,
wxDefaultPosition, wxSize(300, 300));
// Set the panel bar to the docking window
m_wndSolutionBar->SetClient( b );
:
}

Note that if i will try to set the panel directly on the wxDockWindow -
it works (i.e. I create 3 panels, the first panel is the parent of the
other 2, and the third one is set in the client area of the wxDockWindow)

Thx,
Eran


Vadim Zeitlin

unread,
Nov 7, 2005, 8:28:03 PM11/7/05
to wx-u...@lists.wxwidgets.org
On Mon, 07 Nov 2005 19:36:24 +0200 Eran Ifrah <eran....@gmail.com> wrote:

EI> I am trying to create a custom control, so, I derived a class from wxPanel
EI> However, whenever I am trying to display it, (the 'new' and the
EI> construction is OK), in the MyApp calls frame->Show() I get the
EI> following error:
EI>
EI> "Can't create window of class wxWindowClassNR (error 1406: cannot create
EI> a top-level child window.)"

This means that your parent window has never been created at Windows
level. Most likely reason is that you used default ctor for it and forgot
to call Create().

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/


Vadim Zeitlin

unread,
Nov 8, 2005, 5:41:14 AM11/8/05
to wx-u...@lists.wxwidgets.org
On Tue, 8 Nov 2005 12:35:05 +0200 Eran Ifrah <eran....@gmail.com> wrote:

EI> Actually I am not using the default ctor, but the long one( wxWindow*, id,
EI> pos, size etc.),
EI> My ctor is something like this:
EI> myfram( ... ))
EI> {
EI> Create(parent, id, pos, size, style);
EI> }
EI>
EI> And in my Create function I am doing:
EI> MyFrame::Create( .. )
EI> {
EI> wxMDIParentFrame::Create(parent, id, pos, size, style);
EI> // Here I am trying to create my control
EI> }
EI>
EI> Do you think moving the creation of my control outside the Create() function
EI> will fix this?

The only thing it matters is that it should be created after the parent
window Create() had been called.

Eran Ifrah

unread,
Nov 8, 2005, 5:35:05 AM11/8/05
to wx-u...@lists.wxwidgets.org
Actually I am not using the default ctor, but the long one( wxWindow*, id, pos, size etc.),

My ctor is something like this:
myfram( ... ))
{

    Create(parent, id, pos, size, style);
}

And in my Create function I am doing:
MyFrame::Create( .. )
{

    wxMDIParentFrame::Create(parent, id, pos, size, style);
   // Here I am trying to create my control
}

Do you think moving the creation of my control outside the Create() function will fix this?

Sorry for any typos - I am not using my regular email here (and I dont have the code infront of me)
Thx,
Eran

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
For additional commands, e-mail: wx-use...@lists.wxwidgets.org




--
Eran Ifrah
eran....@gmail.com
Reply all
Reply to author
Forward
0 new messages