CHookWnd
v1.02
Welcome to CHookWnd, a freeware MFC class to support subclassing of any CWnd instance. The problem it fixes is that you cannot have 2 CWnd instances attached to the one HWND at the same time. This becomes a problem when you want to derive one of your classes from 2 base classes which are both derived from CWnd themselves. An example is, suppose you have 2 classes namely CBitmapMenuFrameWnd which is derived from CFrameWnd and implements bitmap menus ALA Office 97 and CReBarFrameWnd which implements command bar menus ALA IE4. When you are implementing your own CMainFrame class you then have the problem that you can only derive from one of these classes and you must copy the source from the other one into your class.
This class fixes this problem by subclassing the window before MFC gets to it using a plugin method. The code is based in part on a class developed by Paul DiLascia namely "CSubclassWnd" for the MSJ magazine.
Features |
Usage |
History |
API Reference |
Planned Enhancements |
Contacting the Author |
V1.0 (25th February 1999)
V1.01 (29th March 1999)
V1.02 (10th May 1999)
The API consists of the following member functions of the class CHookWnd
CHookWnd::CHookWnd
CHookWnd::~CHookWnd
CHookWnd::Hook
CHookWnd::UnHook
CHookWnd::Default
CHookWnd::WindowProc
CHookWnd::IsHooked
CHookWnd::FirstInChain
CHookWnd::LastInChain
CHookWnd::MiddleOfChain
CHookWnd::SizeOfHookChain
BOOL CHookWnd::CHookWnd();
Remarks
Standard C++ constructor.
CHookWnd::~CHookWnd();
Remarks
Standard C++ destructor.
void CHookWnd::Hook(CWnd* pWnd);
Parameters
pWnd The CWnd instance which you want to subclass.
Remarks
Call this member function to subclass the HWND currently subclassed by the MFC CWnd instance "pWnd". Messages will be routed to the WindowProc method of this instance prior to being passed of to any other installed CHookWnd's in the chain before eventually being routed back to standard MFC message maps..
See Also
void CHookWnd::UnHook();
Remarks
Removes this instance from the chain of hooks which are handling the subclassing.
See Also
LRESULT CHookWnd::Default();
Return Value
The standard LRESULT which window procedures return. The actual value will depend on the message sent.
Remarks
You can call this function in your derived WindowProc if you want to continue routing of the message. This will pass the message on to any other CHookWnd's in the chain and eventually back to MFC and your message maps.
virtual LRESULT CHookWnd::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam);
Return Value
The standard LRESULT which window procedures return. The actual value will depend on the message sent.
Parameters
nMsg Specifies the Windows message to be processed.
wParam Provides additional information used in processing the message. The parameter value depends on the message.
lParam Provides additional information used in processing the message. The parameter value depends on the message
Remarks
This is the function which you should override in your derived class to implement your plugin functionality. This would appear structured very similar to an SDK window proc. For any messages which you do not handle, you should call Default for these.
BOOL CHookWnd::IsHooked() const;
Return Value
TRUE if this instance is currently hooking a CWnd otherwise FALSE.
Remarks
This function is used internally in CHookWnd as an assert in functions where you first should have call Hook.
BOOL CHookWnd::FirstInChain() const;
Return Value
TRUE if this instance is the first in the chain of CHookWnd's handling subclassing otherwise FALSE.
BOOL CHookWnd::LastInChain() const;
Return Value
TRUE if this instance is the last in the chain of CHookWnd's handling subclassing otherwise FALSE.
BOOL CHookWnd::MiddleOfChain() const;
Return Value
TRUE if this instance is the somewhere in the chain but is not the first or last item in it.
int CHookWnd::SizeOfHookChain() const;
Return Value
The number of CHookWnd's in the chain which is currently handling the subclassing.
PJ Naughter
Email: pjn@indigo.ie
Web: http://indigo.ie/~pjn
10th May 1999