The system header files define several macros that help create and interpret message parameters.
One set of macros helps you construct message parameters. These macros are useful for sending and posting messages. For example, the following code fragment uses the MPFROMSHORT macro to convert a 16-bit integer into the 32-bit message parameter:
HWND hwndButton; WinSendMsg(hwndButton, BM_SETCHECK, MPFROMSHORT(1), NULL);
A second set of macros helps you extract values from a message parameter. These macros are useful for handling messages in a window procedure. The following code fragment determines whether the window receiving the WM_FOCUSCHANGE message is gaining or losing the keyboard focus. The fragment uses the SHORT1FROMMP macro to extract the focus-change flag, the SHORT2FROMMP macro to extract the focus flag, and the HWNDFROMMP macro to extract the window handle.
USHORT fsFocusChange; MPARAM mp1, mp2; HWND hwndGainFocus; case WM_FOCUSCHANGE: fsFocusChange = SHORT2FROMMP(mp2); /* Gets focus-change flags */ if (SHORT1FROMMP(mp2)) /* Gaining or losing focus? */ hwndGainFocus = HWNDFROMMP(mp1);
A third set of macros helps you construct a message result. These macros are useful for returning message results in a window procedure, as the following code fragment illustrates:
return (MRFROM2SHORT(1, 2));