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

 

 

 

Features

 

 

 

Usage

 

 

 

History

V1.0 (25th February 1999)

V1.01 (29th March 1999)

V1.02 (10th May 1999)

 

 

API Reference

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

 

CHookWnd::CHookWnd

BOOL CHookWnd::CHookWnd();

Remarks

Standard C++ constructor.

 

CHookWnd::~CHookWnd

CHookWnd::~CHookWnd();

Remarks

Standard C++ destructor.

 

CHookWnd::Hook

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

CHookWnd::UnHook

 

CHookWnd::UnHook

void CHookWnd::UnHook();

Remarks

Removes this instance from the chain of hooks which are handling the subclassing.

See Also

CHookWnd::Hook

 

CHookWnd::Default

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.

 

CHookWnd::WindowProc

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.

 

CHookWnd::IsHooked

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.

 

CHookWnd::FirstInChain

BOOL CHookWnd::FirstInChain() const;

Return Value

TRUE if this instance is the first in the chain of CHookWnd's handling subclassing otherwise FALSE.

 

CHookWnd::LastInChain

BOOL CHookWnd::LastInChain() const;

Return Value

TRUE if this instance is the last in the chain of CHookWnd's handling subclassing otherwise FALSE.

 

CHookWnd::MiddleOfChain

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.

 

CHookWnd::SizeOfHookChain

int CHookWnd::SizeOfHookChain() const;

Return Value

The number of CHookWnd's in the chain which is currently handling the subclassing.

 

 

 

PLANNED ENHANCEMENTS

 

 

 

CONTACTING THE AUTHOR

PJ Naughter
Email: pjn@indigo.ie
Web: http://indigo.ie/~pjn
10th May 1999