开发者

WTL: Message loop for button

开发者 https://www.devze.com 2023-04-12 05:28 出处:网络
I have some class around this code, let call it ToolbarButton TBBUTTON tbbutton; ZeroMemory(&tbbutton, sizeof(tbbutton));

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 开发者_如何学Govariant 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消