Message Management

Defining Messages

User-defined messages are an interface. As an interface, they need to be defined. I have some macros in my text editor that make this easy. They generate a standard header for me which I fill in. The header looks something like the examples below.

Example 1: A message which has simple parameters, and which is sent but whose response doesn't matter:

/***************************************************************
*                           UWM_COLOR_IT
* Inputs:
*       WPARAM: ignored, 0
*       LPARAM: RGB value to use for coloring
* Result: LRESULT
*	Logically void, 0, always
* Effect:
*	Causes the view to repaint itself in the specified color
***************************************************************/
#define UWM_COLOR_IT_MSG _T("UWM_COLOR_IT-{4E7F6EC1-6ADC-11d3-BC36-006067709674}")

Example 2: A message which has no parameters, and which is sent for the purpose of getting a result:

/***************************************************************
*                           UWM_QUERY_CUT
* Inputs:
*       WPARAM: ignored, 0
*       LPARAM: ignored, 0
* Result: LRESULT
*	(LRESULT)(BOOL) TRUE if a cut operation is possible
*                       FALSE if there is no selection
***************************************************************/
#define UWM_QUERY_CUT_MSG _T("UWM_QUERY_CUT-{4E7F6EC3-6ADC-11d3-BC36-006067709674}")

Example 3: A message which has complex parameters, and which returns an interesting value:

/***************************************************************
*                           UWM_SET_COORD
* Inputs:
*       WPARAM: (WPARAM)(BOOL) FALSE for absolute
*                              TRUE for relative
*       LPARAM: (LPARAM)MAKELONG(x, y)
* Result: LRESULT
*	(LRESULT)MAKELONG(x, y) previous coordinate value
* Effect:
*	Sets the coordinate in the view, and returns the previous
*       coordinate.
* Notes:
*	The x,y values are added to the current position if
*	WPARAM is TRUE, otherwise they replace the current 
*	position.
***************************************************************/
#define UWM_SET_COORD_MSG _T("UWM_SET_COORD-{4E7F6EC2-6ADC-11d3-BC36-006067709674}")

Note that I carefully document the casting that is required to get the desired WPARAM and LPARAM values. Then I know when I'm writing my method how I should cast it. Here's an example of a handler for another message, which takes a pointer to an object. 

/***************************************************************
*                       CMyView::OnAssignMyInfo
* Inputs:
*       WPARAM: ignored, 0
*       LPARAM: (LPARAM)(LPMYINFO)
* Result: LRESULT
*	Logically void, 0, always
* Effect:
*	Modifies the current view by the values in LPMYINFO
* Notes:
*	If LPMYINFO.IsValidCount is FALSE, the count field is
*	not modified
***************************************************************/ 
LRESULT CMyView::OnAssignMyInfo(WPARAM, LPARAM lParam)
    {
     LPMYINFO info = (LPMYINFO)lParam;
     visible = info.visible;
     if(info.IsValidCount)
        count = info.count;
     return 0; // value is ignored
    }

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay