Jump to content

WinQueryWindowText

From EDM2
Revision as of 21:04, 6 August 2023 by Martini (talk | contribs) (Created page with "This function copies window text into a buffer. ==Syntax== WinQueryWindowText(hwnd, lLength, pun); ==Parameters== ;hwnd (HWND) - input :Window handle. :If hwnd is a frame-w...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function copies window text into a buffer.

Syntax

WinQueryWindowText(hwnd, lLength, pun);

Parameters

hwnd (HWND) - input
Window handle.
If hwnd is a frame-window handle, the title-bar window text is copied.
lLength (LONG) - input
Length of pun.
It must be greater than 0.
pun (PUN) - output
Window text.


Returns

lRetLen (LONG) - returns
Length of returned text not including the null terminator.

Errors

Possible returns from WinGetLastError

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

Remarks

If the window text is longer than (lLength-1) only the first (lLength-1) characters of window text are copied.

If the window is the frame window, the title bar window text is copied.

This function sends a WM_QUERYWINDOWPARAMS message to hwnd.

If this function references the window of another process, pun must be in memory that is shared by both processes, otherwise a memory fault can occur.

Note: Extreme caution must be used if this function is used to access an object window (that is, a window that is descended from HWND_OBJECT). This is because it is very possible that the thread that owns the object window might not be processing it's message queue, and if this is the case, a system halt could occur.

Example Code

This example shows how to query window text.

#define INCL_WINWINDOWMGR
#include <OS2.H>
#define FID_CLIENT 255

HWND hwndFrame;
HWND hwndClient;
char szTitle[32];

/* This function creates a new window of    */
/* class Generic and returns hwnd.          */

hwndClient = WinCreateWindow(hwndFrame,
                             "Generic",
                            (PSZ)"My Window", /* No window text     */
                            0UL,              /* No window style    */
                            0,0,0,0,          /* Position and size  */
                            (HWND)NULL,       /* No owner           */
                            HWND_TOP,         /* On top of siblings */
                            FID_CLIENT,       /* Client window ID   */
                            NULL,             /* Control data       */
                            NULL);            /* Pres. params       */

WinQueryWindowText(hwndFrame, sizeof(szTitle), szTitle);


Definition

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

HWND    hwnd;     /*  Window handle. */
LONG    lLength;  /*  Length of pun. */
PUN     pun;      /*  Window text. */
LONG    lRetLen;  /*  Length of returned text not including the null terminator. */

lRetLen = WinQueryWindowText(hwnd, lLength,
            pun);

Related Functions

Related Messages

  • WM_QUERYWINDOWPARAMS