CSizingControlBar - a resizable control bar

转载 2012年03月28日 11:20:05

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 www.datamekanix.com for class reference, a full changelog, FAQ, a dedicated message board and more.



 浮动窗口的制作暨CSizingControlBar类的使用说明***********************************************************  本文在实现过程...
  • xuexiuyin
  • xuexiuyin
  • 2007年06月11日 14:59
  • 5751


jQuery.resizable 是基于jQuery开发的一款插件, 为用户提供html dom resize 行为. 例如存在如下的html dom: 假设整个蓝色边框的div为需要改变...
  • u013291076
  • u013291076
  • 2014年06月09日 17:06
  • 1032

iOS 【错误:'Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'】

错误:'Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'   意为不允许修tabB...
  • Felicity294250051
  • Felicity294250051
  • 2016年02月16日 15:29
  • 2674


MFC中三个最基本的控件的介绍,它们分别是:ProgressControl、ScrollBarControl以及SpinControl。1.ProgressControl实现的功能如下所示: 关...
  • u011371629
  • u011371629
  • 2017年03月05日 17:13
  • 297


在下次用到的方法之前之前先调用一下$("#id").resizable("destroy"); 然后在在后边的方法继续调用$("#id").resizable();方法即可用...
  • Aurevoir1993
  • Aurevoir1993
  • 2017年01月02日 11:17
  • 515

Draw Line and Bar Chart with Matplotlib 画线和图表

做了实验以后,一般需要用图形说明数据的含义,我常用简单的曲线图,和柱状图。 我之前只会用Excel,但是Excel画出来的图总感觉不够专业,在看师弟的presentation的时候,...
  • bibiqueue
  • bibiqueue
  • 2014年03月17日 14:39
  • 1455

MFC_Process control 进度条

MFC class : CProgressCtrl 中文名:进度条 成员函数: GetPos() SetPos() GetRange32() ...
  • qq_35508344
  • qq_35508344
  • 2017年09月25日 18:52
  • 180


 var ResizableExample = {    init: function(){        var basic = new Ext.Resizable(basic, {        ...
  • kinglino520
  • kinglino520
  • 2009年06月26日 09:42
  • 901

RTSP a=control属性的理解

问题: RTSP中SETUP命令,PLAY命令对应的URL怎么填。   分析: 依据 C.1.1 Control URL     The "a=control:" attribute i...
  • u013506600
  • u013506600
  • 2014年04月18日 10:46
  • 905

How to make a resizable dialog bar in Microsoft Foundation Classes (MFC)

 How to make a resizable dialog bar in Microsoft Foundation Classes (MFC)View products that this art...
  • ArduousBonze
  • ArduousBonze
  • 2008年08月04日 13:51
  • 874
您举报文章:CSizingControlBar - a resizable control bar