Click here to Skip to main content
12,821,670 members (43,936 online)
Click here to Skip to main content
Add your own
alternative version


350 bookmarked
Posted 16 Nov 1999

CSizingControlBar - a resizable control bar

, 15 Aug 2000 CPOL
Rate this:
Please Sign up or sign in to vote.
DevStudio-like docking window

Sample Image

Features of CSizingControlBar 2.43

  • Resizable control bar, that can be resized both when docked and when floating.
  • Multiple sizing control bars can be docked on the same row/column.
  • Full dynamic resizing, both when docked and floating, including diagonal resizing when floating.
  • State persistence support (SaveState/LoadState).
  • Gripper with "hide bar" flat button.
  • Memory DC flickerless NC painting.
  • Sample extension class with focus autosensing text caption. On Win98/Win2k, the caption is painted with gradient.
  • No custom resources were used (bitmaps, cursors, strings, etc.), so the integration is easier and you have full control over the resources you eventually use in derived classes.
  • Easy to use: use directly one of the CSizingControlBar* classes or derive your own control bar class, then add your child controls.


Getting Started

1. Include the following files in your project:


2. Add these lines to your stdafx.h (if the files are in a different directory, include the path - see the stdafx.h file in the samples):

#include "sizecbar.h"
#include "scbarg.h"

3. Derive a class from CSizingControlBarG (you have an example in mybar.* files).

4. In mainfrm.h, include your class' header:

#include "mybar.h"
then add a member variable to CMainFrame:
CMyBar m_wndMyBar;

5. Create the bar in CMainFrame::OnCreate(). Then set bar styles, enable it to dock... like any control bar.

