Jump to content

WinPostMsg

From EDM2
Revision as of 16:02, 15 May 2025 by Martini (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function posts a message to the message queue associated with the window defined by hwnd.

Syntax

WinPostMsg(hwnd, ulMsgid, mpParam1, mpParam2);

Parameters

hwnd (HWND) - input
Window handle.
NULL: The message is posted into the queue associated with the current thread. When the message is received by using the WinGetMsg or WinPeekMsg functions, the parameter of the QMSG structure is NULL.
Other: Window handle.
ulMsgid (ULONG) - input
Message identity.
mpParam1 (MPARAM) - input
Parameter 1.
mpParam2 (MPARAM) - input
Parameter 2.

Returns

rc (BOOL) - returns
Message-posted indicator.
TRUE: Message successfully posted.
FALSE: Message could not be posted; for example, because the message queue was full.

Errors

Possible returns from WinGetLastError

PMERR_INVALID_HWND (0x1001)
An invalid window handle was specified.

Example Code

Declaration:

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

HWND      hwnd;      /*  Window handle. */
ULONG    ulMsgid;   /*  Message identity. */
MPARAM   mpParam1;  /*  Parameter 1. */
MPARAM   mpParam2;  /*  Parameter 2. */
BOOL      rc;        /*  Message-posted indicator. */

rc = WinPostMsg(hwnd, ulMsgid, mpParam1, mpParam2);

This example posts a Set menu item checked attribute message (MM_SETITEMATTR) to the message queue associated with the window handle in response to a menu select message (WM_MENUSELECT).

#define INCL_WINMESSAGEMGR      /* Window Message Functions     */
#define INCL_WINMENUS           /* Window Menu Functions        */
#include <os2.h>

BOOL    fResult;        /* message-posted indicator             */
ULONG   ulMsgid;        /* message id                           */
MPARAM  mp1;            /* Parameter 1 (rectl structure)        */
MPARAM  mp2;            /* Parameter 2 (frame boolean)          */
USHORT  usItemId;       /* menu item id                         */
HWND    hwndMenu;       /* menu handle                          */

case WM_MENUSELECT:
     usItemId = SHORT1FROMMP(mp1);
     hwndMenu = HWNDFROMMP(mp2);

     /* initialize message id, parameters */
     ulMsgid = MM_SETITEMATTR;
     mp1 = MPFROM2SHORT(usItemId, TRUE);
     mp2 = MPFROM2SHORT(MIA_CHECKED, TRUE);

     fResult = WinPostMsg(hwndMenu, ulMsgid, mp1, mp2);

Related Functions

Related Messages