[wxMenu] creation without parent Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

[wxMenu] creation without parent

Post by MoonKid » Mon May 18, 2009 3:17 pm

I can read in the docs that all wxMenu objects need to be created on the heap (new) because their parents delete them automaticly.

But what is about wxMenu objects without parents? Is something like this correct?

Code: Select all

void BFPlaceholderButton::OnPressed(wxCommandEvent& rEvent)
{
    wxMenu menu;
    menu.Append(1, "entry 1");
    menu.Append(2, "entry 2");
    PopupMenu(&menu);
}

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Re: [wxMenu] creation without parent

Post by tan » Mon May 18, 2009 6:50 pm

Hi,
MoonKid wrote:I can read in the docs that all wxMenu objects need to be created on the heap (new) because their parents delete them automaticly.
not exactly. From wx docs:
---
All menus except the popup ones must be created on the heap.
---
MoonKid wrote: But what is about wxMenu objects without parents? Is something like this correct?

Code: Select all

void BFPlaceholderButton::OnPressed(wxCommandEvent& rEvent)
{
    wxMenu menu;
    menu.Append(1, "entry 1");
    menu.Append(2, "entry 2");
    PopupMenu(&menu);
}
Hence it is OK.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

Post Reply