Page 1 of 1

Opening a frame within a menu bar

Posted: Thu Aug 01, 2019 10:00 pm
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!

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 1:22 pm
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.

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 4:48 pm
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!

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 4:55 pm
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(...) )

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 6:41 pm
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?

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 6:52 pm
by evstevemd
What are splits?
Also use Bind instead of Connect

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 6:56 pm
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

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 6:59 pm
by bandali99
I think I would need to make an event table for this

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 7:15 pm
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

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 7:26 pm
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?

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 7:36 pm
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.

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 7:37 pm
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.

Re: Opening a frame within a menu bar

Posted: Fri Aug 02, 2019 7:42 pm
by bandali99
thanks going to try this now!