How can I respond to special macOS menu items like wxID_ABOUT?

15 views
Skip to first unread message

Andreas Falkenhahn

unread,
Mar 4, 2021, 11:37:50 AMMar 4
to wx-u...@googlegroups.com
When I declare a menu item as a special macOS menu item by giving it the identifier wxID_ABOUT, it correctly appears in the program menu but it doesn't seem to generate any event. Is there anything else I have to do or is this a bug?

This is the code:

wxMenuItem *item1 = new wxMenuItem(NULL, wxID_ABOUT, wxT("About"));
wxMenu *pop = new wxMenu();
pop->Append(item1);

pop->Bind(wxEVT_MENU, evtcallback_command, item1->GetId(), item1->GetId());

wxMenuBar *mb = new wxMenuBar();
mb->Append(pop, wxT("Test"));
SetMenuBar(mb);

When I select the "About" menu, evtcallback_command() is never called. When I use wxID_ANY instead of wxID_ABOUT it works correctly. But then the menu item doesn't appear in the program menu of course...

Complete test program attached.

--
Best regards,
Andreas Falkenhahn mailto:and...@falkenhahn.com
test.cpp

Igor Korot

unread,
Mar 4, 2021, 12:09:16 PMMar 4
to wx-u...@googlegroups.com
Hi, Andreas,
Does a minimal sample work for you?

It does have a wxID_ABOUT menu.

Thank you.

>
> --
> Best regards,
> Andreas Falkenhahn mailto:and...@falkenhahn.com
>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/1995741119.20210304173836%40falkenhahn.com.

Andreas Falkenhahn

unread,
Mar 4, 2021, 12:43:26 PMMar 4
to Igor Korot
On 04.03.2021 at 18:09 Igor Korot wrote:

> Does a minimal sample work for you?
> It does have a wxID_ABOUT menu.

Yes, it works but it sets up the event handler in a different way by using wxBEGIN_EVENT_TABLE which I don't use in my example. I use Bind() instead.

When I modify the minimal example to use Bind() directly, it stops working as well:

helpMenu->Bind(wxEVT_MENU, evtcallback, wxID_ABOUT, wxID_ABOUT);

evtcallback() never gets called. So it looks like the problem is with Bind()... is this not compatible with wxID_ABOUT or what is going on here?

Ian McInerney

unread,
Mar 4, 2021, 12:46:27 PMMar 4
to wx-u...@googlegroups.com
You can't bind the handler for wxID_ABOUT (or any of the IDs that are in the program menu) to the menu itself because the program menu doesn't dispatch the events to the wxMenu that originally contained the item (the item is effectively moved from its original menu to the program menu). You should attach the handler to the frame that contains the menubar with the program menu.

-Ian

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+u...@googlegroups.com
or visit http://groups.google.com/group/wx-users
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.

Andreas Falkenhahn

unread,
Mar 4, 2021, 3:18:29 PMMar 4
to Ian McInerney
Thanks, that indeed solved the issue!
Reply all
Reply to author
Forward
0 new messages