Click here to Skip to main content
11,412,833 members (73,360 online)
Click here to Skip to main content

Pinnable ControlBar

, 4 Dec 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

ziran lin
Software Developer
United States United States
No Biography provided

Comments and Discussions

 
QuestionUnable to compile under Microsoft visual studio 2010 [modified] Pin
poonampawar11 at 20-Jun-13 19:58
memberpoonampawar1120-Jun-13 19:58 
Questionhow can i change this application to a .dll [modified] Pin
Jijesh Balakrishnan at 8-May-12 2:40
memberJijesh Balakrishnan8-May-12 2:40 
QuestionLicense Terms Pin
Scott Bartine at 7-Dec-11 12:44
memberScott Bartine7-Dec-11 12:44 
AnswerRe: License Terms Pin
ziran lin at 8-Dec-11 8:26
memberziran lin8-Dec-11 8:26 
QuestionInfinite loop? Pin
Guppa at 8-Feb-10 15:42
memberGuppa8-Feb-10 15:42 
GeneralUnable to compile under VS 2005 Pin
PetoG at 25-Oct-07 1:26
memberPetoG25-Oct-07 1:26 
GeneralRe: Unable to compile under VS 2005 Pin
scrat_amir at 25-Oct-07 5:34
memberscrat_amir25-Oct-07 5:34 
GeneralRe: Unable to compile under VS 2005 Pin
raynewmedical at 1-Jun-09 22:48
memberraynewmedical1-Jun-09 22:48 
QuestionHow can I deal with the notify message? Pin
feifa168 at 5-Oct-07 3:30
memberfeifa1685-Oct-07 3:30 
QuestionLoadBarState & SaveBarState Pin
r.teox at 11-Jul-07 4:16
memberr.teox11-Jul-07 4:16 
GeneralDoes not work in MDI project Pin
neyadakim at 17-May-07 1:36
memberneyadakim17-May-07 1:36 
QuestionRe: Does not work in MDI project Pin
r.teox at 11-Jul-07 6:51
memberr.teox11-Jul-07 6:51 
GeneralVisual Studio 2003 Pin
rkshdixit at 10-Apr-07 20:02
memberrkshdixit10-Apr-07 20:02 
GeneralTooltip for auto hide button Pin
scrat_amir at 2-Apr-07 21:52
memberscrat_amir2-Apr-07 21:52 
GeneralThe outlook style in MDI Pin
laronze at 20-Mar-07 3:43
memberlaronze20-Mar-07 3:43 
GeneralRe: The outlook style in MDI Pin
Ziran_lin at 22-Mar-07 11:32
memberZiran_lin22-Mar-07 11:32 
AnswerRe: The outlook style in MDI Pin
r.teox at 11-Jul-07 6:46
memberr.teox11-Jul-07 6:46 
Generala fatal error Pin
ping_linux at 17-Dec-06 6:51
memberping_linux17-Dec-06 6:51 
GeneralRe: a fatal error Pin
PetoG at 21-Jan-09 2:59
memberPetoG21-Jan-09 2:59 
Generalsetting m_pFloatingFrameClass protected data member Pin
Ionut Codrut at 10-Sep-06 4:54
memberIonut Codrut10-Sep-06 4:54 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
ziran lin at 12-Sep-06 14:32
memberziran lin12-Sep-06 14:32 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
Ionut Codrut at 12-Sep-06 22:05
memberIonut Codrut12-Sep-06 22:05 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
ziran lin at 13-Sep-06 11:22
memberziran lin13-Sep-06 11:22 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
Ionut Codrut at 13-Sep-06 21:16
memberIonut Codrut13-Sep-06 21:16 
GeneralRe: setting m_pFloatingFrameClass protected data member Pin
ziran lin at 14-Sep-06 16:28
memberziran lin14-Sep-06 16:28 
GeneralRe: setting m_pFloatingFrameClass protected data member [modified] Pin
Ionut Codrut at 15-Sep-06 23:19
memberIonut Codrut15-Sep-06 23: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 lin at 18-Sep-06 16:54
memberziran lin18-Sep-06 16:54 
Questionhi,Ziran. Have you try to add an item to the list control? Pin
vt1234567890 at 22-Aug-06 16:11
membervt123456789022-Aug-06 16:11 
AnswerRe: hi,Ziran. Have you try to add an item to the list control? Pin
vt1234567890 at 22-Aug-06 19:13
membervt123456789022-Aug-06 19:13 
GeneralResize = Flash is serious [modified] Pin
supau at 31-Jul-06 23:14
membersupau31-Jul-06 23:14 
GeneralRe: Resize = Flash is serious [modified] Pin
ziran lin at 1-Aug-06 16:23
memberziran lin1-Aug-06 16:23 
GeneralResize during startup Pin
isonic at 27-Jul-06 3:50
memberisonic27-Jul-06 3:50 
GeneralRe: Resize during startup Pin
ziran lin at 1-Aug-06 16:44
memberziran lin1-Aug-06 16:44 
QuestionHow can I put a formview in the tabctrl Pin
vt1234567890 at 16-Jun-06 14:23
membervt123456789016-Jun-06 14:23 
AnswerRe: How can I put a formview in the tabctrl Pin
Ziran_lin at 16-Jun-06 15:21
memberZiran_lin16-Jun-06 15:21 
GeneralRe: How can I put a formview in the tabctrl Pin
vt1234567890 at 16-Jun-06 20:45
membervt123456789016-Jun-06 20:45 
Generalload / save state Pin
LoganKale at 12-Jun-06 5:54
memberLoganKale12-Jun-06 5:54 
Generalmissplasing of the control bar Pin
LoganKale at 7-Jun-06 5:38
memberLoganKale7-Jun-06 5:38 
GeneralRe: missplasing of the control bar [modified] Pin
Ziran_lin at 7-Jun-06 15:57
memberZiran_lin7-Jun-06 15:57 
GeneralRe: missplasing of the control bar Pin
LoganKale at 12-Jun-06 5:55
memberLoganKale12-Jun-06 5:55 
GeneralDisplay a modeless dialog Pin
alwittta at 4-May-06 22:00
memberalwittta4-May-06 22:00 
GeneralRe: Display a modeless dialog Pin
Ziran_lin at 22-May-06 12:24
memberZiran_lin22-May-06 12:24 
QuestionHow to set the initial bar state as hide? Pin
humorstar at 16-Jul-05 15:49
memberhumorstar16-Jul-05 15:49 
AnswerRe: How to set the initial bar state as hide? Pin
Vinicius Pontes at 6-Feb-06 3:14
memberVinicius Pontes6-Feb-06 3:14 
AnswerRe: How to set the initial bar state as hide? Pin
James Poag at 25-Jan-07 7:11
memberJames Poag25-Jan-07 7:11 
GeneralAbout License... Pin
Joseph Mendez at 30-Dec-04 0:18
memberJoseph Mendez30-Dec-04 0:18 
GeneralRe: About License... Pin
ziran at 30-Dec-04 7:40
memberziran30-Dec-04 7:40 
GeneralCSizingControlBar::OnLButtonUp doesn't work! Pin
wenzhai at 9-Dec-04 16:40
memberwenzhai9-Dec-04 16:40 
Questionhow to add darg and drop support to tree items? Pin
mahatma_cis at 29-Jul-04 20:34
membermahatma_cis29-Jul-04 20:34 
AnswerRe: how to add darg and drop support to tree items? Pin
ziran at 29-Jul-04 21:06
memberziran29-Jul-04 21:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150427.1 | Last Updated 5 Dec 2003
Article Copyright 2003 by ziran lin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid