Click here to Skip to main content
15,884,986 members
Articles / Desktop Programming / WTL

MFC Docking Framework

Rate me:
Please Sign up or sign in to vote.
4.37/5 (20 votes)
12 Oct 2007CPOL3 min read 123.1K   5.3K   84  
An easy to use MFC Docking framework and more... It also shows an applicable method to mix up WTL and MFC.
#pragma once

extern "C"
{
	HIMAGELIST WINAPI ImageList_Read(LPSTREAM pstm);
	BOOL       WINAPI ImageList_Write(HIMAGELIST himl, LPSTREAM pstm);
#if (_WIN32_WINNT >= 0x0501)
	HRESULT WINAPI ImageList_ReadEx(DWORD dwFlags, LPSTREAM pstm, REFIID riid, PVOID* ppv);
	HRESULT WINAPI ImageList_WriteEx(HIMAGELIST himl, DWORD dwFlags, LPSTREAM pstm);
#endif
};

#include <cassert>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
#include <memory>
#include <deque>
#include <sstream>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <utility>
#include <cmath>
#include <limits>
#include <iomanip>


#define _CSTRING_NS
#define _WTL_NO_AUTOMATIC_NAMESPACE
#define _WTL_NO_CSTRING
#pragma push_macro("CopyCursor")
#include <atlbase.h>
#include <atlapp.h>
#pragma pop_macro("CopyCursor")

extern CComModule _Module;

//DO NOT include these header files to avoid conflict between ATL & MFC
//#include <atlmisc.h>
//#include <atlstr.h>
#define _WTL_USE_CSTRING
#define __ATLMISC_H__
#define __ATLSTR_H__
typedef CString CAtlString;

#include <atlutil.h>
#include <atlcoll.h>
#include <atlwin.h>
#include <atlctrls.h>
#include <atlctrlx.h>
#include <atlcrack.h>
#include <atlframe.h>
#include <atlimage.h>
#include <atlsplit.h>

#if (_WIN32_WINNT >= 0x0501)
#	include <atltheme.h>
#endif

#define _BEGIN_WTL4MFC_NAMESPACE namespace WTL4MFC {
#define _END_WTL4MFC_NAMESPACE }

_BEGIN_WTL4MFC_NAMESPACE

template<class TMFCWnd, class TWTLCWindow>
class ATL_NO_VTABLE CWTL4MFCWndT : public TMFCWnd
{
public:
	typedef TWTLCWindow WTLClass;
	WTLClass m_wndWTLPeer;

	virtual void PreSubclassWindow()
	{
		m_wndWTLPeer.m_hWnd = m_hWnd;
		__super::PreSubclassWindow();
	}

	virtual void PostNcDestroy()
	{
		if(::GetActiveWindow() == m_wndWTLPeer.m_hWnd)
		{
			// Is this a bug of Windows, anyway let protect ourselves
			VERIFY(::SetActiveWindow(NULL));
		}
		m_wndWTLPeer.m_hWnd = NULL;
		__super::PostNcDestroy();
	}

	virtual LRESULT WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
	{
		LRESULT lResult = 0;
		if(FALSE == m_wndWTLPeer.ProcessWindowMessage(m_hWnd, nMsg, wParam, lParam, lResult))
		{
			ASSERT(::IsWindow(m_hWnd));
			lResult = TMFCWnd::WindowProc(nMsg, wParam, lParam);
		}
		return lResult;
	}

	__if_exists(TWTLCWindow::PreTranslateMessage) {
		virtual BOOL PreTranslateMessage(MSG* pMsg)
		{
			BOOL blRes1 = __super::PreTranslateMessage(pMsg);
			BOOL blRes2 = m_wndWTLPeer.PreTranslateMessage(pMsg);

			// if both WTL & MFC handle this message
			// there maybe a problem, consider to override this method in derived class
			ASSERT(FALSE == (blRes2 && blRes1));

			return (blRes1 | blRes2);
		}}
};

_END_WTL4MFC_NAMESPACE

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
Global Cybersoft (Vietnam)
Vietnam Vietnam
Quynh Nguyen is a Vietnamese who has worked for 7 years in Software Outsourcing area. Currently, he works for Global Cybersoft (Vietnam) Ltd. as a Project Manager in Factory Automation division.

In the first day learning C language in university, he had soon switched to Assembly language because he was not able to understand why people cannot get address of a constant as with a variable. With that stupid starting, he had spent a lot of his time with Assembly language during the time he was in university.

Now he is interesting in Software Development Process, Software Architecture and Design Pattern… He especially indulges in highly concurrent software.

Comments and Discussions