Click here to Skip to main content
Click here to Skip to main content

Toolbar within splitter windows

By , 4 Jan 2000
 

Sample Image - toolbar_splitter.jpg

Introduction

Has anyone ever wondered how to dock a toolbar inside a splitter pane? Normally you cannot do that, but you can alter your splitter pane so that it will look just like you placed a toolbar on one of its sides. The trick is to create a two-pane splitter where your initial pane was; but not just any splitter, we will use our own, which does not allow resizing, and has different border settings. There is one additional view to create, and we will derive a class from CFormView since features provided by this class are closer to our goal.

The Code

First goes the custom splitter window:

// class definition
class CSmartSplitterWnd : public CSplitterWnd
{
public:
    CSmartSplitterWnd();
    virtual ~CSmartSplitterWnd();
    intHitTest(CPoint pt)const;
protected:
    DECLARE_MESSAGE_MAP()
};

// class implementation
CSmartSplitterWnd::CSmartSplitterWnd()
{
    // put your own values here, to make the splitter fit your needs
    m_cxSplitter=3;
    m_cySplitter=3;
    m_cxBorderShare=0;
    m_cyBorderShare=0;
    m_cxSplitterGap=3;
    m_cySplitterGap=3;
}

CSmartSplitterWnd::~CSmartSplitterWnd()
{
}

BEGIN_MESSAGE_MAP(CSmartSplitterWnd, CSplitterWnd)
    //{{AFX_MSG_MAP(CSmartSplitterWnd)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

intCSmartSplitterWnd::HitTest(CPoint pt)const
{
    ASSERT_VALID(this);
    // do not allow caller to see mouse hits
    return 0;
}

Next, we must create a simple CFormView using the resource editor and ClassWizard. You can add any controls to your form view, but you must keep in mind that handling the WM_SIZE message may help you improve the look of your view. There are several ways to update your buttons and other controls inside the view; you may need to implement one of them to update, enable or disable the controls.

The last step is to create the splitter itself and the views. The code below matches a SDI application that accommodates the code above inside a splitter pane, but you can easily adjust it to fit your needs.

First, add a member to the CMainFrame class of type CSmartSplitterWnd:

class CMainFrame: public CFrameWnd
{
[...]
public:
    CSmartSplitterWnd m_barSplitter;

In the OnCreateClient member of the CMainFrame class, add code to create the splitter inside the right pane:

// create the splitter window
if (!m_barSplitter.CreateStatic(&m_parentSplitter, 2, 1, 
    WS_CHILD|WS_VISIBLE|WS_BORDER, 
    m_parentSplitter.IdFromRowCol(1, 0))) return false;

// create the views
m_barSplitter.CreateView(0, 0, RUNTIME_CLASS(CBarView), CSize(0, 0), pContext);
m_barSplitter.CreateView(1, 0, RUNTIME_CLASS(CTheView), CSize(0, 0), pContext);
// then set heights

The code is quite easy to follow and change to meet your needs, but if you need assistance, contact me. Also please send me bugs or updates, to keep this solution up-to-date. For more details on the sample application, contact me.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

_stefanu_
Web Developer
Romania Romania
Member
... coming in a short while

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberxiaopanv88815 Jan '12 - 13:05 
Very well!
Generalwell done!memberjame-cxj6 Jul '05 - 19:36 
well done. thank you
GeneralWell done !!!memberirmo_ebel27 May '04 - 22:18 
Works perfectly for me.
 
Easy to implement and working fine. You saved me a lot of time.
Generalgood onemembervikas amin12 Sep '05 - 23:01 
it save my time also
thank you
 
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
QuestionBut ,can not drag it?memberyesong6 Jan '03 - 21:12 
But ,can not drag it now?
GeneralGreat! Worked out of the box.memberjhwurmbach14 Oct '02 - 0:11 
But you need to know what is talked about, and how subclassing works.
Which probably accounts for the most of the low votes.

GeneralNo demomembercenturyithero8 Jul '02 - 16:06 
No demo or source code.
 
I am learning hard !
Generalno resource here!memberAnonymous30 May '02 - 15:07 
Where can I download the resource and demo project?
Generalme too..memberdazinith9 Apr '02 - 4:38 
im confused too, i don't see any explanation of how to actually put the buttons in the extra space.. and no explanation of the member variables you set during the constructor of the splitter window..
 
-dz
QuestionHowto prevent scrollbars?memberTomM26 Mar '02 - 8:11 

If the user resizes the main window so that it is narrower than the dialog resource I use for my toolbar then scrollbars appear on my toolbar.
 
Since the toolbar is thin, this obscures the whole toolbar?
 
How do I prevent this?
 
Also, your text mentions a sample application - but I dont see any links to it.
 
Thanks,
 
Tom.
GeneralI'm confused...memberAnonymous13 Nov '01 - 19:39 
Why the heck anybody in his right mind is going to do that?... Was doing the same look during all my 10 years of MFC experience:
Wouldn't it be simplier to create standard 2(or one) CView derived panes and place standard 2(or one) CMainFrame derived Frames into it => each of them will or will not contain CToolBars, CStatusBars and whatever you want coming for free with CMainFrame, including standard message routing with UpdateCommandUI BTW...
Good Luck...Confused | :confused:
 
igor1960
GeneralWell done! :-)memberLeithian22 Sep '01 - 10:31 
Thx for this article, it was exactly what I was looking for! Smile | :)
Greets,
Leithian
 
-----------------------------
Nobody's perfect but this is no excuse for bad code!
So let's code well! Smile | :)
(Chris Meier)

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 5 Jan 2000
Article Copyright 2000 by _stefanu_
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid