Click here to Skip to main content
15,867,835 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 185K   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

 
GeneralRe: setting m_pFloatingFrameClass protected data member [modified] Pin
bioan15-Sep-06 22:19
professionalbioan15-Sep-06 22:19 
Hi Ziran!
Everything seems to work fine! Now I got NO doubled frame and my dialog is dockable with double click on the title bar. I hope the your tricky offset to be safe I do not test it very well!
Now I have another problem: when I push the pin button (on the instant bar) I got no reaction - nothing happend. I insert some break point in the code, but it seems that the debbuger don't reach, not enter - in OnPushPinOn(..) member function. I check out all the declaration and their positions in the code, but I'm not sure that the press button message goes in coresponding function, probably becose it is a DLL COM. You have any ideea how I can achive this push button message in my case?
Important: the debugger reach CPinDockBar::OnNcLButtonUp(..)
Kind regards!
Ioan



-- modified at 4:33 Saturday 16th September, 2006
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
ziran lin18-Sep-06 15:54
ziran lin18-Sep-06 15:54 
Questionhi,Ziran. Have you try to add an item to the list control? Pin
vt123456789022-Aug-06 15:11
vt123456789022-Aug-06 15:11 
AnswerRe: hi,Ziran. Have you try to add an item to the list control? Pin
vt123456789022-Aug-06 18:13
vt123456789022-Aug-06 18:13 
GeneralResize = Flash is serious [modified] Pin
supau31-Jul-06 22:14
supau31-Jul-06 22:14 
GeneralRe: Resize = Flash is serious [modified] Pin
ziran lin1-Aug-06 15:23
ziran lin1-Aug-06 15:23 
GeneralResize during startup Pin
isonic27-Jul-06 2:50
isonic27-Jul-06 2:50 
GeneralRe: Resize during startup Pin
ziran lin1-Aug-06 15:44
ziran lin1-Aug-06 15:44 
QuestionHow can I put a formview in the tabctrl Pin
vt123456789016-Jun-06 13:23
vt123456789016-Jun-06 13:23 
AnswerRe: How can I put a formview in the tabctrl Pin
Ziran_lin16-Jun-06 14:21
Ziran_lin16-Jun-06 14:21 
GeneralRe: How can I put a formview in the tabctrl Pin
vt123456789016-Jun-06 19:45
vt123456789016-Jun-06 19:45 
Generalload / save state Pin
LoganKale12-Jun-06 4:54
LoganKale12-Jun-06 4:54 
Generalmissplasing of the control bar Pin
LoganKale7-Jun-06 4:38
LoganKale7-Jun-06 4:38 
GeneralRe: missplasing of the control bar [modified] Pin
Ziran_lin7-Jun-06 14:57
Ziran_lin7-Jun-06 14:57 
GeneralRe: missplasing of the control bar Pin
LoganKale12-Jun-06 4:55
LoganKale12-Jun-06 4:55 
GeneralDisplay a modeless dialog Pin
alwittta4-May-06 21:00
alwittta4-May-06 21:00 
GeneralRe: Display a modeless dialog Pin
Ziran_lin22-May-06 11:24
Ziran_lin22-May-06 11:24 
QuestionHow to set the initial bar state as hide? Pin
humorstar16-Jul-05 14:49
humorstar16-Jul-05 14:49 
AnswerRe: How to set the initial bar state as hide? Pin
Vinicius Pontes6-Feb-06 2:14
Vinicius Pontes6-Feb-06 2:14 
AnswerRe: How to set the initial bar state as hide? Pin
James Poag25-Jan-07 6:11
James Poag25-Jan-07 6:11 
GeneralAbout License... Pin
Member 48490029-Dec-04 23:18
Member 48490029-Dec-04 23:18 
GeneralRe: About License... Pin
Ziran_lin30-Dec-04 6:40
Ziran_lin30-Dec-04 6:40 
GeneralCSizingControlBar::OnLButtonUp doesn't work! Pin
wenzhai9-Dec-04 15:40
wenzhai9-Dec-04 15:40 
Questionhow to add darg and drop support to tree items? Pin
mahatma_cis29-Jul-04 19:34
mahatma_cis29-Jul-04 19:34 
AnswerRe: how to add darg and drop support to tree items? Pin
Ziran_lin29-Jul-04 20:06
Ziran_lin29-Jul-04 20:06 

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.