Jump to content

WinInSendMsg

From EDM2
Revision as of 16:50, 8 April 2025 by Martini (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function determines whether the current thread is processing a message sent by another thread.

Syntax

WinInSendMsg(hab)

Parameters

hab (HAB) - Input
Anchor-block handle.

Returns

rc (BOOL) - returns
Message-processing indicator.
TRUE
Current thread is processing a message sent by another thread
FALSE
Current thread is not processing a message, or an error occurred.

Remarks

This function determines if the current thread is processing a message that originated from another thread. It can also indicate if a function is being called recursively.

If the message originates from another thread, this function helps determine if that message was initiated by the "active thread." The "active thread" is associated with the currently active window. (See also WinIsThreadActive).

Applications typically use this function to decide how to handle errors when the window processing the message is not the active window. For instance, if the active window uses WinSendMsg to request information from another window, the other window cannot become active until WinSendMsg returns. In such cases, an inactive window can inform the user of an error by creating a message box (see WinMessageBox) or flashing a window (see WinFlashWindow).

Example Code

#define INCL_WINMESSAGEMGR /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

HAB     hab;  /*  Anchor-block handle. */
BOOL    rc;   /*  Message-processing indicator. */

rc = WinInSendMsg(hab);

This example demonstrates how to use WinInSendMsg within a WM_ERROR message handler to display an error message box if the error originated from a message sent by another thread.

#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 */
        }

Related Functions