4

I am trying to use some classes from the MFC Feature Pack to improve the look & feel of my MFC application.

In my application, I use one CReBar object to dock three different toolbars. I have updated the class of this object to use CMFCReBar, but it doesn´t look good when using some visual styles.

It seems there's a problem in the Feature Pack because it happens even with the RebarTest example deployed with package.

This is a screenshot of the example application just changing the visual style to Office 2007 (using the app. menu not by code):

Screenshot of RebarTest example application http://img105.imageshack.us/img105/1057/rebartestep5.png

Has anybody successfully used CMFCReBar? Is there any other way to achieve the same without using it?

staticbeast
  • 2,073
  • 2
  • 22
  • 24
Javier De Pedro
  • 2,219
  • 4
  • 32
  • 49

3 Answers3

2

Basically you don't need to use a rebar control anymore. By simply creating your CMFCToolbars and CMFCMenuBar, calling EnableDocking on them and then using DockPane on each, they will dock and take on the Office 2007 (or whatever other theme you use) look-and-feel. Check out the WordPad Feature Pack sample, or create a new project (one with all the default settings is fine) using AppWizard to see an example.

Ok from your comment: if you want to dock toolbars next to each other you can use DockPaneLeftOf after DockPane. It tends to act strangely with toolbar placement in my experience if you don't DockPane both toolbars first.

I haven't found a good simple solution to stopping the toolbars from being dragged yet while docking next to each other, you can remove the CBRS_GRIPPER style, however that doesn't stop the toolbars from being dragged.

You can also just not call EnableDocking on the menubar or toolbars. This will make them fixed place. However, DockPaneLeftOf does not seem to work in this case, so you lose docking toolbars next to each other.

So it seems like one or the other right now if you want to stop docking, or dock toolbars next to each other.

Alisdair W
  • 21
  • 3
  • Hi Alisdair Walker, thanks for replying. Maybe you are right and the problem is I am not using the right control. But I want my toolbars not to be undocked by the user and I want my three toolbars in the same row. Could you help me to achive that? – Javier De Pedro Feb 03 '09 at 09:00
1

Paul DiLascia wrote a class to lock the CToolBar, I used it to create this class which will work on CMFCToolbar. And you can copy it to do exactly the same sort of thing for CMFCMenuBar - just change MFCToolBar to MFCMenuBar and you're done.

alt text

class CLockedMFCToolBar : public CMFCToolBar
{
public:
    CLockedMFCToolBar() : CMFCToolBar() {}

protected:
    LRESULT CLockedMFCToolBar::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
    {
        if ((msg==WM_LBUTTONDOWN || msg==WM_LBUTTONDBLCLK))
        {
            // Got click or double-click and toolbar is locked: if mouse in "dead
            // zone" then ignore the message--don't pass to control bar
            CPoint pt(lp);
            if (OnToolHitTest(pt, NULL) == -1)
                return 0; // return without handling: bypass control bar dragging!
        }
        // pass unhandled messages subclassed window--this is important!*/
        return CMFCToolBar::WindowProc(msg, wp, lp);
    }
};


//////////////////////////////
// in CMainFrame declaration
protected:
    CLockedMFCMenuBar m_wndMenuBar;
    CLockedMFCToolBar m_wndToolBar1;
    CLockedMFCToolBar m_wndToolBar2;


////////////////////////////
// in CMainFrame::OnCreate
if (!m_wndToolBar1.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar1.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
{
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
}

if (!m_wndToolBar2.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar2.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
{
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
}

EnableDocking(CBRS_ALIGN_ANY);
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
DockPane(&m_wndToolBar2);
DockPane(&m_wndToolBar1);
DockPaneLeftOf(&m_wndToolBar1, &m_wndToolBar2);

m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() &
            ~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
m_wndToolBar1.SetPaneStyle(m_wndToolBar1.GetPaneStyle() &
            ~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
m_wndToolBar2.SetPaneStyle(m_wndToolBar2.GetPaneStyle() &
            ~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
  • Thanks! That seems to be what I was looking for. Just one thing, could you let me know how do you create the toolbars? I mean which style you use in the Create/CreateEx instruction. – Javier De Pedro Feb 06 '09 at 09:37
  • I've edited with the creation code. It's whatever the MFC wizard created for me. You might also want to comment out the following line, to remove that nasty Add/Remove buttons thing at the end of each toolbar: //m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize); – demoncodemonkey Feb 06 '09 at 09:59
0

I've noticed a few visual problems when using the Office 2007 style too - it seems to be a little bit buggy. Can you use one of the others instead? XP Luna seems to be quite stable...

Stu Mackellar
  • 11,510
  • 1
  • 38
  • 59
  • Hey Stu! Thanks for your comment. The problem also happens with other styles. It's not so evident but it also has some visual "defects". – Javier De Pedro Jan 15 '09 at 16:28
  • Yes, I've also seen problems with other styles too, but none seem as bad as the Office 2007 ones. It seems that the theming mostly works until you try to do anything even slightly out of the ordinary. – Stu Mackellar Jan 15 '09 at 17:00