Click here to Skip to main content
15,892,059 members
Articles / Desktop Programming / MFC

Windows subclassing and hooking with C++ classes

Rate me:
Please Sign up or sign in to vote.
4.38/5 (24 votes)
9 Oct 2003CPOL10 min read 151.2K   3.8K   59  
This article put forwards a proposal for structured window subclassing and hooking
#pragma once

#include "smartptr.h"

namespace GE_{ namespace Utils{

	//istal a ForegroundIdleProc Hook and chain the instances.
	// when the hook is called, the OnIdle finctions are called in turn

	// handle always on the heap, using strong poiters

	class CHookIdle;
	typedef Safe::PtrStrong<CHookIdle> PHookIdle;

	class CHookIdle: public Safe::ObjStrong
	{
	private:
		LPVOID _token;
	protected:
		LRESULT Default();
		virtual LRESULT OnIdle(); //override this function. call Default as appropriate
	public:
		CHookIdle();
		virtual ~CHookIdle(void);
		static LRESULT Call(LPVOID token);
		bool Clear();
	};


}}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Italy Italy
Born and living in Milan (Italy), I'm an engineer in electronics actually working in the ICT department of an important oil/gas & energy company as responsible for planning and engineering of ICT infrastructures.
Interested in programming since the '70s, today I still define architectures for the ICT, deploying dedicated specific client application for engineering purposes, working with C++, MFC, STL, and recently also C# and D.

Comments and Discussions