Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
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.
Posted 7-Dec-12 9:54am
Maximilien71.3K
Comments
CPallini at 7-Dec-12 16:55pm
   
"Determines whether the most recently executed command was sent from the specified toolbar button." looks clear enough to me. What is your doubt?
Maximilien at 7-Dec-12 18:09pm
   
I can read the description, but I was looking for a test case to demonstrate why it should be used.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Maximilien at 7-Dec-12 18:10pm
   
Thanks, I will look at those scenarios next week, I think I understand better (scenario A).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 321
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 PhilLenoir 70
4 nv3 60
0 Sergey Alexandrovich Kryukov 6,691
1 OriginalGriff 6,119
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100