WTL:按钮的消息循环
我有一些围绕此代码的类,我们将其称为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该以某种不同的方式工作。
我建议您检查使用工具栏控件你真正的选择是什么。
It is supposed to work in a somewhat different way.
I suggest that you check Using Toolbar Controls as for what your options really are.