Handle any category of messages using Class Wizard | CodeGuru

Handle any category of messages using Class Wizard

Very often the Class Wizard will not list the messages you want to handle. In such situations you have to add the message map entry yourself. One common situation where this happens is when you derive from a class which itself has been derived from an MFC class. For example, if CListViewEx is derived from […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 1, 2002
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More




Very often the Class Wizard will not list the messages you want to handle. In such situations you have to add the message map entry yourself. One common situation where this happens is when you derive from a class which itself has been derived from an MFC class. For example, if CListViewEx is derived from CListView and then you derive CMyListView from CListViewEx, then you would be unable to handle any of the list view control messages in the CMyListView class using the Class Wizard.

Here’s what you can do to continue using the Class Wizard. At the top of your implementation file (cpp file) will the the message map which begins with a line like

BEGIN_MESSAGE_MAP(CMyListView, CListViewEx)

Class Wizard uses the second argument in this macro to decide whether it needs to display more messages. Since class wizard doesn’t recognize the CListViewEx class it does not show any of the list view control messages. What you can do is change the line to

#define CListView CListViewEx
BEGIN_MESSAGE_MAP(CMyListView, CListView)
#undef CListView

This will now allow you to add message handlers for the CListView class.

Thanks to Gert Rijs from Netherlands for suggesting the use of the #define directive. It fools the Class Wizard
parser but provides the right code to the compiler.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.