if (!m_wndMyBar.Create(_T("My Bar"), this, 123)
    TRACE0("Failed to create mybar\n");
    return -1;
    // fail to create
m_wndMyBar.SetBarStyle(m_wndMyBar.GetBarStyle() |



DockControlBar(&m_wndMyBar, AFX_IDW_DOCKBAR_LEFT);

Advanced Example

The instructions above will make a docking bar with a DevStudio-like gripper (with 2 raised lines and a hide button) when docked, and with no gripper when floating.

Let's explore some advanced features. Now we will use the CSizingControlBarCF class as a base class, and will hide the miniframe caption, showing the gripper in the floating state too. That's possible, because CSizingControlBarCF's gripper looks like a small caption. As a side effect of using a custom miniframe class, the resizing of the floating bar will be dynamic if "Show window contents while dragging" display property is enabled.

1. Add these files to your project too:


2. Change the stdafx.h file to look like this:

#include "sizecbar.h"
#include "scbarg.h"
#include "scbarcf.h"
#define baseCMyBar CSizingControlBarCF

3. Add these lines in CMainFrame::OnCreate(), after the EnableDocking() call

    m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd);


These classes are intended to be used as base classes. Do not simply add your code to the files - instead create a new class derived from CSizingControlBarG or CSizingControlBarCF and put there what you need. If you want to customize your gripper, or simply don't want a gripper, you can use CSizingControlBar as a base class.

Window IDs: The usage of IDs in the range of AFX_IDW_CONTROLBAR_FIRST + 32 .. AFX_IDW_CONTROLBAR_LAST is required only if the bar will not be enabled for docking (that's is - it will stay fixed right under the frame's menu). But in this situation you won't be able to fully use the features of this class, so if you will enable it to dock (a reasonable guess :) then you can use any valid window ID.
Another place where the IDs are important is the saving/loading of the bar's state. You must use different IDs for each control bar that is enabled to dock, and this includes the other bars too. For example, if you have two toolbars, you can create the first one with the default ID (which is AFX_IDW_TOOLBAR = AFX_IDW_CONTROLBAR_FIRST), but the second one must have a different ID.

OnUpdateCmdUI: This member function is pure virtual in CControlBar (the base class of CSizingControlBar). Its purpose is to allow updating of controls at idle time (from here CCmdUI::DoUpdate() is called for the toolbars buttons, controls on dialog bars, panes of status bar, etc.).
However, I found it very useful to update the look of the "x" flat button in CSizingControlBarG and the color of the caption in CSizingControlBarCF (no timers needed). So, if you will use this function, don't forget to call the base class' member (see mybar.cpp).

Dynamic resizing: This feature allows redrawing of the bar during resizing. Also all the bars are repositioned and redrawn if necessary.
The SPI_GETDRAGFULLWINDOWS system parameter is queried for this (it is enabled by the "Show window contents while dragging" checkbox in Display Properties).

CBRS_SIZE_DYNAMIC: This bar style is required. Make sure you add it to the bar, otherwise the application will crash when the user floats a bar. You can add it using SetBarStyle() after Create(), or by changing the default style for Create() to something like: WS_VISIBLE|WS_CHILD|CBRS_TOP|CBRS_SIZE_DYNAMIC.

State persistence: The common MFC control bars' docking state is saved using CMainFrame::SaveBarState(). In addition to the info saved by this function, the CSizingControlBar class needs to save 3 sizes. This is done in CSizingControlBar::SaveState() function, so a m_wndMyBar.SaveState() call is required. Please note that the state storing code must be placed in CMainFrame's OnClose() or DestroyWindow(), not in OnDestroy(), because at the time the WM_DESTROY message is received, the floating bars are already destroyed.
In CMainFrame::OnCreate(), the m_wndMyBar.LoadState() call must be placed before LoadBarState().
Alternatively, if you have more than one resizable bars, you can call once the static member SizingControlBar::GlobalSaveState() instead of calling each bar's SaveState(). The same for LoadState() - there is a CSizingControlBar::GlobalLoadState() function. See both samples here for more details.

Precompiler flags: There are 2 symbols which can be defined to cause the floating bars to have different appearance and functionality:

  1. _SCB_REPLACE_MINIFRAME can be used to plug in CSCBMiniDockFrameWnd, which is a custom miniframe class. The main gain of using this class is that the floating bars can be resized dynamically, like all other windows. The other advantage is that the miniframe caption can be turned off, allowing the bar to display its own gripper, for increased functionality and/or custom designs.
    If you use this flag, you have to change the m_pFloatingFrameClass member of the main frame (see the advanced example above).
  2. _SCB_MINIFRAME_CAPTION can be defined only if the previous flag is also defined. It causes the custom miniframe to keep the tool window caption.
    Both CSizingControlBarG and CSizingControlBarCF classes do not display a gripper when floating if this flag is set.

See also for class reference, a full changelog, FAQ, a dedicated message board and more.


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


About the Author

Cristi Posea
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralRe: afxChNil Pin
ijcullen9-Aug-06 20:59
memberijcullen9-Aug-06 20:59 
GeneralRe: afxChNil Pin
yaodebo25-Nov-07 22:45
memberyaodebo25-Nov-07 22:45 
GeneralRe: afxChNil Pin
yaodebo25-Nov-07 22:45
memberyaodebo25-Nov-07 22:45 
Generalsave setting to .ini instead of registry Pin
Abu Mami28-Jul-05 19:24
memberAbu Mami28-Jul-05 19:24 
QuestionHow to resize the main frame with the bars. Pin
pfkhkwon21-Jul-05 1:47
memberpfkhkwon21-Jul-05 1:47 
QuestionHow disable mainframe separators ??? Pin
Relyer4-Jul-05 7:23
sussRelyer4-Jul-05 7:23 
GeneralI meet a samll problem when using MDI. Pin
Mick20082-Jul-05 20:51
memberMick20082-Jul-05 20:51 
GeneralRe: I meet a samll problem when using MDI. Pin
Mick20082-Jul-05 21:08
memberMick20082-Jul-05 21:08 
QuestionHow i Can write in this Docking bar Pin
kokabgujjar1-Jun-05 1:00
memberkokabgujjar1-Jun-05 1:00 
GeneralGetting rid of the view... Pin
bedei22-Apr-05 12:31
sussbedei22-Apr-05 12:31 
GeneralTypo Mistake! Pin
Priyank Bolia21-Mar-05 21:09
memberPriyank Bolia21-Mar-05 21:09 
QuestionHow can I set the Size of the Bar Pin
Schniddel13-Dec-04 1:55
memberSchniddel13-Dec-04 1:55 
AnswerRe: How can I set the Size of the Bar Pin
Priyank Bolia21-Mar-05 20:36
memberPriyank Bolia21-Mar-05 20:36 
AnswerRe: How can I set the Size of the Bar Pin
lpen28-Feb-06 17:44
memberlpen28-Feb-06 17:44 
m_szMinHorz = CSize(33, 32);
m_szMinVert = CSize(33, 32);
m_szMinFloat = CSize(37, 32);
m_szHorz = CSize(100, 100);//see here
m_szVert = CSize(100, 100);
m_szFloat = CSize(100, 100);
m_bTracking = FALSE;
m_bKeepSize = FALSE;
m_bParentSizing = FALSE;
m_cxEdge = 5;
m_bDragShowContent = FALSE;
m_nDockBarID = 0;
m_dwSCBStyle = 0;
QuestionHow to get a dialog (CDialog) in this dockable toolbar? Pin
T.T.H.22-Oct-04 0:32
memberT.T.H.22-Oct-04 0:32 
AnswerRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
Gammenon10-Nov-04 1:05
memberGammenon10-Nov-04 1:05 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
Ma Yanzhao23-Nov-04 2:02
memberMa Yanzhao23-Nov-04 2:02 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
Gammenon23-Nov-04 3:19
memberGammenon23-Nov-04 3:19 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
yuen_wc23-Nov-04 5:06
memberyuen_wc23-Nov-04 5:06 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
Gammenon23-Nov-04 22:31
memberGammenon23-Nov-04 22:31 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
Ma Yanzhao23-Nov-04 23:17
memberMa Yanzhao23-Nov-04 23:17 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
SeongHoon, Kim1-Dec-04 19:12
memberSeongHoon, Kim1-Dec-04 19:12 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
raquid26-Dec-04 2:37
memberraquid26-Dec-04 2:37 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
JohnCFemiani3-Mar-05 22:33
memberJohnCFemiani3-Mar-05 22:33 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
Isildur30-Jun-05 10:11
memberIsildur30-Jun-05 10:11 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
andrewtruckle18-Jan-06 22:12
memberandrewtruckle18-Jan-06 22:12 
GeneralRe: How to get a dialog (CDialog) in this dockable toolbar? Pin
peburkle22-Jul-06 10:10
memberpeburkle22-Jul-06 10:10 
QuestionHow can I change the position of the titlebar on a docking bar Pin
fullc0de20-Oct-04 6:15
memberfullc0de20-Oct-04 6:15 
GeneralWant to use this class. But... Pin
LRNATH22-Sep-04 23:32
memberLRNATH22-Sep-04 23:32 
GeneralRe: Want to use this class. But... Pin
mnarayan27-Sep-04 6:43
membermnarayan27-Sep-04 6:43 
GeneralRe: Want to use this class. But... Pin
LRNATH27-Sep-04 7:04
memberLRNATH27-Sep-04 7:04 
GeneralRe: Want to use this class. But... Pin
Steve Muccione2-Apr-05 3:23
memberSteve Muccione2-Apr-05 3:23 
GeneralCSizingControlBar Focus Pin
skinney465-Aug-04 7:27
memberskinney465-Aug-04 7:27 
GeneralRe: CSizingControlBar Focus Pin
m_harriss18-Sep-04 20:38
memberm_harriss18-Sep-04 20:38 
GeneralRe: CSizingControlBar Focus Pin
m_harriss25-Sep-04 10:41
memberm_harriss25-Sep-04 10:41 
QuestionHow can I focus on one ViewBar after OnCreate()?? Pin
jarba14-Jun-04 19:12
memberjarba14-Jun-04 19:12 
GeneralApplication inside web browser Pin
Gabriel Simoes18-May-04 1:57
memberGabriel Simoes18-May-04 1:57 
GeneralWicked, just a suggestion/question Pin
Hockey12-May-04 21:59
memberHockey12-May-04 21:59 
Generaldocking windows gets side by side on min, and max. of main window Pin
suneetchandok30-Mar-04 4:27
membersuneetchandok30-Mar-04 4:27 
Generaldocking windows moving out of main window area Pin
suneetchandok30-Mar-04 4:17
susssuneetchandok30-Mar-04 4:17 
GeneralProblem with Activex Pin
Angshuman4-Mar-04 23:43
memberAngshuman4-Mar-04 23:43 
GeneralFlickering problem Pin
Alex9999921-Feb-04 17:50
memberAlex9999921-Feb-04 17:50 
GeneralRe: Flickering problem Pin
LRNATH24-Sep-04 6:43
memberLRNATH24-Sep-04 6:43 
GeneralRe: Flickering problem Pin
xrestassuredx22-Feb-05 7:20
memberxrestassuredx22-Feb-05 7:20 
GeneralRe: Flickering problem Pin
Steve Muccione20-Mar-05 4:25
memberSteve Muccione20-Mar-05 4:25 
GeneralForm in CSizingControlBar Pin
_jaromir_20-Feb-04 1:25
member_jaromir_20-Feb-04 1:25 
GeneralRe: Form in CSizingControlBar Pin
mtzlplyk23-May-04 2:40
membermtzlplyk23-May-04 2:40 
GeneralRe: Form in CSizingControlBar Pin
vjedlicka13-Jun-04 10:42
membervjedlicka13-Jun-04 10:42 
QuestionHow to make group of multiple docked control bars with header control? Pin
23W18-Feb-04 2:13
suss23W18-Feb-04 2:13 
Questionhow to make a form based sizing control bar Pin
jeromecoroyer@yahoo.fr21-Jan-04 6:25
memberjeromecoroyer@yahoo.fr21-Jan-04 6:25 

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 | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 16 Aug 2000
Article Copyright 1999 by Cristi Posea
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid