Pinnable ControlBar
This article is based on Cristi Posea's CSizeControlBar
Introduction
This article is based on the article CSizingControlBar - a resizable control bar by Cristi Posea. It implements a control bar that can be pinned.
Using the code
- Include the following files in your project:
scbarcf.cpp scbarcf.h sizecbar.h sizecbar.cpp scbarg.h scbarg.cpp PinDockBar.cpp PinDockBar.h AutoHideBar.cpp AutoHideBar.h DrawFrame.cpp DrawFrame.h
- 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):
#define _SCB_REPLACE_MINIFRAME #include "sizecbar.h" #include "scbarg.h" #include "scbarcf.h" #include "PinDockBar.h" #include "DrawFrame.h" #include "AutoHideBar.h
- Derive classes from
CPinDockBar
(you have an example in mybar.* files). - In mainfrm.h, include your class' header, i.e.
#include "mybar.h"
Then add member variables to
CMainFrame
, i.e.CMyBar m_MyBar; CMyBar2 m_MyBar2; CMyBar2 m_MyBar2_1;
- In mainfrm.h, Add following macro in the
CMainFrame
class definitionclass CMainFrame : public CFrameWnd { //.... DECLARE_PINDOCK() };
- In mainfrm.cpp, add following macro:
IMPLEMENT_PINDOCK(CMainFrame)
- In mainfrm.cpp, add following macro in the message map of the class:
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //... ON_PINDOCK_MESSAGES() END_MESSAGE_MAP()
- Create the bar in
CMainFrame::OnCreate()
. Then set bar styles, enable it to dock... like any control bar. UsingEnablePinDocking(..)
instead ofEnableDocking
, i.e.EnablePinDocking(CBRS_ALIGN_ANY); //EnableDocking(CBRS_ALIGN_ANY);
- Set your imagelist for the
AutoHideBar
arraym_AutoHideBar[0..3]
m_ImgList.Create(IDB_TAB, 16, 1, RGB(255,0,255)); for(int i = 0;i < 4; i ++) m_AutoHideBar[i].SetImageList(&m_ImgList);
CPinDockBar
is an abstract class, you need to implement two functions for your class:public: void AddToDrawBar(CAutoHideBar * pDrawBar); void RemoveFromDrawBar(CAutoHideBar * pDrawBar);
AddToDrawBar
is called when a control sizing bar needs to move its child control(s) to side pane. RemoveFromDrawBar
is called when a control sizing bar needs to take back its child control(s) from side pane.
The functions could be like this:
void CMyBar2::AddToDrawBar(CAutoHideBar * pDrawBar) { CRect rt; GetClientRect(&rt); CString szStr; GetWindowText(szStr); pDrawBar->AddButton(szStr, DRAWBTNSTYLE_BTN, &m_List, this, &rt, this, 0); }; void CMyBar2::RemoveFromDrawBar(CAutoHideBar * pDrawBar) { CRect rect; pDrawBar->RemoveButton(&m_List); pDrawBar->Shrink(); pDrawBar->CalcLayout(); pDrawBar->Invalidate(); GetParentFrame()->ShowControlBar(this, TRUE, FALSE); GetClientRect(&rect); m_List.MoveWindow(9,9, rect.Width() - 18, rect.Height() - 9 - 9); };
Note
LoadBarState()
and SaveState()
not implemented