自定义CMFCToolBar时出现问题 [英] Problem customising a CMFCToolBar

查看:191
本文介绍了自定义CMFCToolBar时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我已经按照我在网上找到的关于如何通过调用 CMFCToolBar来自定义工具栏的所有说明进行操作:: ReplaceButton(),并让它显示 CMFCToolBarComboBoxButton



I已经子类 CMFCToolBarComboBoxButton 以覆盖 CreateCombo(),但如果我调用 CMFCToolBar :: ReplaceButton()使用此派生类,我的派生 CreateCombo()永远不会被调用。



任何想法我做错了什么?



TIA。



PS - 这个项目从VS2005转换为VS2010,如果这有任何区别。

Hi all,

I've followed all the instructions I can find online on how to customise a toolbar by calling CMFCToolBar::ReplaceButton(), and have got it to display a CMFCToolBarComboBoxButton.

I have subclassed CMFCToolBarComboBoxButton in order to override CreateCombo(), but if I call CMFCToolBar::ReplaceButton() with this derived class, my derived CreateCombo() is never being called.

Any ideas what I am doing wrong?

TIA.

PS - This project was converted from VS2005 to VS2010, if that makes any difference.

推荐答案

//我得到一个指向CMFCToolBarComboBoxButton的指针,而不是我的派生类



只需将 DECLARE_DYNCREATE(CYourButton)放入其声明:)
// I get a pointer to a CMFCToolBarComboBoxButton, not to my derived class

Just place DECLARE_DYNCREATE(CYourButton) into its declaration :)


其中(方法)你打电话给Replac吗? e按钮。





它应该在主框架中AFX_WM_RESETTOOLBAR的处理程序中完成。



这就是我的工作:

...

ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR,OnToolbarReset)

...

Where (what method) do you call Replace Button.


It should be done in the handler of AFX_WM_RESETTOOLBAR in the main frame.

this is what I do:
...
ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)
...
LRESULT CMainFrame::OnToolbarReset(WPARAM wp,LPARAM)
{
 UINT uiToolBarId = (UINT) wp;
 TRACE( "CMainFrame::OnToolbarReset : %i\n", uiToolBarId );

 switch (uiToolBarId)
 {
  case YOUR_TOOLBAR_ID:
    CMFCToolBarComboBoxButton deviceCombo(IDC_DEVICE_TOOLBAR_COMBO, GetCmdMgr()->GetCmdImage(IDC_DEVICE_TOOLBAR_COMBO, FALSE), CBS_DROPDOWNLIST);
    m_DeviceToolBar.ReplaceButton ( IDC_DEVICE_TOOLBAR_COMBO, deviceCombo   );

  break;
 }
}





注意 :框架将保存/加载注册表中工具栏按钮的状态,如果您对代码进行更改,应用程序仍将使用这些值。所以在(重新)编码工具栏时删除注册表中的应用程序条目。这是非常加重的。



祝你好运。



NOTE: the framework will save/load the state of the buttons of the toolbars in the registry, if you make changes to the code, the application will still use those values. so remove your application entry in the registry when (re)coding toolbars. This is quite aggravating.

Good luck.


我在菜单栏中实施了CMFCToolbarComboboxbut。

我还为它指定了一个标签文本。

但它没有显示标签。

所以

如何在菜单栏中为CMFCToolbarComboboxbutton设置标签?

plz帮帮我
i have implemented CMFCToolbarComboboxbutton in Menubar.
and i also specified a Label text for it.
but it does not show label.
so
how to set label for CMFCToolbarComboboxbutton in Menubar?
plz help me


这篇关于自定义CMFCToolBar时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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