Click here to Skip to main content
14,209,015 members
Click here to Skip to main content
Posted 6 Feb 2002


211 bookmarked

WTL Docking Windows

Rate this:
4.89 (73 votes)
Please Sign up or sign in to vote.
4.89 (73 votes)
21 Nov 2007        
This is an implementation of docking windows for the WTL library

Sample Image - WTLDockingWindows1.png


This is an implementation of docking windows for the WTL library. The following topics describe how to use docking window classes.

Pre-Build Set-Up.

  • Make sure all header files are placed in the appropriate location and compiler can reach it.
  • Add DockImpl.cpp to the project. Probably the best way to do it is to add #include<span class="code-keyword"><DockImpl.cpp></span> to the stdafx.cpp.
  • Docking Windows use STL so it's requires to enable exception handling (/GX or /EH compiler options) and remove _ATL_MIN_CRT from the list the preprocessor defines in release configuration. If you use standard HP's STL you can leave default project setting intact, but I don't think it is a good idea.
  • If you use boost library define USE_BOOST.
  • I use some private message in range WM_USER to WM_USER + 2
    So if you define your own private messages please use WMDF_LAST+1 or if it is impossible redefine WMDF_FIRST.

Add to Main Frame Support for Docking Window Features

  • Create a new project with ATL/WTL AppWizard (MDI or SDI as you like)
  • Add #include <span class="code-keyword"><DockingFrame.h></span> to CMainFrame header.
  • Change the base of your CMainFrame class to dockwins::CDockingFrameImpl<CMainFrame> for SDI applications or to dockwins::CMDIDockingFrameImpl<CMainFrame> for MDI applications. All references to previous base class should be replaced by new one.
  • Add to the OnCreate method of your CMainFrame class InitializeDockingFrame(); it's the best place to change windows behavior of docking window. By default it is depend on system setting (Show window contents while dragging) if you for some reason need to change it you should use the following flags:
    CDockingBarStyle::sUseSysSettings — depend on system setting, default.
    CDockingBarStyle::sIgnoreSysSettings | CDockingBarStyle::sFullDrag — full drag
    CDockingBarStyle::sIgnoreSysSettings | CDockingBarStyle::sGhostDrag — ghost drag.
    If you use auto-hiding features you also can use the following flags:
    CDockingBarStyle::sAnimation — animate auto-hiding windows.
    CDockingBarStyle::sNoAnimation — do not animate auto-hiding windows.

Implement a Docking Window

  • Add #include <span class="code-keyword"><ExtDockingWindow.h></span> to header file of your docking window.
  • Create new class CSampleDockingWindow for example. Derive it from dockwins::CTitleDockingWindowImpl.
  • Add message map and DECLARE_WND_CLASS macro The CSampleDockingWindow class should look like this:
    class CSampleDockingWindow :
             public dockwins::CTitleDockingWindowImpl< SampleDockingWindow,
                    CWindow, dockwins::COutlookLikeTitleDockingWindowTraits >
            typedef CSampleDockingWindow    thisClass;
            typedef dockwins::CTitleDockingWindowImpl<CSAMPLEDOCKINGWINDOW,
             dockwins::COutlookLikeTitleDockingWindowTraits>  baseClass;
  • Instantiate an object of the CSampleDockingWindow class as a member of the CMainFrame
  • In the CMainFrame::OnCreate(...) method, call the Create(...) method of the instantiated docking window class.
    LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)
            CRect rcBar(0,0,100,100);
            m_sampleDockWnd.Create(m_hWnd,rcBar,_T("Sample docking window"));

    Do not use empty rect even if you dock the window. When window start dragging it use previously stored floating rect size.

Add to Generic Window Support for Docking Window Features

To implement a window with docking window features, derive a class from dockwins::CDockingSiteImpl. In derived class chain default message map to the base class.

class CDockSiteSampleWnd : public dockwins::CDockingSiteImpl < 
        CDockSiteSampleWnd >
        typedef dockwins::CDockingSiteImpl < CDockSiteSampleWnd > baseClass;

