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 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.


Comments

  • using mpeg4 in VC++

    Posted by Legacy on 03/16/2002 12:00am

    Originally posted by: tarun

    hi!

    i would like to know how i could use VC++ to decode an mpeg4 input. if any body knows it please mail me at tar4ever@tatanova.com

    Reply
  • What about VS.NET?

    Posted by Legacy on 02/27/2002 12:00am

    Originally posted by: Anatoly

    Nice and helpful tip. Thanks a lot. Now I'm porting existing code to VC++.Net and noticed that the same approach doesn't work anymore. At least I couldn't map CPropertyPageEx derived calss messages using IDE's standard means (Control events).

    Any ideas how to solve the problem?

    Anatoly Smelkov
    anatoly@smelkov.com

    Reply
  • Plz Help me

    Posted by Legacy on 01/16/2002 12:00am

    Originally posted by: Saheer

    i have a very complicated task..
    
    i want to create thumb nail preview of html documents
    in dialog based mfc application in vc
    if u have any idea abt this subject plz mail me
    at the following address
    kpsaheer@hotmail.com

    regards & thanks
    saheer

    Reply
  • You Must Read It..!!

    Posted by Legacy on 12/13/2001 12:00am

    Originally posted by: Renjith Pandalam

    Sems to so better which help to keep some good manners and easiness whle programming with VC++.and i felt is so cool and comfortable.keep it up and good code

    Reply
  • WRong in VC++

    Posted by Legacy on 04/01/2001 12:00am

    Originally posted by: AHAM

    When I started Vc++ 6.0 
    
    Message to me :
    Msdev has caused an error in MFC42.DLL.

    What's Wrong
    Please I want The Help
    Thanks

    Reply
  • HAI

    Posted by Legacy on 09/29/1999 12:00am

    Originally posted by: I.R.L.REDDY

    HELLO FRIEND,

    IAM R.L.REDDY FROM HYDERABAD.IAM INTERESTED TO BECOME A PROFESSIONAL IN VC++.PLEASE GIVE ME YOUR VALUABLE SUGGESTIONS WHICH HELPS ME A LOT

    YOURS FAITHFULLY

    RAMALINGAREDDY

    VISUAL SOFT(INDIA)PVT LIMITED
    HYDERABAD.

    Reply
  • Thanks

    Posted by Legacy on 09/09/1999 12:00am

    Originally posted by: Alexander

    It's very usefull and buetefull!
    Thank you.

    Reply
  • Be very careful

    Posted by Legacy on 07/12/1999 12:00am

    Originally posted by: Rod Ball

    Although this trick will fool it into letting you add handlers (which is awesome by the way), if you have overridden any of the handlers in your base class, they will not be called as a result but, if you are careful you will catch it. For example, if in your base class you have overridden OnSetActive so you have CBaseClass::OnSetActive and then you define the macro

    #define CPropertyPage CBaseClass
    BEGIN_MESSAGE_MAP(CDerivedClass, CPropertyPage)
    #undef CPropertyPage

    and then you use class wizard to overrided it in the derived class you will get:

    BOOL CDerivedClass::OnSetActive()
    {
    return CPropertyPage::OnSetActive();
    }

    and your call to the overridden OnSetActive() is completely lost because it calls the CPropertyPage's OnSetActive(). So, be careful and make sure you correct these or else you may get undesired results.

    Reply
  • Document, document, document

    Posted by Legacy on 07/05/1999 12:00am

    Originally posted by: John Killingbeck

    Nice idea to solve a problem. A more thorough way to fool the system is to copy, then comment out, the original line and comment the reason for the change. That way the original can be easily restored if an upgrade bombs the trick. You want to fool the system, not your co-workers or yourself.

    Reply
  • bug from MS

    Posted by Legacy on 06/17/1999 12:00am

    Originally posted by: chandra s s

    i came across this problem,but i solved in the same way.but i saw this site today only.s/w giant microsoft is
    having lot of bugs,because they are releasing products very quicly
    
    nice idea indeed,to fool the products.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • On-demand Event Event Date: July 22, 2014 In this WhatWorks analysis, John Pescatore examines a use case where end users had local administrative rights on their PCs and it had gotten out of hand for this Fortune 500 Energy and Utilities company. The compelling event that prompted the company to reexamine this situation was the migration to Windows 7. In Windows XP, a custom tool that allowed users one of three levels of administrative rights to their workstations would need to be replaced during the Windows …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds