Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

Template window class - How to map messages ?

Hi,

I have a CWnd derived class that has to be a template class:
template <UINT COLUMNS>
class CMyWnd : public CWnd
{
  ...
};

When I try to use the BEGIN_MESSAGE_MAP macro I get compilation errors.
BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
>> error C2955: 'CMyWnd' use of class template requires template argument list.

What is the right way to write this ?
0
gurly
Asked:
gurly
  • 2
  • 2
1 Solution
 
jkrCommented:
It should read

BEGIN_MESSAGE_MAP(CMyWnd<[the number of colums you used to instantiate CMyWnd]>, CWnd)
0
 
gurlyAuthor Commented:
Yes, but when I write my class I still don't know the number of columns.
That's why it is a template.
0
 
jkrCommented:
I know - that is a Catch22, but that's the way it is...
0
 
gurlyAuthor Commented:
So what you're saying is that it can't be done.
A CWnd derived that is a template and also needs to map messages ?
Can I somehow call the BEGIN_MESSAGE_MAP where I instatiate CMyClass ?
0
 
MelangeCommented:
The BEGIN_MESSAGE_MAP macro is actually part of the instantiation of the class, not the declaration. You would need a separate BEGIN_MESSAGE_MAP section for every separate instantiation of the class.

Just by using the BEGIN_MESSAGE_MAP macro you would be creating an instance of the class, that's why you would need to specify the number of columns as part of the macro.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now