Add Support for Tabbed Docking Window

  • The tabbed docking window depend on Daniel Bowen's The Codeproject article "Custom Tab Controls,Tabbed Frame and Tabbed MDI", Please download the source code for this article.
  • Change the base class of your docking window from dockwins::CTitleDockingWindowImpl to dockwins::CBoxedDockingWindowImpl.
  • Use the following classes as traits for the dockwins::CBoxedDockingWindowImpl: COutlookLikeBoxedDockingWindowTraits, COutlookLikeExBoxedDockingWindowTraits or CVC6LikeBoxedDockingWindowTraits.
  • To add tabbed docking features support to the previous CSampleDockingWindow class, the code should look like this:
    class CSampleTabDockingWindow :
             public dockwins::CBoxedDockingWindowImpl< SampleDockingWindow,
                    CWindow, dockwins::COutlookLikeBoxedDockingWindowTraits >
            typedef CSampleTabDockingWindow    thisClass;
            typedef dockwins::CBoxedDockingWindowImpl<CSAMPLEDOCKINGWINDOW,
             dockwins::COutlookLikeBoxedDockingWindowTraits>  baseClass;

Add Support for Auto-Hiding Features

To add auto-hiding features to your project just include a DWAutoHide.h header before any other docking windows headers.

Dock a Docking Window

Call the DockWindow methods from your frame window class.

template<class T>
bool DockWindow(T& dockWnd,CDockingSide side,
                unsigned long nBar,float fPctPos,
                unsigned long nWidth, unsigned long nHeight);
Docking window.
Sides of the frame window to dock to
CDockingSide::sSingle force docking window to occupy the fulll width of the docking bar, combine this style with one of the following:
CDockingSide::sRight Dock to the right side of the frame window.
CDockingSide::sLeft Dock to the left side of the frame window.
CDockingSide::sTop Dock to the top side of the frame window.
CDockingSide::sBottom Dock to the bottom side of the frame window.
Index of dockbar to dock to, it's zero-based.
The percent of the dock bar's width that the docking window should use as top point.
The requested width (in pixels) of the docking window. If the docking window is vertical, this parameter actually represents the control bar height.
The requested height (in pixels) of the docking window. If the docking window is vertical, this parameter actually represents the control bar width.

Dock One Tabbed Docking Window to Another

Call the DockTo method of the tabbed docking window.

bool DockTo(HWND hWnd,int index=0);
Tabbed docking window to dock to.
Zero-based index.

Float a Docking Window that is Docked

Call the Float methods from your docking window class.

bool Float() - restore previous floating position
bool Float(LPCRECT pRc, <br />UINT flags=SWP_SHOWWINDOW | SWP_NOACTIVATE,<br />HWND hWndInsertAfter=HWND_TOP) - float docking window and move to a specified location.

Pin-up Docking Window

Call the one of the PinUp methods of the tabbed docking window.

bool PinUp(const CDockingSide& side);
bool PinUp(const CDockingSide& side, unsigned long width, 
    bool bVisualize=false);
Sides of the frame window to pin-up to:
CDockingSide::sRight Pin-up to the right side of the frame window.
CDockingSide::sLeft Pin-up to the left side of the frame window.
CDockingSide::sTop Pin-up to the top side of the frame window.
CDockingSide::sBottom Pin-up to the bottom side of the frame window.
The requested width (in pixels) of the docking window.
Specifies the show state of the docking window after pinning.

Unpin Pinned Docking Window

Call Hide then Show methods of the pinned window to emulate the pin button press,
or call Float method to float a pinned docking window,
or call Hide method then call any functions that set docking window position.

Receive Notifications when the Docked State of a Docking Window Changes

Override the following member functions of your docking window class

void OnDocked(HDOCKBAR hBar,bool bHorizontal)
void OnUndocked(HDOCKBAR hBar)
Handle to the dockbar to docking to.
Docking window orientation.

Hide/Show a Docking Window

To hide/show a docking window simply call Hide()/ Show() or Togle() methods of the CTitleDockingWindowImpl class.

Specify Minimum Docking Window Size

You can specify minimum docking window size by overriding GetMinMaxInfo method of your docking window, like this:

void GetMinMaxInfo(LPMINMAXINFO pMinMaxInfo) const

Preserve Docking Window Position

You can use following member functions of the CDockingWindowBaseImpl class:

bool GetDockingWindowPlacement(DFDOCKPOSEX* pHdr) const
bool SetDockingWindowPlacement(DFDOCKPOSEX* pHdr)

Replace Splitter Bar

If you do not like splitter bar you can make your own. If you just want to change it's appearance probably the best way to derive it from CSimpleSplitterBar. And override Draw(),DrawGhostBar() etc. Then define your traits

typedef CDockingFrameTraitsT <CMySplitterBar,
                WS_EX_APPWINDOW | WS_EX_WINDOWEDGE>  CMyDockingFrameTraits;
