更改为工具栏UI代码不会反映在实际程序执行中 [英] Change to toolbar UI code is not reflected in actual program execution

查看:133
本文介绍了更改为工具栏UI代码不会反映在实际程序执行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(并不是真正紧急的问题).

我正在使用带有一些自定义按钮(编辑框)的CMFToolbar.

在AFX_WM_RESETTOOLBAR的处理程序中,我创建工具栏按钮并将其替换为CMFCToolBarEditBoxButton.

ON_register_MESSAGE(AFX_WM_RESETTOOLBAR,OnToolbarReset)

(Not really an urgent problem to fix).

I''m using a CMFToolbar with some custom buttons in them (edit box).

In the handler of AFX_WM_RESETTOOLBAR, I create and replace the toolbar button with a CMFCToolBarEditBoxButton .

ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)

LRESULT CMainFrame::OnToolbarReset(WPARAM wp,LPARAM)
{
  UINT uiToolBarId = (UINT) wp;
  if ( uiToolBarId == ID_MY_TOOLBAR)
  {
    CMFCToolBarEditBoxButton edit(IDM_BUTTON, 
       GetCmdMgr()->GetCmdImage(IDM_BUTTON, FALSE), 
       ES_RIGHT, 75);
    m_DeviceToolBar.ReplaceButton(IDM_BUTTON, edit);

  }



这样可以正常工作,并会在工具栏中创建一个宽度为75的编辑框.
这也适用于工具栏中的其他控件.

但是现在,如果要将编辑框的宽度增加到100(例如),我会将代码更改为



This works, and will create an edit box with a width of 75 in the toolbar.
This also works for other kind of controls in the toolbar.

But now, if I want to increase the width of the editbox to 100 (for example), I will change the code to

CMFCToolBarEditBoxButton edit(IDM_BUTTON,
   GetCmdMgr()->GetCmdImage(IDM_BUTTON, FALSE),
   ES_RIGHT, 100);



由于实际大小存储在注册表中,因此在执行程序时不会自动反映出来.

用户要么必须抓取注册表项,要么进入自定义对话框并放下工具栏.

是否有一种干净的内置方式将工具栏标记为脏",这样它的设置就不会从注册表中加载(一次)?

我可以想到许多方法来破解该漏洞,但我认为这会造成不必要的伤害.

谢谢.



This will not automatically be reflected when the program is executed because the actual size is stored in the registry.

User either have to scrap the registry entry or go in the customize dialog and rest the toolbar.

Is there a clean built-in way to have the toolbar marked as "dirty" so that its settings will not be loaded from the registry (once) ?

I can think of many ways to hack that into place, but I feel it will cause more harm than necessary.

Thanks.

推荐答案

只需使用重新实现的compare-function构造您自己的派生类:
Just construct your own derivation with reimplemented compare-function:
class CMyEditButton : public CMFCToolBarEditBoxButton
{
  DECLARE_SERIAL(CMyEditButton)
//..
public:
//..
  virtual BOOL CompareWith(const CMFCToolBarButton& other) const {
    return CMFCToolBarEditBoxButton::CompareWith(other) &&
           other.IsKindOf(RUNTIME_CLASS(CMyEditButton)) &&
           m_iWidth == other.m_iWidth;
  }
//..
};


...将设置父工具栏的m_bResourceChanged标志
并在加载后重置它(小节):)


...it will set the m_bResourceChanged flag of the parent Toolbar
and reset it (the bar) after its loading :)


这篇关于更改为工具栏UI代码不会反映在实际程序执行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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