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.
wxMenu *menuBorders = new wxMenu;
menuBorders->Append(ID_FSAVE, wxT("Save as Single &Image"));
menuBorders->Append(ID_TSAVE, wxT("Save as &Multi-Page TIFF"));
this->AppendSubMenu(menuBorders, wxT("Save &Triview..."));
However if I just attach them to (this) like so...
this->Append(ID_FSAVE, wxT("Save as Single &Image"));
this->Append(ID_TSAVE, wxT("Save as &Multi-Page TIFF"));
The command event is now captured by my event handler. I haven't found anything that mentions if a submenu needs to be managed any differently. My event handler is declared as a EVT_MENU. I'm using 3.0.2 on windows 7. Using Bind() doesn't work either.
In the 'Standard items demo' submenu, is it supposed to just print the ID when you click on a menuitem such as Add or are Dialog windows supposed to pop up as well? Because I am not seeing anything pop up from that particular menu item. Quit works, but Add or Print Preview have no dialogs popup. I guess it doesn't matter since they showed the events being caught.
I compiled using mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=debug CXXFLAGS="-std=gnu++11"
without issues.
Syntactically I don't see them doing anything different other than capturing the events to log them before skipping them.
Hi,
Are you trying to create your own handler for the menu or you are using the standard one?
Are you using event table or dynamic binding?
Could you please copy'n'paste the event binding code (either how do you call Bind() or the event table macros)?
Also I presume in the code you posted 'this' is referencing wxMenuBar/wxMenu, right?
And finally its a little suspicious that you said "second event is not fired". What about the first one? Are you talking about first clicking the menu and clicking it second time? Or you are referencing "ID_FSAVE" and "ID_ISAVE"?
ONEEYEMAN wrote:Hi,
Are you trying to create your own handler for the menu or you are using the standard one?
Are you using event table or dynamic binding?
Could you please copy'n'paste the event binding code (either how do you call Bind() or the event table macros)?
Also I presume in the code you posted 'this' is referencing wxMenuBar/wxMenu, right?
And finally its a little suspicious that you said "second event is not fired". What about the first one? Are you talking about first clicking the menu and clicking it second time? Or you are referencing "ID_FSAVE" and "ID_ISAVE"?
My this is a wxMenu and yeh, it's the second item in the submenu that isn't firing. Actually I've been tweaking them so the enum values have changed, but now neither item works unless I append them to (this) instead of a new wxMenu*. I think I actually had the first one set to the default menu macro instead of ID_TSAVE when it was working earlier, but now I can't remember what it is.
wxMenu *menuBorders = new wxMenu;
menuBorders->Append(ID_FSAVE, wxT("Save as Single &Image"));
menuBorders->Append(ID_TSAVE, wxT("Save as &Multi-Page TIFF"));
this->AppendSubMenu(menuBorders, wxT("Save &Triview..."));
Yeh, I've been tweaking things since I posted the initial issue, so names have changed, but having the same issue. I use the same event handler now for both and use evt.GetID() to set the different behavior for both menuItems. But I still have the same issue of them working when Appended to (this), instead of the wxMenu* that gets appended to (this) as a submenu
wxMenu *menuBorders = new wxMenu;
menuBorders->Append( ID_TSAVE, wxT("Save as Single &Image"));
menuBorders->Append( ID_TSAVEM, wxT("Save as &Multi-Page TIFF"));
this->AppendSubMenu(menuBorders, wxT("Save &Triview..."));
I haven't researched the sources, but i think menu events are usually sent directly to the wxFrame. The fact that you can catch some events in a class derived from wxMenuBar is just a lucky coincidence
doublemax wrote:I haven't researched the sources, but i think menu events are usually sent directly to the wxFrame. The fact that you can catch some events in a class derived from wxMenuBar is just a lucky coincidence
I'm starting to feel like my attempt to encapsulate every wxMenu into their own class, that gets appended to my wxMenuBar is just a terrible idea.
EDIT: So is the solution to build and handle anything wxMenuBar related in the wxFrame derived class?
It seems to be the one exception on the event page of the wxwidgets wiki,
A wxMenuBar doesn't send events to itself, but to its parent frame. This might seem inconsistent, but it's actually convenient in all common situations.
Is it potentially a bug that some of my items didn't send events to the parent frame? Even when I explicitly skipped the events that were working, just to see if they got processed by my wxFrame, the wxFrame wasn't picking them up.