This example determines, during a WM_ERROR message, if the current thread is processing a message sent by another thread using WinInSendMsg; if so, a message box is generated with the error information to alert the active window that originally sent the message.

#define INCL_WINMESSAGEMGR      /* Window Message Functions     */
#define INCL_WINDIALOGS         /* Window Dialog Mgr Functions  */
#include <os2.h>

HAB     hab;            /* anchor-block handle                  */
BOOL  fSuccess;         /* Success indicator                    */
MPARAM  mpParam1;       /* Parameter 1                          */
USHORT  errorcode;      /* error code                           */
CHAR szMsg[100];        /* message text                         */
HWND   hwnd;            /* handle of window with error msg      */

case WM_ERROR:
     /* get error code */
     errorcode = SHORT1FROMMP(mpParam1);

     if (WinInSendMsg(hab))
        {
        /* parse and display error message */
        sprintf(szMsg, "Error code %d occurred", errorcode);
        WinMessageBox(HWND_DESKTOP,
            hwnd,                      /* client-window handle  */
            szMsg,                     /* body of the message   */
            "Error notification",      /* title of the message  */
            0,                         /* message box id        */
            MB_NOICON | MB_OK);        /* icon and button flags */
        }


[Back] [Next]