---
title: "Which are the various message map macros ?"  
description: "Which are the various message map macros ?"  
author: "Amit Singh"  
published: 2011-03-28  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/682/which-are-the-various-message-map-macros  
category: "visual c++"  
tags: ["visual c++"]  
reading_time: 2 minutes  

---

# Which are the various message map macros ?

Message maps are an MFC approach to windows programming. Instead of writing a WinMain () function that sends messages to your WindProc and then writing a WindProc that checks which kind of message this is and then calls another of your functions, you just write the function that will handle the message, and you add a message map to your class that says, in effect, "I will handle this sort of message." The framework handles whatever routing is required to send that message to you.\
A number of macros are used in message maps:- DECLARE_MESSAGE_MAP: used in the include file to declare that there will be a message map in the source file.- BEGIN MESSAGE MAP: marks the beginning of the message map in the source file.- END MESSAGE MAP: marks the end of the message map- ON_COMMAND: used to delegate the handling of a command to a function of a class.- ON_COMMAD_RANGS: used to handle a group of commands- ON_MESSAGE: used to delegate the handling of a user defined message to a function- ON_NOTIFY: used to handle the control notification message with some extra information and calls a member function of a class.

## Answers

### Answer by Amit Singh

Message maps are an MFC approach to windows programming. Instead of writing a WinMain () function that sends messages to your WindProc and then writing a WindProc that checks which kind of message this is and then calls another of your functions, you just write the function that will handle the message, and you add a message map to your class that says, in effect, "I will handle this sort of message." The framework handles whatever routing is required to send that message to you.\
A number of macros are used in message maps:- DECLARE_MESSAGE_MAP: used in the include file to declare that there will be a message map in the source file.- BEGIN MESSAGE MAP: marks the beginning of the message map in the source file.- END MESSAGE MAP: marks the end of the message map- ON_COMMAND: used to delegate the handling of a command to a function of a class.- ON_COMMAD_RANGS: used to handle a group of commands- ON_MESSAGE: used to delegate the handling of a user defined message to a function- ON_NOTIFY: used to handle the control notification message with some extra information and calls a member function of a class.


---

Original Source: https://www.mindstick.com/interview/682/which-are-the-various-message-map-macros

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
