| |||||||||||
IntroductionHas 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 The CodeFirst 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 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 class CMainFrame: public CFrameWnd { [...] public: CSmartSplitterWnd m_barSplitter; In the // 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. About Stefan Ungureanu
|