CHookWnd v1.08

Welcome to CHookWnd, a freeware MFC class to support sub classing 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 sub classing the window before MFC gets to it using a plug-in 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 (25 February 1999)

V1.01 (29 March 1999)

V1.02 (10 May 1999)

V1.03 (21 March 2003)

V1.04 (29 March 2003)

V1.05 (31 March 2003)

V1.06 (2 April 2003)

V1.07 (17 April 2003)

V1.08 (1 November 2004)

 

 

 

API Reference

The API consists of the following member functions of the class CHookWnd

CHookWnd::CHookWnd
CHookWnd::~CHookWnd
CHookWnd::Subclass
CHookWnd::Unsubclass
CHookWnd::ProcessWindowMessage
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::Subclass

BOOL CHookWnd::Subclass(CWnd* pWnd);

BOOL CHookWnd::Subclass(HWND hWnd);

Parameters

pWnd The CWnd instance which you want to subclass.

hWnd The HWND which you want to subclass

Remarks

Call this member function to subclass the HWND currently sub classed 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::Unsubclass

HWND CHookWnd::Unsubclass();

Remarks

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

See Also

CHookWnd::Hook

 

CHookWnd::ProcessWindowMessage

virtual BOOL ProcessWindowMessage(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult);

Return Value

TRUE if the message was handled otherwise FALSE.

Parameters

hWnd   Specifies the HWND the message is for

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

lResult The return value from the window procedure if handled

Remarks

This is the function which you should override in your derived class to implement your plug-in 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 sub classing otherwise FALSE.

 

CHookWnd::LastInChain

BOOL CHookWnd::LastInChain() const;

Return Value

TRUE if this instance is the last in the chain of CHookWnd's handling sub classing 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 sub classing.

 

 

 

PLANNED ENHANCEMENTS

 

 

 

CONTACTING THE AUTHOR

PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
1 November 2004