and apply it to base class of CMainFrame.

Make Custom Caption

Create a new caption class. You can derive it from CCaptionBase or from other available Caption classes. Then define DockingWindowTraits

typedef CDockingWindowTraits<CMyCaption,
                       WS_OVERLAPPEDWINDOW | WS_POPUP | WS_VISIBLE |
                       WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
                       WS_EX_TOOLWINDOW> CMyTitleDockingWindowTraits;

and apply it to CTitleDockingWindowImpl.

Docking Window Classes

Docking Windows Frame Classes

CDockingFrameImplBase[DockingFrame.h] — this class provides basic docking window features.
CDockingFrameImpl [DockingFrame.h] — base class for a single document interface (SDI) frame window.
CMDIDockingFrameImpl [DockingFrame.h] — base class for a multiple document interface (MDI) frame window.
CDockingSiteImpl [DockingFrame.h] — base class for a generic window with docking window features.
CDockingFrameTraitsT [DockMisc.h] — traits of docking frame it's derived from CWinTraits class and add TSplitterBar parameter.

Docking Windows Classes

CDockingWindowBaseImpl [DockingWindow.h] — base class for docking windows. The CDockingWindowBaseImpl class derives from CWindowImpl and has the same parameters except TWinTraits. Instead, it is uses CDockingWindowTraits.
CTitleDockingWindowImpl [DockingWindow.h] — titled docking window.
CBoxedDockingWindowImpl [DockingBox.h] — titled docking window which support tabbed docking.
CDockingWindowTraits [DockingWindow.h] — traits of docking window it's derived from CWinTraits class and add TCaption parameter. If you need to customize the docking window caption, make new caption class and use CDockingWindowTraits with new class as TCaption parameter.

Docking Windows Captions Classes

CCaptionBase[DockingWindow.h] — base class for other caption class
COutlookLikeExCaption and COutlookLikeCaption [ExtDockingWindow.h] — Microsoft Outlook™ likes caption.
COutlookLikeCaption — always horizontal caption.
COutlookLikeExCaption — orientation of the caption depends on docking position.
CVC6LikeCaption [ExtDockingWindow.h] — Microsoft Visual C++ 6™ IDE like caption.

Docking Windows Traits Classes

COutlookLikeTitleDockingWindowTraits [ExtDockingWindow.h] traits for COutlookLikeCaption, use this class with CTitleDockingWindowImpl
COutlookLikeExTitleDockingWindowTraits [ExtDockingWindow.h] traits for COutlookLikeExCaption, use this class with CTitleDockingWindowImpl
CVC6LikeTitleDockingWindowTraits [ExtDockingWindow.h] traits forCVC6LikeCaption, use this class with CTitleDockingWindowImpl
COutlookLikeBoxedDockingWindowTraits [TabDockingBox.h] traits for COutlookLikeCaption, use this class with CBoxedDockingWindowImpl
COutlookLikeExBoxedDockingWindowTraits [TabDockingBox.h] traits for COutlookLikeExCaption, use this class with CBoxedDockingWindowImpl
CVC6LikeBoxedDockingWindowTraits[TabDockingBox.h] traits for CVC6LikeCaption, use this class with CBoxedDockingWindowImpl

Docking Windows Splitter Bar Classes

CSimpleSplitterBar[SimpleSplitterBar.h] - Very simple splitter bar.
CSimpleSplitterBarEx[SimpleSplitterBar.h] - another simple splitter bar.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Serge Klimov
Software Developer
Ireland Ireland
No Biography provided

Comments and Discussions

GeneralRe: VC 7 and .NET Pin
Soliant22-Aug-03 14:25
memberSoliant22-Aug-03 14:25 
GeneralDocking MDI Children Pin
bzBetty13-Aug-03 19:45
memberbzBetty13-Aug-03 19:45 
GeneralDocking the other way :P Pin
Kronuz22-Jul-03 15:52
memberKronuz22-Jul-03 15:52 
GeneralRe: Docking the other way :P Pin
Kronuz7-Nov-03 9:34
memberKronuz7-Nov-03 9:34 
GeneralCannot work with VS.NET 2003 Pin
Aoong7-Jun-03 3:52
memberAoong7-Jun-03 3:52 
GeneralRe: Cannot work with VS.NET 2003 Pin
Anonymous7-Jun-03 6:15
memberAnonymous7-Jun-03 6:15 
GeneralRe: Cannot work with VS.NET 2003 Pin
Aoong7-Jun-03 16:51
memberAoong7-Jun-03 16:51 
GeneralThis is fantastic (just a few bugs) Pin
Simon Steele10-May-03 10:18
memberSimon Steele10-May-03 10:18 

