0
votes
  1. Can I safely remove a BEGIN_MESSAGE_MAP/ END MESSAGE pair if there are no events to handled between them?

  2. I could have

    class MyListView : public ListView

    class MySpecialisedListView : public MyListView

and MySpecialisedListView has events to be handled, but MyListView does not. Could I remove BEGIN_MESSAGE_MAP/ END MESSAGE pair for MyListView and be sure that any event not handled in MySpecialisedListView will still be serviced by ListView event handlers despite the inheritance class in-between not having an event handler?

Microsoft's MSDN and MFC documentation does not cover this.

Thanks

1
why do you want to do this?samini
Because it make the code smaller. It is the principle that if the class does not need something, then don't add it in (with the proviso that it is safe and correct)SJHowe
in my case one of BEGIN_MESSAGE_MAP/ END MESSAGE (which is empty)is for AboutDlg and when I uncheck it on creating new project , it doesn't exist on codesamini

1 Answers

2
votes

I think that you are safe. Just remember to remove the DECLARE_MESSAGE_MAP() from the .h file aswell.

It works because these macros basically create an override of this function:

virtual const AFX_MSGMAP* GetMessageMap() const
{ return GetThisMessageMap(); }

And the static member function that hides the one from the inherited base class.

static const AFX_MSGMAP* GetThisMessageMap()
{
    static AFX_MSGMAP messageMap = 
        { baseClass::GetThisMessageMap(), <mapped_messages>... };
    return &messageMap;
}

If you do not override it, then it will use the ones inherited from the base class and all will work as expected.