Click here to Skip to main content
15,861,172 members
Articles / Desktop Programming / MFC
Article

Pinnable ControlBar

Rate me:
Please Sign up or sign in to vote.
4.81/5 (28 votes)
4 Dec 2003CPOL1 min read 184.8K   3.6K   65   55
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

  1. 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
  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):
    #define _SCB_REPLACE_MINIFRAME
    #include "sizecbar.h"
    #include "scbarg.h"
    #include "scbarcf.h"
    
    #include "PinDockBar.h"
    #include "DrawFrame.h"
    #include "AutoHideBar.h
  3. Derive classes from CPinDockBar (you have an example in mybar.* files).
  4. 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;
    
  5. In mainfrm.h, Add following macro in the CMainFrame class definition
    class CMainFrame : public CFrameWnd
    {
    //....    
        DECLARE_PINDOCK()
    };
  6. In mainfrm.cpp, add following macro:
    IMPLEMENT_PINDOCK(CMainFrame)
  7. In mainfrm.cpp, add following macro in the message map of the class:
    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //...
        ON_PINDOCK_MESSAGES()
    END_MESSAGE_MAP()
  8. Create the bar in CMainFrame::OnCreate(). Then set bar styles, enable it to dock... like any control bar. Using EnablePinDocking(..) instead of EnableDocking, i.e.
    EnablePinDocking(CBRS_ALIGN_ANY);
    //EnableDocking(CBRS_ALIGN_ANY);
    
  9. Set your imagelist for the AutoHideBar array m_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);
    
  10. 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

License

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


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionUnable to compile under Microsoft visual studio 2010 Pin
poonampawar1120-Jun-13 18:58
poonampawar1120-Jun-13 18:58 
Questionhow can i change this application to a .dll Pin
Jijesh Balakrishnan8-May-12 1:40
Jijesh Balakrishnan8-May-12 1:40 
QuestionLicense Terms Pin
Scott Bartine7-Dec-11 11:44
Scott Bartine7-Dec-11 11:44 
AnswerRe: License Terms Pin
ziran lin8-Dec-11 7:26
ziran lin8-Dec-11 7:26 
QuestionInfinite loop? Pin
Guppa8-Feb-10 14:42
Guppa8-Feb-10 14:42 
GeneralUnable to compile under VS 2005 Pin
PetoG25-Oct-07 0:26
PetoG25-Oct-07 0:26 
GeneralRe: Unable to compile under VS 2005 Pin
scrat_amir25-Oct-07 4:34
scrat_amir25-Oct-07 4:34 
GeneralRe: Unable to compile under VS 2005 Pin
RayChenMedical1-Jun-09 21:48
RayChenMedical1-Jun-09 21:48 
QuestionHow can I deal with the notify message? Pin
feifa1685-Oct-07 2:30
feifa1685-Oct-07 2:30 
QuestionLoadBarState & SaveBarState Pin
r.teox11-Jul-07 3:16
r.teox11-Jul-07 3:16 
GeneralDoes not work in MDI project Pin
neyadakim17-May-07 0:36
neyadakim17-May-07 0:36 
QuestionRe: Does not work in MDI project Pin
r.teox11-Jul-07 5:51
r.teox11-Jul-07 5:51 
GeneralVisual Studio 2003 Pin
rkshdixit10-Apr-07 19:02
rkshdixit10-Apr-07 19:02 
GeneralTooltip for auto hide button Pin
scrat_amir2-Apr-07 20:52
scrat_amir2-Apr-07 20:52 
GeneralThe outlook style in MDI Pin
laronze20-Mar-07 2:43
laronze20-Mar-07 2:43 
GeneralRe: The outlook style in MDI Pin
Ziran_lin22-Mar-07 10:32
Ziran_lin22-Mar-07 10:32 
AnswerRe: The outlook style in MDI Pin
r.teox11-Jul-07 5:46
r.teox11-Jul-07 5:46 
Generala fatal error Pin
ping_linux17-Dec-06 5:51
ping_linux17-Dec-06 5:51 
GeneralRe: a fatal error Pin
PetoG21-Jan-09 1:59
PetoG21-Jan-09 1:59 
Generalsetting m_pFloatingFrameClass protected data member Pin
bioan10-Sep-06 3:54
professionalbioan10-Sep-06 3:54 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
ziran lin12-Sep-06 13:32
ziran lin12-Sep-06 13:32 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
bioan12-Sep-06 21:05
professionalbioan12-Sep-06 21:05 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
ziran lin13-Sep-06 10:22
ziran lin13-Sep-06 10:22 
Probably this "dirty" way is feasible:

1. Get the offset of m_pFloatingFrameClass in CMDIFrameWnd
You can get this by derivng a class from CMDIFrameWnd, and adding a member functiuon of calculating the offset of m_pFloatingFrameClass

2. Since you have the offset of m_pFloatingFrameClass
You can put code like:
*(CRuntimeClass*)((BYTE *)pFrame + offset) = RUNTIME_CLASS(CSCBMiniDockFrameWnd);


GeneralRe: setting m_pFloatingFrameClass protected data member Pin
bioan13-Sep-06 20:16
professionalbioan13-Sep-06 20:16 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
ziran lin14-Sep-06 15:28
ziran lin14-Sep-06 15:28 

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.