How to send a notification that's handled by ON_NOTIFY?

后端 未结 2 1078
情话喂你
情话喂你 2021-01-15 04:01

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         


        
相关标签:
2条回答
  • 2021-01-15 04:38

    Send WM_NOTIFY, pass control id as wParam and NMHDR* as lParam.

    You'll need to allocate an NMHDR variable and fill it appropriately - set code to LVN_ITEMCHANGED and idFrom to the control id. You can only use SendMessage(), not PostMessage() since the receiving party will directly read memory through the NMHDR* pointer.

    Smth like this:

    NMHDR nmhdr;
    nmhdr.code = LVN_ITEMCHANGED;
    nmhdr.idFrom = controlId;
    nmhdr.hwndFrom = controlWindowHandle;
    SendMessage( targetWindowHandle, WM_NOTIFY, controlId, &nmhdr );
    
    0 讨论(0)
  • 2021-01-15 04:40

    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)
    

    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.

    0 讨论(0)
提交回复
热议问题