Problem with event on menuItm

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
Romain.Terracina
In need of some credit
In need of some credit
Posts: 2
Joined: Thu Oct 27, 2011 8:04 am

Problem with event on menuItm

Post by Romain.Terracina » Thu Oct 27, 2011 8:08 am

Hi,
I'm trying to put a click Event on a MenuItem ( used in MenuBar ).

+ File
-Quitter ( no problem on this event )
+ About ( problem on this event (first lvl item))

Do someone know this problem ? Have someone a solution ?

Sorry for my english but i'm french, and thank you

Romain

jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: Problem with event on menuItm

Post by jgrzybowski » Sat Nov 05, 2011 10:18 pm

Honestly, I do not understand your problem, could you describe problem in more details? I use wxDecC++ and I have not any problem to add event for menu bar items. I always use option “Edit MenuItems” in Properties window for MenuBar object. There is button “Create” for “OnMenu” event. Here you can find simple example with explanation step by step: http://wxdsgn.sourceforge.net/?q=node/13
Regards
Jarek

Romain.Terracina
In need of some credit
In need of some credit
Posts: 2
Joined: Thu Oct 27, 2011 8:04 am

Re: Problem with event on menuItm

Post by Romain.Terracina » Sun Nov 06, 2011 2:32 pm

Thank you for answer me.
My problem is just a bug I think.
After adding my event with Edit MenuItems and implementing the generate method.
When I click on this menu item, nothing happens.
And this only on a first level menu Item, no problem for the submenu...
Thanks

jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: Problem with event on menuItm

Post by jgrzybowski » Sun Nov 06, 2011 10:29 pm

OK. I understand your problem (I think it is not a bug). You have written only “first level menu item” has problem, because first level is wxMenu object. And sub menu items are objects of wxMenuItem:

wxMenuBar
+wxMenu example: File
-wxMenuItem example: New
-wxMenuItem example: Open

wxDevC++ via Edit MenuItems can create menu events like wxEVT_COMMAND_MENU_SELECTED (and macro EVT_MENU(id, func)). This kind of events are generated by wxMenuItem objects. Object wxMenu generate different events for example wxEVT_MENU_OPEN (and macro EVT_MENU_OPEN(func)), when user open first level menu. I believe the only way is to write manually code like this below. Next problem is macro EVT_MENU_OPEN(func) – there is not id argument, so we do not know which first level menu was opened. Short example below shows message “Menu test?” each time when user try open any menu, but the most important problem is: user can not open menu (bad solution). My advise:
+About
-About the program

Code: Select all

//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(Your_FrameFrm,wxFrame)
	////Manual Code Start
	//__here manually added new macro
	EVT_MENU_OPEN(Your_FrameFrm::Mnutestmenu1059Click) 
	////Manual Code End

	//__(...) macros of events created by wxDev automatically
	//__for example when designer use  Edit MenuItems

END_EVENT_TABLE()
////Event Table End

//__(...)
//__(...)
//__(...)

void Your_FrameFrm::Mnutestmenu1059Click(wxMenuEvent& event)
{
//__use wxMenuEvent in stead wxCommandEvent
	wxMessageBox("Menu test?");	
	return;
}
Regards
Jarek

Post Reply