WTL:按钮的消息循环

发布于 2024-12-09 00:16:48 字数 816 浏览 3 评论 0原文

我有一些围绕此代码的类,我们将其称为 ToolbarButton,

TBBUTTON tbbutton;
ZeroMemory(&tbbutton, sizeof(tbbutton));  
tbbutton.idCommand = index;
tbbutton.dwData = 0;
tbbutton.fsState = TBSTATE_ENABLED | BSTYLE_BUTTON | BTNS_SHOWTEXT;
tbbutton.iBitmap = I_IMAGENONE;
tbbutton.iString = toolbar->AddStrings(text);

toolbar->InsertButton(index, &tbbutton);

其中工具栏是 CToolBarCtrl*

如何为 ToolbarButton 类创建消息循环?

像 OnClick这样的东西

class ToolbarButton : public CMessageMap{
  ..
  BEGIN_MSG_MAP(ToolbarButton )
    MESSAGE_HANDLER(WM_COMMAND, OnClick)
  END_MSG_MAP()

  ..
}

没有被调用,我还应该做什么?

更新:我还考虑了答案的变体 - 工具栏处理点击消息,通过 idCommand 查找按钮并调用创建按钮的 OnClick。 ..但是我有一个正在重构的代码,并看到按钮类(正确的〜按钮周围大约有4个接口和15个类),它们执行了我需要的语法糖,但它们也包含过时的代码和我想要的代码消除,目前我无法切片它

I have some class around this code, let call it ToolbarButton

TBBUTTON tbbutton;
ZeroMemory(&tbbutton, sizeof(tbbutton));  
tbbutton.idCommand = index;
tbbutton.dwData = 0;
tbbutton.fsState = TBSTATE_ENABLED | BSTYLE_BUTTON | BTNS_SHOWTEXT;
tbbutton.iBitmap = I_IMAGENONE;
tbbutton.iString = toolbar->AddStrings(text);

toolbar->InsertButton(index, &tbbutton);

where toolbar is something CToolBarCtrl*

How can I create message loop for ToolbarButton class?

something like

class ToolbarButton : public CMessageMap{
  ..
  BEGIN_MSG_MAP(ToolbarButton )
    MESSAGE_HANDLER(WM_COMMAND, OnClick)
  END_MSG_MAP()

  ..
}

OnClick didn't called, what else should I do?

Update: I also think about the variant from answer - toolbar handles click message, find button by idCommand and call OnClick of founded button. .. But I have a code that I am refactoring and see the button class (to be correct ~ about 4 interfaces and 15 classes around button) that do such syntax sugar what I need, but also they contains obsolete code and code that I want to eliminate and currently I can't slice it

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

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

发布评论

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

评论(1

眼眸印温柔 2024-12-16 00:16:48

它应该以某种不同的方式工作。

  • 您不继承消息映射类,通常窗口类有消息映射
  • 工具栏按钮不是窗口;工具栏是窗口控件,按钮是其内部部分,没有单独的句柄,没有消息映射;您将按钮单击作为来自具有特定按钮标识符的工具栏的通知进行处理
  • 如果您想将自定义按钮放到工具栏上,它应该是(a)自定义按钮,例如所有者绘制的按钮,最多由工具栏控件本身支持,或者( b) 一个功能齐全的窗口控件

我建议您检查使用工具栏控件你真正的选择是什么。

It is supposed to work in a somewhat different way.

  • you don't inherit from message map class, normally windowed classes have message maps
  • toolbar button is not a window; toolbar is the windowed control and button is its internal part without separate handle, without message map; you handle button clicks as notifications from toolbar with specific button identifiers
  • if you want to put a custom button onto toolbar, it should be either (a) customized button, such as owner-drawn, up to extent supported by toolbar control itself, or (b) a fully featured windowed control

I suggest that you check Using Toolbar Controls as for what your options really are.

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