Drawing my own embedded button with CMFCPropertyGridProperty and detecting the button state

26 Views Asked by At

I have a CMFCPropertyGridCtrl that I am using in a CDialog. I am rolling out a derived property class and customizing the look n feel of the embedded button.

Now, this is the boilerplate MFC code:

void CMFCPropertyGridProperty::OnDrawButton(CDC* pDC, CRect rect)
{
  ASSERT_VALID(this);
  ASSERT_VALID(pDC);
  ASSERT_VALID(m_pWndList);

  CMFCToolBarComboBoxButton button;

  pDC->FillRect(rect, m_pWndList->m_bControlBarColors ? &(GetGlobalData()->brBarFace) : &(GetGlobalData()->brBtnFace));

  if (m_dwFlags & AFX_PROP_HAS_LIST)
  {
    visualManager->OnDrawComboDropButton(pDC, rect, !m_bEnabled, m_bButtonIsDown, m_bButtonIsDown, &button);
    return;
  }

  CString str = _T("...");
  pDC->DrawText(str, rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

  CMFCVisualManager::AFX_BUTTON_STATE state = m_bButtonIsDown ? CMFCVisualManager::ButtonsIsPressed : CMFCVisualManager::ButtonsIsRegular;
  visualManager->OnDrawButtonBorder(pDC, &button, rect, state);

  if (m_bButtonIsFocused)
  {
    CRect rectFocus = rect;
    rectFocus.DeflateRect(2, 2);

    pDC->DrawFocusRect(rectFocus);
  }
}

I realise that the Visual Manager does not really work in a dialog project, but it seems to me that the properties own variables are never set to true? Specifically:

  • m_bButtonIsFocused
  • m_bButtonIsDown

I can draw a new button using my own code:

enter image description here

But I thought I would be able to adjust it a bit when the mouse was over the button. Yet those variables in the CMFCPropertyGridProperty class never seem to be true.

0

There are 0 best solutions below