Jump to content

WinSubclassWindow

From EDM2
Revision as of 16:39, 15 May 2025 by Martini (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function subclasses the indicated window by replacing its window procedure with another window procedure.

Syntax

WinSubclassWindow(hwnd, pNewWindowProc);

Parameters

hwnd (HWND) - input
Handle of window that is being subclassed.
pNewWindowProc (PFNWP) - input
New window procedure.
Window procedure used to subclass hwnd.

Returns

pOldWindowProc (PFNWP) - returns
Old window procedure.
Previous window procedure belonging to hwnd.
If this function fails, 0L is returned.

Errors

Possible returns from WinGetLastError

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

Remarks

To subclass a window effectively, the new window procedure calls the old window procedure rather than WinDefWindowProc, for those messages it does not process itself.

To reverse the effect of subclassing, call this function again using the old window procedure address.

Note
It is not possible to subclass a window created by another process.

Example Code

Declaration:

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

HWND     hwnd;            /* Handle of window that is being subclassed. */
PFNWP    pNewWindowProc;  /* New window procedure. */
PFNWP    pOldWindowProc;  /* Old window procedure. */

pOldWindowProc = WinSubclassWindow(hwnd, pNewWindowProc);

This example uses the WinSubclassWindow call to subclass the frame window procedure, so that frame-sizing restrictions can be implemented.

#define INCL_WINWINDOWMGR
#include <os2.h>

HAB hab;
PFNWP FrameWndProc, OldpFrame;
HWND hwndFrame;

OldpFrame = WinSubclassWindow(hwndFrame, (PFNWP)FrameWndProc);

MRESULT EXPENTRY FrameWndProc(hwnd, msg, mp1, mp2)
{
    switch(msg) {
        case /* ... */:
            /* ... */
            break;
        default:
            OldpFrame(hwnd, msg, mp1, mp2);
    }
}

Related Functions