如何使用 CMFCRebar 产生可接受的外观和感觉?

发布于 2024-07-12 12:50:10 字数 510 浏览 11 评论 0原文

我正在尝试使用 MFC 功能包中的一些类来改进外观和功能。 我的 MFC 应用程序的感觉。

在我的应用程序中,我使用一个 CReBar 对象来停靠三个不同的工具栏。 我已经更新了该对象的类以使用 CMFCReBar,但在使用某些视觉样式时它看起来不太好。

功能包中似乎存在问题,因为即使使用包部署的 RebarTest 示例也会发生这种情况。

这是示例应用程序的屏幕截图,只是将视觉样式更改为 Office 2007(使用应用程序菜单而不是通过代码):

RebarTest 示例应用程序的屏幕截图 http://img105.imageshack.us/img105/1057/rebartestep5.png

有人成功使用过 CMFCReBar 吗? 有没有其他方法可以在不使用它的情况下实现相同的目的?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夕色琉璃 2024-07-19 12:50:10

基本上您不再需要使用钢筋控件。 只需创建 CMFCToolbars 和 CMFCMenuBar,对它们调用 EnableDocking,然后在每个上使用 DockPane,它们就会停靠并呈现 Office 2007(或您使用的任何其他主题)的外观和感觉。 查看写字板功能包示例,或使用 AppWizard 创建一个新项目(使用所有默认设置即可)来查看示例。

根据您的评论,好的:如果您想将工具栏停靠在彼此旁边,您可以在 DockPane 之后使用 DockPaneLeftOf。 根据我的经验,如果您不先 DockPane 两个工具栏,工具栏的放置往往会表现得很奇怪。

我还没有找到一个好的简单解决方案来阻止工具栏被拖动,同时停靠在彼此旁边,您可以删除 CBRS_GRIPPER 样式,但这并不能阻止工具栏被拖动。

您也可以不调用菜单栏或工具栏上的 EnableDocking。 这将使它们固定在一个地方。 但是,DockPaneLeftOf 在这种情况下似乎不起作用,因此您会丢失彼此相邻的停靠工具栏。

因此,如果您想停止停靠或将工具栏停靠在彼此旁边,那么现在似乎是其中之一。

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.

单调的奢华 2024-07-19 12:50:10

Paul DiLascia 编写了一个 来锁定 CToolBar,我用它来创建将在 CMFCToolbar 上工作的此类。 您可以复制它以对 CMFCMenuBar 执行完全相同的操作 - 只需将 MFCToolBar 更改为 MFCMenuBar 即可完成。

替代文本

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));

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));
哑剧 2024-07-19 12:50:10

我在使用 Office 2007 样式时也注意到了一些视觉问题 - 它似乎有点问题。 您可以使用其他之一来代替吗? XP Luna 看起来相当稳定......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文