WinSubclassWindow: Difference between revisions
Appearance
Created page with "Subclassing Windows ==Syntax== WinSubclassWindow (btnHandle, winfunc) Category:Win" |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
This function subclasses the indicated window by replacing its window procedure with another window procedure. | |||
==Syntax== | == Syntax == | ||
WinSubclassWindow ( | |||
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: | |||
<PRE> | |||
#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); | |||
</PRE> | |||
This example uses the WinSubclassWindow call to subclass the frame window procedure, so that frame-sizing restrictions can be implemented. | |||
<pre> | |||
#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); | |||
} | |||
} | |||
</pre> | |||
== Related Functions == | |||
* [[WinCalcFrameRect]] | |||
* [[WinCreateFrameControls]] | |||
* [[WinCreateStdWindow]] | |||
* [[WinCreateWindow]] | |||
* [[WinDefWindowProc]] | |||
* [[WinDestroyWindow]] | |||
* [[WinQueryClassInfo]] | |||
* [[WinQueryClassName]] | |||
* [[WinRegisterClass]] | |||
[[Category:Win]] | [[Category:Win]] |
Latest revision as of 16:39, 15 May 2025
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); } }