Jump to content

WinQueryWindowPtr

From EDM2

This function retrieves a pointer value from the memory of the reserved window word.

Syntax

WinQueryWindowPtr(hwnd, index)

Parameters

hwnd (HWND) - Input
Window handle which has the pointer to retrieve.
index (LONG) - Input
Zero-based index of the pointer value to retrieve.
The units of index are bytes. Valid values are zero through (cbWindowData - 4), where cbWindowData is the parameter in WinRegisterClass that specifies the number of bytes available for application-defined storage.
The value QWP_PFNWP can be used for the address of the window's window procedure.

Returns

pRet (PVOID) - returns
NULL Error occurred.
Other Pointer value.

Parameters

hwnd (HWND) - Input
Window handle which has the pointer to retrieve.
index (LONG) - Input
Zero-based index of the pointer value to retrieve.
The units of index are bytes. Valid values are zero through (cbWindowData - 4), where cbWindowData is the parameter in WinRegisterClass that specifies the number of bytes available for application-defined storage.
The value QWP_PFNWP can be used for the address of the window's window procedure.
pRet (PVOID) - returns
NULL Error occurred.
Other Pointer value.

Remarks

The index parameter is valid only if all of the bytes referenced are within the reserved memory.

Errors

Possible returns from WinGetLastError:

  • PMERR_INVALID_HWND (0x1001) An invalid window handle was specified.
  • PMERR_PARAMETER_OUT_OF_RANGE (0x1003) The value of a parameter was not within the defined valid range for that parameter.

Example Code

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

HWND     hwnd;   /*  Window handle which has the pointer to retrieve. */
LONG     index;  /*  Zero-based index of the pointer value to retrieve. */
PVOID    pRet;   /*  Pointer value. */

pRet = WinQueryWindowPtr(hwnd, index);

This function retrieves a pointer value from the memory of the reserved window word.

MyWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
MYINSTANCEDATA *InstanceData;  /* application defined structure */

    switch (msg) {
    case WM_CREATE:
        DosAllocMem(&InstanceData, sizeof(MYINSTANCEDATA), fALLOC);
        /* WindowProcedure initializes instance data for this window */
        .
        .
        /* set pointer to instance in window words */
        WinSetWindowPtr(hwnd, 0, InstanceData);
        break;

    case WM_USER + 1: /* application defined message */
        /* Window procedure retrieves instance data to   */
        /* process this message                        */

        InstanceData = WinQueryWindowPtr(hwnd, 0);
        .
        .

        break;
        .
        .

Related Functions