如何发送由 ON_NOTIFY 处理的通知?

2022-01-12 00:00:00 c++ messages mfc

我正在尝试向我的自定义网格列表的所有者发布一个 LVN_ITEMCHANGED.我知道如何使用 PostMessage 发送 WM_ 用户消息(如图所示)

I'm trying to post a LVN_ ITEMCHANGED to my custom gridlist's owner. I know how to send a WM_ User message using PostMessage (as shown here)

::PostMessage( AfxGetMainWnd()->GetSafeHwnd(), WM_REFRESH, (WPARAM)pBuffer, (LPARAM)GetOutputIdx() );

当我使用相同的代码发送 LVN_ITEMCHANGED 消息时,

When I use this same code to send a LVN_ITEMCHANGED message though,

::PostMessage( AfxGetMainWnd()->GetSafeHwnd(), LVN_ITEMCHANGED, 0, 0);

好像没被抓到

ON_NOTIFY(LVN_ITEMCHANGED, ..., ...) 

我在所有者类中.

使用 ::PostMessage 发送 Notify 事件是不是我错了?
Notify 消息和 WM_ 前缀消息之间有区别吗?或者它们的处理方式有区别吗?
有人可以发布我如何正确发送消息的示例吗?

Am I wrong to be using ::PostMessage to send a Notify event?
Is there a difference between Notify messages and WM_ prefix messages or how they're handled?
Can someone post a sample of how I would send the message properly?

提前致谢.

编辑
我找到了解决问题的另一种方法.请参阅下面的答案.

Edit
I found another solution to the problem. See my answer below.

推荐答案

我发现我可以重写派生类中的消息处理程序并将消息传递给我的父控件,只需在消息映射中使用以下代码:

I found out that I could override the message handler in my derived class and pass the message on to my parent control simply by using this code in the message map:

ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnListItemChanged)

然后在 OnListItemChanged 中,我先调用基类函数然后返回 FALSE.这使得消息可以毫不费力地反映到父类.

Then in OnListItemChanged, I first call the base class function then return FALSE. This causes the message to be reflected to the parent class effortlessly.

相关文章