这应该做什么:CMFCToolBar :: IsLastCommandFromButton? [英] What is this supposed to do : CMFCToolBar::IsLastCommandFromButton ?

查看:87
本文介绍了这应该做什么:CMFCToolBar :: IsLastCommandFromButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这种方法的用途和用途是什么。



MSDN:确定最近执行的命令是否是从指定的工具栏按钮。



我唯一的参考是来自VisualStudio MSDN示例:



当用户在工具栏中的组合框中选择一个值时调用方法。

I''m not certain what this method is used for and in what circumstances.

MSDN : "Determines whether the most recently executed command was sent from the specified toolbar button."

The only reference I have is from the VisualStudio MSDN sample :

The method is called when the user select a value in a combobox in a toolbar.

  ON_COMMAND(ID_DUMMY_SELECT_ACTIVE_CONFIGURATION, OnDummySelectActiveConfiguration)
  ON_CBN_SELENDOK(ID_DUMMY_SELECT_ACTIVE_CONFIGURATION, OnDummySelectActiveConfiguration)

//...
void CVisualStudioDemoDoc::OnDummySelectActiveConfiguration()
{
  CMFCToolBarComboBoxButton* pSrcCombo = NULL;

  CObList listButtons;
  if (CMFCToolBar::GetCommandButtons(ID_DUMMY_SELECT_ACTIVE_CONFIGURATION, listButtons) > 0)
  {
    for (POSITION posCombo = listButtons.GetHeadPosition(); pSrcCombo == NULL && posCombo != NULL;)
    {
      CMFCToolBarComboBoxButton* pCombo = DYNAMIC_DOWNCAST(CMFCToolBarComboBoxButton, listButtons.GetNext(posCombo));

      if (pCombo != NULL && CMFCToolBar::IsLastCommandFromButton(pCombo))
      {
        pSrcCombo = pCombo;
      }
    }
  }

  if (pSrcCombo != NULL)
  {
    ASSERT_VALID(pSrcCombo);
    LPCTSTR lpszSelItem = pSrcCombo->GetItem();
    CString strSelItem = (lpszSelItem == NULL) ? _T("") : lpszSelItem;

    AfxMessageBox(strSelItem);
  } 
  else
  {
    AfxMessageBox(_T("Show \"Set Active Configuration\" dialog...."));
  }
}





任何线索/提示?



谢谢。



最大。



Any clue/hints ?

Thanks.

Max.

推荐答案

该函数调用 CWnd :: GetCurrentMessage() [ ^ ]



用于检索描述当前消息的MSG结构(仅当在OnMessage处理程序中时才有效)。



然后比较对当前消息的hwnd和lParam按钮的hwnd,以查看当前消息是否从按钮开始。





我可以想想有几个不同的场景,人们可以使用它:



a)你有几个不同的按钮调用相同的消息处理程序。在这种情况下,您可以枚举按钮并测试它们以找出被调用的特定按钮。



如果您动态创建新按钮并将它们添加到工具栏中,那么您就无法为所有可能的按钮设置单独的处理程序,而是您拥有基于与按钮本身相关联的数据执行不同操作的单个处理程序。



b)相同的消息可能来自工具栏,菜单项或键盘快捷键。你想要做同样的事情,无论它来自哪里,但也许你想要播放一些视觉提示取决于它是否是按下的按钮。
The function calls CWnd::GetCurrentMessage()[^]

to retrieve a MSG structure that describes the "current message" (which is only valid "when in an OnMessage handler").

It then compares the hwnd of the button against the hwnd and lParam of the current message to see if the current message orignated from the button.


I can think of a couple of different scenarios where one might use this:

a) You have the same message handler invoked for several different buttons. In which case you might enumerate the buttons and test them to find out the specific one that was invoked.

If you dynamically create new buttons and add them to the toolbar then you can''t have a separate handler for all possible buttons, instead you''d have a single handler that did different things based on data associated with the button itself.

b) The same message might be coming from the toolbar, or a menu item or a keyboard shortcut. You want to do the same thing no matter where it came from, but maybe there is some visual cue you want to play depending on if it was the button that was pressed or not.


这篇关于这应该做什么:CMFCToolBar :: IsLastCommandFromButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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