|
#ifndef _SUBCLASSW_H
#define _SUBCLASSW_H
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
/////////////////////////////////////////////////////////////////////////////
/****************************************************************************
*
* $Date: 10/26/99 10:50p $
* $Revision: 4 $
* $Archive: /CodeJock/Include/Subclass.h $
*
* $History: Subclass.h $
*
* ***************** Version 4 *****************
* User: Kirk Stowell Date: 10/26/99 Time: 10:50p
* Updated in $/CodeJock/Include
* Made class methods virtual for inheritance purposes.
*
* ***************** Version 3 *****************
* User: Kirk Stowell Date: 10/14/99 Time: 12:41p
* Updated in $/CodeJock/Include
* Added source control history to file header.
*
***************************************************************************/
/////////////////////////////////////////////////////////////////////////////
//////////////////
// Generic class to hook messages on behalf of a CWnd.
// Once hooked, all messages go to CSubclassWnd::WindowProc before going
// to the window. Specific subclasses can trap messages and do something.
//
// To use:
//
// * Derive a class from CSubclassWnd.
//
// * Override CSubclassWnd::WindowProc to handle messages. Make sure you call
// CSubclassWnd::WindowProc if you don't handle the message, or your
// window will never get messages. If you write seperate message handlers,
// you can call Default() to pass the message to the window.
//
// * Instantiate your derived class somewhere and call HookWindow(pWnd)
// to hook your window, AFTER it has been created.
// To unhook, call HookWindow(NULL).
//
// This is a very important class, crucial to many of the widgets Window
// widgets implemented in PixieLib. To see how it works, look at the HOOK
// sample program.
//
class _CJX_EXT_CLASS CSubclassWnd : public CObject {
public:
DECLARE_DYNAMIC(CSubclassWnd);
CSubclassWnd();
~CSubclassWnd();
// Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
virtual BOOL HookWindow(HWND hwnd);
virtual BOOL HookWindow(CWnd* pWnd) { return HookWindow(pWnd->GetSafeHwnd()); }
virtual BOOL IsHooked() { return m_hWnd!=NULL; }
friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
friend class CSubclassWndMap;
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
HWND m_hWnd; // the window hooked
WNDPROC m_pOldWndProc; // ..and original window proc
CSubclassWnd* m_pNext; // next in chain of hooks for this window
// Override this to handle messages in specific handlers
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
virtual LRESULT Default(); // call this at the end of handler fns
};
#endif // _SUBCLASSW_H
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing
Darth Vader's Codpiece * for the UK Army in 1990).
* Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for
Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company,
Riverblade Ltd.
One of my personal specialities is IDE plug-in development.
ResOrg was my first attempt at a plug-in, but my day to day work is with
Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.
I love lots of things, but particularly music, photography and anything connected with history or engineering. I
despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...
I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!