WinSetWindowPtr
Appearance
This function sets a pointer value into the memory of the reserved window words.
Syntax
WinSetWindowPtr(hwnd, lb, pp)
Parameters
- hwnd (HWND) - Input
- Window handle.
- lb (LONG) - Input
- Zero-based index into the window words.
- The units of b 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 as the index for the address of the window procedure for the window.
- pp (PVOID) - Input
- Pointer value to store in the window words.
Returns
- rc (BOOL) - returns
- TRUE Successful completion
- FALSE Error occurred.
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. */ LONG lb; /* Zero-based index into the window words. */ PVOID pp; /* Pointer value to store in the window words. */ BOOL rc; /* Success indicator. */ rc = WinSetWindowPtr(hwnd, lb, pp);
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; . .