Thanks very much for this fantastic set of classes. I have noticed a couple of small (but irritating) problems:

1) When you call Hide on a docked docking window the whole application loses focus. I have fixed this (with a kludge) by overriding Hide, storing the current window focus before the call to Float and then restoring it afterwards. I tried adding SWP_NOACTIVATE to the call to Float but this didn't seem to help.

2) CWindowStateMgr::Restore does not return true or false so you can't tell if it got data or not. This is a simple fix:

bool Restore()
	sstate::CMainState mstate(m_strMainKey);
	CRegKey key;
	if(mstate.Restore() && (key.Open(mstate.MainKey(), 
		sstate::ctxtMainWindow, KEY_READ) == ERROR_SUCCESS))
		m_pImpl->Restore(&mstate, key);
		return true;
		return false;

3. As pointed out by some others (and included here for completeness) keyboard shortcuts do not work from docked windows. I'm going to have a look into this.

4. The current code has a bug which causes undocked, hidden windows to re-load their position wrongly when using CWindowStateMgr. This manifested itself for me by causing the windows to appear offscreen in the top-left corner with minimum size. This seems to be fixed by initialising all of the DFDOCKPOS and similar structs with 0s before using them, I also filled rects with 0s when I noticed them uninitialised.

Thanks again for the excellent code. Once I've put all of the other fixes in that I've noticed whilst trawling this message board I'll put a patch on my website that applies the fixes that I've made.


Simon Steele
Programmers Notepad -
GeneralRe: This is fantastic (just a few bugs) Pin
Lioric27-May-03 14:04
memberLioric27-May-03 14:04 
GeneralMDIExSample maximize/size Pin
quarium25-Apr-03 11:54
memberquarium25-Apr-03 11:54 
GeneralMenus Dont Work Pin
peter@howudodat.com19-Apr-03 10:55
memberpeter@howudodat.com19-Apr-03 10:55 
QuestionMFC Project Link ? Pin
hhko12-Apr-03 0:47
memberhhko12-Apr-03 0:47 
GeneralMDIExSample hosting IWebBrowser2 in MDI Child Window bugs Pin
LoupiWa9-Mar-03 4:53
memberLoupiWa9-Mar-03 4:53 
QuestionHow to put a dialog into the docking window Pin
wutongtree3-Mar-03 11:24
memberwutongtree3-Mar-03 11:24 
AnswerRe: How to put a dialog into the docking window Pin
jennyq30-May-03 10:26
memberjennyq30-May-03 10:26 
GeneralRe: How to put a dialog into the docking window Pin
wutongtree30-May-03 12:27
memberwutongtree30-May-03 12:27 
GeneralRe: How to put a dialog into the docking window Pin
freehawk14-Dec-03 18:08
memberfreehawk14-Dec-03 18:08 
GeneralError message in demo projects Pin
Brian Nichols17-Feb-03 14:55
memberBrian Nichols17-Feb-03 14:55 
GeneralCommand bar and tool bar "moves" bug Pin
Ralph Shnelvar11-Feb-03 7:32
memberRalph Shnelvar11-Feb-03 7:32 
GeneralRe: Command bar and tool bar "moves" bug Pin
Ralph Shnelvar11-Feb-03 9:03
memberRalph Shnelvar11-Feb-03 9:03 
GeneralClose only Active Tab in TabDockingBox Pin
Jens Nilsson30-Jan-03 17:54
memberJens Nilsson30-Jan-03 17:54 
GeneralDifferent Layouts Pin
Mat B27-Jan-03 0:09
memberMat B27-Jan-03 0:09 
GeneralRe: Different Layouts Pin
Paul Selormey15-Mar-03 2:03
memberPaul Selormey15-Mar-03 2:03 
GeneralRe: Different Layouts Pin
Kjetil Haga2-Apr-03 17:33
memberKjetil Haga2-Apr-03 17:33 
GeneralRe: Different Layouts Pin
Simon Steele14-May-03 7:45
memberSimon Steele14-May-03 7:45 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190617.1 | Last Updated 21 Nov 2007
Article Copyright 2002 by Serge Klimov
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid