如何设置动态创建的 CMFCToolbar 的原始状态? [英] How to SetOriginalState of a dynamically created CMFCToolbar?

查看:30
本文介绍了如何设置动态创建的 CMFCToolbar 的原始状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 mfc 应用程序中动态创建了一些工具栏

I have create some toolbars dynamically in my mfc application

m_cToolBarEx.CreateEx(this, TBSTYLE_FLAT , WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_HIDE_INPLACE);

工具栏没有位图或资源 ID.我使用函数 InsertButton 在我的工具栏中添加按钮

the toolbar has no bitmap or resource id. I used the function InsertButton to add buttons in my toolbar

当我尝试通过菜单中的重置工具栏按钮重置此工具栏时.工具栏不会重置为其原始状态,仅提示 消息框 并且没有更改已恢复.

When I try to reset this toolbar through Reset Toolbar button from menu. The toolbar does not reset to its original state only the message box is prompted and no changes are restored.

我认为问题是当 CMFCToolBar::RestoreOriginalstate() 执行条件:

I assume the problem is when the CMFCToolBar::RestoreOriginalstate() is executed the condtion:

if (m_uiOriginalResID == 0)
    {
        return FALSE;
    }

为真,函数返回假,因为 m_uiOriginalResID 中没有资源 ID.

gets true and the function returns false as there is no resource id in the m_uiOriginalResID.

有没有办法加载动态创建的工具栏,或者我必须继承RestoreOriginalstate函数并自己编写.

Is there any way to load the dynamically created toolbar or I have to inherit RestoreOriginalstate function and write my own.

推荐答案

您应该按照 注意部分:

当用户从自定义菜单中选择重置时调用此方法.您也可以手动调用此方法以编程方式重置菜单栏的状态.此方法从资源文件中加载原始状态.

This method is called when the user selects Reset from the customization menu.You can also manually call this method to programmatically reset the state of the menu bar.This method loads the original state from the resource file.

如果您想在用户选择重置选项时进行任何处理,请覆盖此方法.

Override this method if you want to do any processing when the user selects the Reset option.

您还应该覆盖 CanBeRestored() 函数,defaut implementation 如果资源 ID 为 0,则返回 FALSE.

You should also override CanBeRestored() function, the defaut implementation returns FALSE if the resource ID is 0.

这里是 RestoreOriginalstate() 的一个例子 :

BOOL CLinksBar::RestoreOriginalstate ()
{
    RemoveAllButtons ();

    InsertButton (CLinkButton (_T("MSDN Home"), _T("http://www.msdn.com")));
    InsertButton (CLinkButton (_T("Microsoft Home"), _T("http://www.microsoft.com")));
    InsertButton (CLinkButton (_T("Visual C++ Developer Center"), _T("http://msdn2.microsoft.com/visualc/")));

    EnableCustomizeButton (TRUE, -1, _T(""));

    AdjustLayout ();
    Invalidate ();

    return TRUE;
} 

这篇关于如何设置动态创建的 CMFCToolbar 的原始状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