Click here to Skip to main content
14,981,532 members
Articles / Desktop Programming / WTL
Posted 12 Oct 2007


82 bookmarked

MFC Docking Framework

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



Image 1


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>
    typedef TWTLCWindow WTLClass;
    WTLClass m_wndWTLPeer;

    virtual void PreSubclassWindow()
        m_wndWTLPeer.m_hWnd = m_hWnd;

    virtual LRESULT WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
        LRESULT lResult = 0;
        if(FALSE == m_wndWTLPeer.ProcessWindowMessage
            (m_hWnd, nMsg, wParam, lParam, lResult))
            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.

Image 2

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


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.


  • Oct 12, 2007: Initial version


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
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

GeneralMy vote of 2 Pin
Panic2k35-Dec-08 9:33
MemberPanic2k35-Dec-08 9:33 
Questionerror c2248 Pin
Member 428765931-Aug-08 19:07
MemberMember 428765931-Aug-08 19:07 
AnswerRe: error c2248 Pin
Quynh Nguyen31-Aug-08 23:21
MemberQuynh Nguyen31-Aug-08 23:21 
AnswerRe: error c2248 Pin
SM_Leon20-Jul-09 7:23
MemberSM_Leon20-Jul-09 7:23 
AnswerRe: error c2248 Pin
extremjoy30-Jun-10 16:56
Memberextremjoy30-Jun-10 16:56 
Questionneed help Pin
abc_nus_student23-Nov-07 0:09
Memberabc_nus_student23-Nov-07 0:09 
Generalunable to compile MDIDemo Pin
PetoG24-Oct-07 22:15
MemberPetoG24-Oct-07 22:15 
GeneralRe: unable to compile MDIDemo Pin
Quynh Nguyen25-Oct-07 1:58
MemberQuynh Nguyen25-Oct-07 1:58 
GeneralRe: unable to compile MDIDemo Pin
qiuyangsky23-Oct-08 3:17
Memberqiuyangsky23-Oct-08 3:17 
NewsRe: unable to compile MDIDemo Pin
Member 449228512-Aug-09 18:06
MemberMember 449228512-Aug-09 18:06 
GeneralRe: unable to compile MDIDemo Pin
Member 449228512-Aug-09 18:07
MemberMember 449228512-Aug-09 18:07 
Generalgood point Pin
code_discuss18-Oct-07 16:36
Membercode_discuss18-Oct-07 16:36 
QuestionRe: good point Pin
Quynh Nguyen19-Oct-07 6:37
MemberQuynh Nguyen19-Oct-07 6:37 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.