WinQueryWindowText
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);
Related Functions
- WinQueryDlgItemShort
- WinQueryDlgItemText
- WinQueryDlgItemTextLength
- WinQueryWindowTextLength
- WinSetDlgItemShort
- WinSetDlgItemText
- WinSetWindowText
Related Messages
- WM_QUERYWINDOWPARAMS