Identifying the Destination Window

When passing messages between windows using the WinPostMsg() or WinSendMsg() functions, the window handle of the destination window must be known and specified in the message. If window handles are not defined globally, the required handle must be obtained from Presentation Manager. This may be achieved in a number of ways:

  • If the target window has a known relationship to the current window or to another window for which the handle is already known, the WinQueryWindow() function may be used to obtain the window handle of the target window. For example, if a window wishes to post a message to its own parent window, the technique shown in Figure "Obtaining a Window Handle - WinQueryWindow() Function" may be used.

    The WinQueryWindow() call returns the handle of the required window. Relationships other than parent/child may also be used by this function; the valid relationships are described, along with the WinQueryWindow() function, in the IBM OS/2 Version 2.0 Presentation Manager Reference.

  • If the parent window and window identifier of the target window are known, the WinWindowFromID() function may be used to obtain the window handle of the target window. For example, if a window wishes to post a message to the client window of its application's main window, assuming the frame window handle is known, the method shown in Figure "Obtaining a Window Handle - WinWindowFromID() Function" may be used.

    The WinWindowFromID() function also returns the handle of the required window.

  • If the target window is the application's main window, its handle may be obtained by first querying the application's switch entry in the Workplace Shell Window List to obtain the handle of the main frame window (using the WinQuerySwitchHandle() and WinQuerySwitchEntry() functions), then using the WinWindowFromID() function to obtain the handle of the client window, as shown in Figure "Obtaining a Window Handle Using the Switch Entry".

    The above example assumes that the application has been added to the OS/2 Window List using the WinAddSwitchEntry() function, and the handle of its main frame window supplied as a parameter. See Figure "WinAddSwitchEntry() Function".

    When passing messages synchronously to control windows using the WinSendDlgItemMsg() function, it is generally assumed that the target control window is a child of the current window or dialog box. Thus the parent window handle is the handle of the current window, and the window identifier is also known to the current window procedure. An exception is the case where a window procedure wishes to send a message to a frame control of its own parent frame window. In this case a WinQueryWindow() call must be issued with the QW_PARENT parameter to determine the handle of the frame window. The WinSendDlgItemMsg() function may then be used with this handle and the window identifier of the required frame control.


    [Back: Message Boxes]
    [Next: Creating Message Parameters]