1

I have a hierarchy of classes one base B, several derived D from B.

There is a protected member m_treeID, which is the ID of each tree inside.

I want at the base class to fill the message map like

ON_NOTIFY(NM_CLICK, m_treeID, OnNMClickTree)

instead of going for each D to do

ON_NOTIFY(NM_CLICK, TREE_A, OnNMClickTree)
ON_NOTIFY(NM_CLICK, TREE_B, OnNMClickTree)

... and so on.

Is it possible?

sergiol
  • 4,122
  • 4
  • 47
  • 81
  • 1
    It's not quite clear what you want to achieve and how it relates to polymorphism. The base class may process the notification or not, as can the descendants. The descendants may also override the base-class implementation of the handler, and optionally call the base implementation as well. Plus, the protected member m_treeID is available to both the base and the descendants. Polymorphism is achieved in any case. And the 2nd parameter in the ON_NOTIFY() macro identifies the control, and that's how it's meant to work, why change this? – Constantine Georgiou Nov 08 '17 at 00:57
  • @ConstantineGeorgiou: Because I want to write 1 line with `ON_NOTIFY(NM_CLICK, m_treeID, OnNMClickTree)` instead of n lines each having individually the ID of each tree; given the processing is the same for every tree, I can have the handler method on the base class. – sergiol Nov 08 '17 at 11:04

1 Answers1

1

If I understand you right, have you looked at using ON_NOTIFY_RANGE?

If you need to process the same WM_NOTIFY message for a set of controls, you can use ON_NOTIFY_RANGE rather than ON_NOTIFY. For instance, you may have a set of buttons for which you want to perform the same action for a certain notification message.

When you use ON_NOTIFY_RANGE, you specify a contiguous range of child identifiers for which to handle the notification message by specifying the beginning and ending child identifiers of the range.

ClassWizard does not handle ON_NOTIFY_RANGE; to use it, you need to edit your message map yourself.

It explains how to use it in the article. As long as TREE_A, TREE_B etc. are sequentially numbered then you can have one message handler for all of them.

Community
  • 1
  • 1
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • No. You didn't understood. I know `ON_NOTIFY_RANGE`, but it only serves to handle a continuous range. I want to handle items based on **Polymorphism** using the ID they are identified by on a class member field. – sergiol Nov 07 '17 at 17:06
  • Yes, and I got errors because it m_treeID falls out of scope when inside the message map specification! – sergiol Nov 07 '17 at 17:23
  • Maybe you should have put your results of your tests in your question? – Andrew Truckle Nov 07 '17 at 17:42
  • @sergiol _I got errors because it m_treeID falls out of scope_ - Try to prefix it with the class name like `ON_NOTIFY(NM_CLICK, D::m_treeID, OnNMClickTree)`. – zett42 Nov 07 '17 at 23:56
  • @zett42: It gives another kind of errors. Otherwise, I wouldn't be posting question here! – sergiol Nov 08 '17 at 00:07