> Cheers.
> The difference is that your code implements a single specialized message map
> each time, whereas the library code declares an entire family of message
[quoted text clipped - 3 lines]
> functions that use the base class, whatever it may be, in the argument list
> or return type.
I'm doing my best to understand what you wrote, but I'm having a hard
time connecting it to real life.
Can you please give a usage example to MFC's version of the macro? I'm
just missing its purpose.
Also, am I on the right track, or do you have a better idea for me to
solve my issue using standard macros instead of redefining it?
TIA.
Ben Voigt - 15 Dec 2006 16:11 GMT
>> The difference is that your code implements a single specialized message
>> map
[quoted text clipped - 13 lines]
> Also, am I on the right track, or do you have a better idea for me to
> solve my issue using standard macros instead of redefining it?
You have something along these lines you wrote:
// Define a custom template IMPLEMENT_MESSAGE_MAP
#define WND_TEMPLATE_IMPLEMENT_MESSAGE_MAP(baseClass) \
BEGIN_MESSAGE_MAP(TMyCWndWrapper< baseClass >, baseClass) \
ON_WM_ENABLE() \
END_MESSAGE_MAP()
WND_TEMPLATE_IMPLEMENT_MESSAGE_MAP( CListBox );
WND_TEMPLATE_IMPLEMENT_MESSAGE_MAP( CListCtrl );
With the MFC map, you get the per-class repetition for free as part of the
template behavior, no macro needed.
BEGIN_TEMPLATED_MESSAGE_MAP(TMyCWndWrapper, baseClass, baseClass) \
ON_WM_ENABLE()
END_MESSAGE_MAP()
defines the message map for TMyCWndWrapper<baseClass> for all needed values
of baseClass. The compiler will instantiate the template for both
TMyCWndWrapper<CListBox> and TMyCWndWrapper<CListCtrl> if you have used them
anywhere. This is far better than the macro because: it is type-safe and
error reporting is far better, and there is no need to maintain the list of
instances.
or to see why there need to be three arguments instead of two, add to the
above:
template <typename T>
class TMyDerivedWnd : TMyCWndWrapper<T> {};
BEGIN_TEMPLATED_MESSAGE_MAP(TMyDerivedWnd, baseClass,
TMyCWndWrapper<baseClass>) \
ON_WM_ENABLE()
END_MESSAGE_MAP()
> TIA.