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

瀏覽次數:21 次
跳到第一則未讀訊息

Andreas Falkenhahn

未讀,
2021年3月4日 上午11:37:502021/3/4
收件者: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

未讀,
2021年3月4日 中午12:09:162021/3/4
收件者: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

未讀,
2021年3月4日 中午12:43:262021/3/4
收件者: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

未讀,
2021年3月4日 中午12:46:272021/3/4
收件者: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

未讀,
2021年3月4日 下午3:18:292021/3/4
收件者:Ian McInerney
Thanks, that indeed solved the issue!
回覆所有人
回覆作者
轉寄
0 則新訊息