Link to home
Start Free TrialLog in
Avatar of meow00
meow00

asked on

BEGIN_MESSAGE_MAP ....

Hi Experts,

    Can anyone please tell me what do "BEGIN_MESSAGE_MAP" and "END_MESSAGE_MAP" do ? also, how are they different from "afx_MSG_MAP" ? Thanks !

meow

Avatar of wayside
wayside

BEGIN_MESSAGE_MAP and END_MESSAGE_MAP are macros that set up a table  that maps a Windows message to the function to call to handle it.

I don't know what an "afx_MSG_MAP" is; if you are referring to the line in a header file that looks like

  //{{AFX_MSG(CMyClass)

it's a marker for Class Wizard to know what was created by the Class Wizard.

Avatar of meow00

ASKER

..... thanks for the information .... so what is "macro" ? how is it defined and used exactly ? thanks !
meow.
SOLUTION
Avatar of wayside
wayside

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> Virtual functions are not space-efficient because they require vtables, and vtables > consume memory even if the functions in them are not overridden. The amount of > memory used by a message map, in contrast, is proportional to the number of
> entries it contains.

There are at least two downsides to using message maps, however:

1) They are not type-safe. One of the primary reasons MFC programs work in debug but crash in release build is that a handler has been added to the message map by hand and it doesn't have the right prototype for that message.

2) They are not time efficient. Instead of having a nice efficient vtable it has to search through (possibly) multiple message maps until it finds an entry to handle the event.

In the days of 8 mb Windows systems the message map might have been a good choice; if the MFC developers were doing this today I wonder if they would make the same choice.