Opening a frame within a menu bar

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
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Opening a frame within a menu bar

Post by bandali99 »

I created an option in a menu bar to open a particular type of frame. I am having trouble opening the frame, I thought I could use Settopwindow and show however those commands are in myApp.

Code: Select all

void SimpleMenu::Ontwo(wxCommandEvent & event)
{
	wxFrame* frame = new twosplit(NULL); //change four to three or two to change layout

}
My plan is that when you select the type of split you want, a separate window opens with the split you selected. thanks!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Opening a frame within a menu bar

Post by ONEEYEMAN »

Hi,
So what is the problem?
The window is not opening? You handler does not execute? You receive an RT exception?

Thank you.
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Opening a frame within a menu bar

Post by bandali99 »

I thought I could use

Code: Select all

SetTopWindow(frame); 
frame -> show(true);
but thats only in the myApp library and im using wxFrame. Any ideas or examples as to go about this? thanks!
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Opening a frame within a menu bar

Post by doublemax »

You can still call frame->Show()

SetTopWindow() is not really necessary. That just sets the "main" window. This mean that when that window gets destroyed, the application will terminate.

You can also access the unique wxApp instance through wxTheApp from anywhere. (z.B: wxTheApp->SetTopWindow(...) )
Use the source, Luke!
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Opening a frame within a menu bar

Post by bandali99 »

Awesome the code runs with no error, however, when I click two split, three or four the program opens only the 4 split no matter the option...

Code: Select all

Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::OnQuit));
	Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::Ontwo));
	Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::Onthree));
	Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::Onfour));
this is how I connected them- am I suppose to create new IDs for each command or is there something else going wrong?
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2408
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Opening a frame within a menu bar

Post by evstevemd »

What are splits?
Also use Bind instead of Connect
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Opening a frame within a menu bar

Post by bandali99 »

evstevemd wrote: Fri Aug 02, 2019 6:52 pm What are splits?
Also use Bind instead of Connect
splits are window splits oops, I created functions called On two and so on to call for a frame that has a split-screen. splits is the nickname i gave it i guess sorry

I tried using bind and the same output comes out- no matter which option i click the same split screen comes up
Last edited by bandali99 on Fri Aug 02, 2019 7:03 pm, edited 1 time in total.
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Opening a frame within a menu bar

Post by bandali99 »

I think I would need to make an event table for this
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2408
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Opening a frame within a menu bar

Post by evstevemd »

bandali99 wrote: Fri Aug 02, 2019 6:56 pm splits are window splits oops, I created functions called On two and so on to call for a frame that has a split-screen. splits is the nickname i gave it i guess sorry
Please put a minimal code describig what you are doing. We can't peep on your machine to see what you are doing!
bandali99 wrote: Fri Aug 02, 2019 6:56 pm I tried using bind and the same output comes out- no matter which option i click the same split screen comes up
The advice was not for solving this issue. Avoid connect and event tables. Always use Bind
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Opening a frame within a menu bar

Post by bandali99 »

Code: Select all

	Bind(wxEVT_COMMAND_MENU_SELECTED, &SimpleMenu::OnQuit, this);
	Bind(wxEVT_COMMAND_MENU_SELECTED, &SimpleMenu::Ontwo, this);
Here is my code for binding the function to the command menu selected

Code: Select all

	menubar = new wxMenuBar;
	file = new wxMenu;
	file->Append(wxID_EXIT, wxT("&Quit"));
	file->Append(wxID_ANY, wxT("&two Screen Split"));
	file->Append(wxID_ANY, wxT("&three Screen Split"));
	file->Append(wxID_ANY, wxT("&four Screen Split"));
	menubar->Append(file, wxT("&File"));
	SetMenuBar(menubar);
here is my code for how I created my menu bar

Code: Select all

void SimpleMenu::Ontwo(wxCommandEvent & event)
{
	wxFrame* frame = new twosplit(NULL); //change four to three or two to change layout
	frame->Show(true);
}
here is my code for my function Ontwo

Did I bind it incorrectly?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Opening a frame within a menu bar

Post by ONEEYEMAN »

Hi,
bandali99 wrote: Fri Aug 02, 2019 6:41 pm Awesome the code runs with no error, however, when I click two split, three or four the program opens only the 4 split no matter the option...

Code: Select all

Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::OnQuit));
	Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::Ontwo));
	Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::Onthree));
	Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
		wxCommandEventHandler(SimpleMenu::Onfour));
this is how I connected them- am I suppose to create new IDs for each command or is there something else going wrong?
You should create a unique IDs, yes.
There is no other way to identify the menu you are clicking other than use different IDs.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Opening a frame within a menu bar

Post by doublemax »

No. For menu entries you need unique IDs.

E.g. if you take the "minimal" sample:

Code: Select all

enum
{
    Minimal_Quit = wxID_EXIT,
    Minimal_About = wxID_ABOUT
};

helpMenu->Append(Minimal_About, "&About\tF1", "Show about dialog");
fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
The sample uses a static event table (which is usually easier and less to type) for menu entries. If it used Bind(), it would look like this:

Code: Select all

Bind(wxEVT_MENU, &MyFrame::OnAbout, this, Minimal_About );
Bind(wxEVT_MENU, &MyFrame::OnQuit, this, Minimal_Quit );
So, you need to define unique IDs and use them in both the menu->Append() and Bind() call.
Use the source, Luke!
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Opening a frame within a menu bar

Post by bandali99 »

thanks going to try this now!
Post Reply