Jump to content

WinPostMsg: Difference between revisions

From EDM2
No edit summary
No edit summary
 
Line 1: Line 1:
This function posts a message to the message queue associated with the window defined by hwnd.
This function posts a message to the message queue associated with the window defined by ''hwnd''.


==Syntax==
== Syntax ==
<pre>
WinPostMsg(hwnd, ulMsgid, mpParam1, mpParam2);
</pre>


==Example Code==
== 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:
Declaration:
<pre>
<pre>
Line 9: Line 33:
#include <os2.h>
#include <os2.h>


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


rc = WinPostMsg(hwnd, ulMsgid, mpParam1, mpParam2);
rc = WinPostMsg(hwnd, ulMsgid, mpParam1, mpParam2);
</pre>
</pre>


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).
<pre>
#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);
</pre>


[[Category:Win]]
== Related Functions ==
* [[WinBroadcastMsg]]
* [[WinCreateMsgQueue]]
* [[WinDestroyMsgQueue]]
* [[WinDispatchMsg]]
* [[WinGetDlgMsg]]
* [[WinGetMsg]]
* [[WinInSendMsg]]
* [[WinPeekMsg]]
* [[WinPostQueueMsg]]
* [[WinQueryMsgPos]]
* [[WinQueryMsgTime]]
* [[WinQueryQueueInfo]]
* [[WinQueryQueueStatus]]
* [[WinSendDlgItemMsg]]
* [[WinSendMsg]]
* [[WinSetClassMsgInterest]]
* [[WinSetMsgInterest]]
* [[WinSetMsgMode]]
* [[WinSetSynchroMode]]
* [[WinWaitMsg]]


== Related Messages ==
* [[QMSG]]
* [[MM_SETITEMATTR]]
* [[WM_MENUSELECT]]


[[Category:WorkToDo]]
[[Category:Win]]

Latest revision as of 16:02, 15 May 2025

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