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 }
Comments