Search code examples
c++mfcafx

Message Map MFC: Inheriting multiple message maps


I am using MFC100, VS2010, MDI.

I am over ridding the basic functionality of CPreviewView.

I want it to act very similar to my CMyView(Which is a CView)

CMyView and CMyPreviewView are not in the same class inheritance paths.

So I want to inherit both the CPreviewView message map and CMyView message maps. Currently, it only inherits the CPreviewView message maps.

BEGIN_MESSAGE_MAP(CMyPreviewView, CPreviewView)
    //{{AFX_MSG_MAP(CMyPreviewView)
    ON_COMMAND(AFX_ID_PREVIEW_CLOSE, OnPreviewClose)
    ON_COMMAND(AFX_ID_PREVIEW_PRINT, OnPreviewPrint)
    ON_UPDATE_COMMAND_UI(ID_WINDOW_NEW, OnUpdateWindowNew)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

Any Ideas? I saw things like

ALT_MSG_MAP(UINT msgMapID)

But that is only for ATL. I could copy and paste my entire CMyView message map, but that is really messy being that is has 300+ handlers.


Solution

  • Put the message map into a separate .h file and #include it into both classes.

    BEGIN_MESSAGE_MAP(CMyPreviewView, CPreviewView)
        //{{AFX_MSG_MAP(CMyPreviewView)
        ON_COMMAND(AFX_ID_PREVIEW_CLOSE, OnPreviewClose)
        ON_COMMAND(AFX_ID_PREVIEW_PRINT, OnPreviewPrint)
        ON_UPDATE_COMMAND_UI(ID_WINDOW_NEW, OnUpdateWindowNew)
    
    #include "SharedViewMessageMap.h"
    
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()