Click here to Skip to main content
Click here to Skip to main content

MFC Docking Framework

By , 12 Oct 2007
 

Index

Screenshot

Introduction

A nice user interface is an important part of a good application besides other criteria like performance, stability/reliability... Personally, I really like following libraries which were published on CodeProject long time ago.

These listed libraries are written in WTL. But it's really hard to mix both MFC & WTL together. Obviously, it's not reasonable to ask a developer or a team to giving up MFC and move to the WTL world just because there were some great controls or visual Frameworks written in WTL (there are many things that should be considered especially in a company with hundreds of developers like the company I work for). Unfortunately, there was no such good and free visual Framework in MFC until now. Whatever difficulties there are, I still desire to be able to use them and now my effort is here to be shared with you.

Under the Hood

Technical Decision

There are two possible approaches:

  1. Porting WTL source code to MFC completely: There are some problems with this approach. First, it will take me a lot of time (just to re-write what people did). Second, bug-fixing and enhancement from the original authors will not be up to date. Third, I have to port again if another good WTL-targeted library is published one day. With such reasons in mind, I decide not to follow this direction.
  2. Mixing MFC & WTL together. I know there are a lot of problems with this approach as shown in the forum of the article Mix up WTL with MFC. Since I don't have an ambition to have a generic way to integrate all WTL-targeted libraries (now and in the future) but just for these above ones, I believe it's possible.

How Does it Work?

Here is the core of the MFC wrapper:

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 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);
    }}
};

Not much to say; for each window message (WM_xxx), if the corresponding WTL peer doesn't handle it, the MFC wrapper will.

Potential Problems

Problems occur when a window message (WM_xxx) is handled by the WTL peer (return TRUE from ProcessWindowMessage) but the message is also important for the MFC framework. To resolve this problem, I choose a very simple approach: do testing and workaround case by case.

Using the Code

Applying this library into an existing MFC project is easy; let's take the demo project as your starting point. Here is the class diagram for quick reference.

Supported Compilers

Bug Fix and Update

  • Basically, a bug or a request for more features may belong to this MFC wrapper (1) or the original WTL code (2) or both (3). I will try fixing bugs that belong to category (1) and (3) and forward others to the corresponding authors (I will try not to touch WTL code as much as possible unless it's really necessary and of course with consent from original authors)
  • Since this library is just a wrapper, please remember to get updates from other authors and the WTL Library too

Acknowledgements

I'd like to thank Daniel Bowen, Sergey Klimov and Igor Katrayev for their excellent WTL-targeted libraries. Thanks also for their consent to allow me to redistribute their source code (with a little modification) in this article.

History

  • Oct 12, 2007: Initial version

License

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

About the Author

Quynh Nguyen
Global Cybersoft (Vietnam)
Vietnam Vietnam
Member
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberPanic2k35 Dec '08 - 9:33 
Badly named article (should refer the use of WTL), and the article itself attempts to expalin the mixing of WTL to MFC not the proposed Docking framework...
Questionerror c2248memberMember 428765931 Aug '08 - 19:07 
not support??
 

 

d:\mfcdockingframework_20071012\dockingframework\dockingframework.cpp(60) : error C2248: 'WTL::dockwins::CDockingWindowBaseImpl<T,TBase,TWinTraits>::CDocker' : cannot access private typedef declared in class 'WTL::dockwins::CDockingWindowBaseImpl<T,TBase,TWinTraits>'
 
z

AnswerRe: error c2248memberQuynh Nguyen31 Aug '08 - 23:21 
Which is the C++ compiler you are using?
AnswerRe: error c2248memberSM_Leon20 Jul '09 - 7:23 
this error also occured when I tryed to compile MFC Docking Framework code using visual stdio 2008, so how to resolve this problem??
AnswerRe: error c2248memberextremjoy30 Jun '10 - 16:56 
you can add "public:" in dockingwindow.h like this:
 
public:
typedef CWindowImpl< T, TBase, TWinTraits > baseClass;
typedef CDockingWindowBaseImpl< T, TBase, TWinTraits > thisClass;
typedef typename TWinTraits::CDocker CDocker;
Questionneed helpmemberabc_nus_student23 Nov '07 - 0:09 
Hi,
Need some help.
Does anyone know how to do the following
 
1. Collect all the messages the Microsoft OS provides in order to draw buttons or menus etc on an application screen (say for Microsoft word)
 
2. Take the above messages and put them into another custom-made application window after mapping the window handles, so that you recreate the exact same application on a different application window.
 
Thanks!
aBC
Generalunable to compile MDIDemomemberPetoG24 Oct '07 - 22:15 
Hi,
 
I am not able to compile MDIDemo project in VS 2003. I got:
 
c:\work\Codeproject\Dockable windows\Docking framework\DockingFramework\WTL4MFC.h(36): fatal error C1083: Cannot open include file: 'atlapp.h': No such file or directory
 
What to do?
 
Peter
GeneralRe: unable to compile MDIDemomemberQuynh Nguyen25 Oct '07 - 1:58 
We need WTL to compile the demo, get it here http://sourceforge.net/projects/wtl/[^]
GeneralRe: unable to compile MDIDemomemberqiuyangsky23 Oct '08 - 3:17 
I have included the WTL into the project,but I can not compile it for the following reason:
"fata error : can not open include file "sal.h""
what I should do?
Thank you! Smile | :)
NewsRe: unable to compile MDIDemomemberMember 449228512 Aug '09 - 18:06 
fata error C1083 : can not open include file

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 12 Oct 2007
Article Copyright 2007 by Quynh Nguyen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid