Locking Rebars and Toolbars

I found a way to lock the rebars like the rebars in the Windows Explorer under Win 2000/XP (which wasn't easy to do). Simply add the following code to the MainFrm.cpp where you want to lock or unlock the rebar:

CReBarCtrl& rbc = m_wndReBar.GetReBarCtrl();
REBARBANDINFO rbbi;
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask  = RBBIM_STYLE;
int nCount  = rbc.GetBandCount();
for (int i  = 0; i < nCount; i++)
{
   rbc.GetBandInfo(i, &rbbi);
   rbbi.fStyle ^= RBBS_NOGRIPPER | RBBS_GRIPPERALWAYS;
   rbc.SetBandInfo(i, &rbbi);
}

The toolbars in the rebar unlocked:

And now locked:

Thanks to the CodeGuru reviewers, I also know a way to lock toolbars (not within a rebar). The idea is this: when locking controlbars, we need to disable any mouse attempts to move'em around. The key to this is to set the m_pDockBar member to NULL.

When unlocking, make sure to set it back to what it was earlier.. which means the app needs to cache these. This dirty little trick should do the job.

Add these to mainfrm.h:

CDockBar*   m_pTBDockBar;
CDockBar*   m_pDBDockBar;
BOOL m_bLocked;

Add this to mainfrm.cpp (into the constructor):

m_bLocked = FALSE;

Add this code to toggle:

DWORD dwToolbarStyle = m_wndToolBar.GetBarStyle();
DWORD dwDlgbarStyle  = m_wndDlgBar.GetBarStyle();
if(m_bLocked)
{
   // Changes the bars' style, so they have grippers
   dwToolbarStyle |= CBRS_GRIPPER;
   dwDlgbarStyle  |= CBRS_GRIPPER;
   m_wndToolBar.SetBarStyle(dwToolbarStyle);
   m_wndDlgBar.SetBarStyle(dwDlgbarStyle);

   //when removing the fixed style, set back the dockbar
   m_wndToolBar.m_pDockBar = m_pTBDockBar;
   m_wndDlgBar.m_pDockBar  = m_pDBDockBar;
}
else
{
   // Changes the bars' style, so they have not grippers
   dwToolbarStyle &= ~CBRS_GRIPPER;
   dwDlgbarStyle  &= ~CBRS_GRIPPER;
   m_wndToolBar.SetBarStyle(dwToolbarStyle);
   m_wndDlgBar.SetBarStyle(dwDlgbarStyle);

   // If the bar is floating, it will be docked before locking it.
   DockControlBar(&m_wndToolBar);
   DockControlBar(&m_wndDlgBar);

   //remove dockbar so that it cannot be moved around
   m_pTBDockBar = m_wndToolBar.m_pDockBar;
   m_pDBDockBar = m_wndDlgBar.m_pDockBar;
   m_wndToolBar.m_pDockBar = NULL;
   m_wndDlgBar.m_pDockBar  = NULL;
}

m_wndDlgBar.Invalidate();    // dialog bars need Invalidate()
RecalcLayout();
m_bLocked = !m_bLocked;

The toolbars unlocked:

And now locked:

Summary

This code has been tested on Win NT 4.0/2000/XP Pro.

Best regards, Frank



About the Author

Frank Gsellmann

I'm a student and a software developer in Germany

Downloads

Comments

  • Works like a charm, thanks!

    Posted by assaf3D on 10/28/2009 08:07am

    CToolBar on WinXP, set m_pDockBar = NULL just after the three "Docking" function calls and it works.

    Reply
  • You Rock!

    Posted by 3dtrue on 08/13/2005 03:24am

    Just wanted to say thanks Frank! Just what is was looking for! danke

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds