WinSendMsg

From EDM2
Jump to: navigation, search

This function sends a message with identity ulMsgid to hwnd, passing mpParam1 and mpParam2 as the parameters to the window.

Syntax

WinSendMsg(hwnd, ulMsgid, mpParam1, mpParam2);

Parameters

hwnd (HWND) - input
Window handle.
ulMsgid (ULONG) - input
Message identity.
mpParam1 (MPARAM) - input
Parameter 1.
mpParam2 (MPARAM) - input
Parameter 2.

Returns

mresReply (MRESULT) - returns
Message-return data.

Errors

Possible returns from WinGetLastError

PMERR_INVALID_HWND (0x1001)
An invalid window handle was specified.
PMERR_WINDOW_NOT_LOCKED (0x1007)
The window specified in WinSendMsg was not locked.

Remarks

mresReply is the value returned by the window procedure that is invoked. For standard window classes, the values of mresReply are documented with the message definitions.

This function does not complete until the message has been processed by the window procedure whose return value is returned in mresReply.

If the window receiving the message belongs to the same thread, the window function is called immediately as a subroutine. If the window is of another thread or process, the operating system switches to the appropriate thread that enters the necessary window procedure recursively. The message is not placed in the queue of the destination thread.

If a message is sent from one process to another and the message contains a pointer, the receiving process may not have read/write access to the memory referenced by the pointer. If the receiving process is expected to update that memory, this must be done using shared memory. For more information about Dynamic Data Exchange (DDE) and shared memory, see "Dynamic Data Exchange" section of the Presentation Manager Programming Guide - Advanced Topics.

Sample Code

#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. */
MRESULT    mresReply;  /*  Message-return data. */

mresReply = WinSendMsg(hwnd, ulMsgid, mpParam1,
              mpParam2);

This example gets the window handle of the system menu and calls WinSendMsg to send a message to disable the Close menu item.

#define INCL_WINMENUS
#define INCL_WINMESSAGEMGR
#define INCL_WINFRAMEMGR
#include <OS2.H>
HWND hwndDlg;
HWND hwndSysMenu;

 hwndSysMenu = WinWindowFromID(hwndDlg, FID_SYSMENU);
 WinSendMsg(hwndSysMenu, MM_SETITEMATTR,
     MPFROM2SHORT(SC_CLOSE, TRUE),
     MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));

Related Functions

  • WinBroadcastMsg
  • WinCreateMsgQueue
  • WinDestroyMsgQueue
  • WinDispatchMsg
  • WinGetDlgMsg
  • WinGetMsg
  • WinInSendMsg
  • WinPeekMsg
  • WinPostMsg
  • WinPostQueueMsg
  • WinQueryMsgPos
  • WinQueryMsgTime
  • WinQueryQueueInfo
  • WinQueryQueueStatus
  • WinSendDlgItemMsg
  • WinSendMsg
  • WinSetClassMsgInterest
  • WinSetMsgInterest
  • WinSetMsgMode
  • WinSetSynchroMode
  • WinWaitMsg