Improve company productivity with a Business Account.Sign Up

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

MESSAGE_MAP in template class

I have a small problem, how to write MESSAGE_MAP in template class. I've something like "template <class DLGCLASS> class CMyComboBox : public CComboBox" and I don't know how to write "BEGIN_MESSAGE_MAP(???, CComboBox)". I want only to know how (and if) I can do it, no how to do it by another way f.e. as not template class. Thanks.
0
lonicekm
Asked:
lonicekm
1 Solution
 
gandalf79Commented:
you would write something like:

BEGIN_MESSAGE_MAP(CMyComboBox<DLGCLASS>, CComboBox)
     ...
END_MESSAGE_MAP()

the compiler will make a new copy of CMyComboBox each time you place a new variable type into the class. DLGCLASS will be replaced at that time with the apropreate type.
0
 
lonicekmAuthor Commented:
Did u try it? Sure I tried this possibility and

error C2065: 'DLGCLASS' : undeclared identifier
error C2955: 'CMyComboBox' : use of class template requires template argument list
error C2039: '_GetBaseMessageMap' : is not a member of 'CMyComboBox'
...
and many others.
0
 
gandalf79Commented:
sorry for the bad info i was up late last night and was not thinking strait.

this is the definition for BEGIN_MESSAGE_MAP.

#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
     const AFX_MSGMAP* theClass::GetMessageMap() const \
          { return &theClass::messageMap; } \
     AFX_COMDAT AFX_DATADEF const AFX_MSGMAP theClass::messageMap = \
     { &baseClass::messageMap, &theClass::_messageEntries[0] }; \
     AFX_COMDAT const AFX_MSGMAP_ENTRY theClass::_messageEntries[] = \
     { \

you must retype this. you cant use the macros! the first function need to look like this

template <class DLGCLASS> const AFX_MSGMAP* CMyComboBox<DLGCLASS>::GetMessageMap() const
     { return &CMyComboBox<DLGCLASS>::messageMap; }

the lack of "template <class DLGCLASS>" before GetMessageMap() function is causing the error C2065 and C2955.

you may also have to rewrite other macros in the class like IMPLEMENT_DYNCREATE etc. in the same manner.

this is all i have time for right now but let me know how this works out for you and ill get back to you if you need any more help.
0
 
griesshCommented:
Dear lonicekm

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "gandalf79"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
MindphaserCommented:
Force accepted

** Mindphaser - Community Support Moderator **
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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