Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is there a way in my <code>ON_COMMAND</code> handler to get the <code>CMFCRibbonBaseElement*</code> that fired the event?</p> </blockquote> <p>Not directly, no. The <code>WM_COMMAND</code> message is sent from <code>CMFCRibbonBaseElement::NotifyCommand</code>, and this message doesn't include the pointer in its parameters.</p> <p>To be able to tell which Undo button was clicked from the <code>ON_COMMAND</code> handler, I wrote this class, which inherits <code>CMFCRibbonUndoButton</code>. What this code does is store a pointer to the last activated Undo button each time one of the buttons is clicked, or the popup menu activated.</p> <pre><code>// CMyMFCRibbonUndoButton.h class CMyMFCRibbonUndoButton : public CMFCRibbonUndoButton { DECLARE_DYNCREATE(CMyMFCRibbonUndoButton) public: CMyMFCRibbonUndoButton(); CMyMFCRibbonUndoButton(UINT nID, LPCTSTR lpszText, int nSmallImageIndex = -1, int nLargeImageIndex = -1); virtual void OnClick(CPoint point); virtual void OnShowPopupMenu(); static CMyMFCRibbonUndoButton* GetLastActivated(); private: static CMyMFCRibbonUndoButton* s_pLastActivated; }; // CMyMFCRibbonUndoButton.cpp IMPLEMENT_DYNCREATE(CMyMFCRibbonUndoButton, CMFCRibbonUndoButton) CMyMFCRibbonUndoButton* CMyMFCRibbonUndoButton::s_pLastActivated = NULL; CMyMFCRibbonUndoButton::CMyMFCRibbonUndoButton() { } CMyMFCRibbonUndoButton::CMyMFCRibbonUndoButton(UINT nID, LPCTSTR lpszText, int nSmallImageIndex, int nLargeImageIndex) : CMFCRibbonUndoButton(nID, lpszText, nSmallImageIndex, nLargeImageIndex) { } void CMyMFCRibbonUndoButton::OnClick(CPoint point) { s_pLastActivated = this; CMFCRibbonUndoButton::OnClick(point); } void CMyMFCRibbonUndoButton::OnShowPopupMenu() { s_pLastActivated = this; CMFCRibbonUndoButton::OnShowPopupMenu(); } CMyMFCRibbonUndoButton* CMyMFCRibbonUndoButton::GetLastActivated() { return s_pLastActivated; } </code></pre> <p>Use this class in place of <code>CMFCRibbonUndoButton</code> when initialising your ribbon bar. In your handler function, call <code>GetLastActivated()</code> to retrieve this pointer, for example:</p> <pre><code>void CMyTestDoc::OnEditUndo() { CMyMFCRibbonUndoButton* pUndoButton = CMyMFCRibbonUndoButton::GetLastActivated(); ASSERT_VALID(pUndoButton); if (pUndoButton != NULL) { int ActionNumber = pUndoButton-&gt;GetActionNumber(); // etc. } } </code></pre> <p>This is a bit of a hack, certainly, but it was about the only way I could find to solve the problem.</p> <p>Anyway, I hope this helps,</p> <p>Chris</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload