CMyMFCPropertyGridProperty 是继承自CMFCPropertyGridProperty的类,在其中添加一个成员变量m_bHasButton。需要添加按钮对象将该变量设为TRUE。
接下来重载如下几个函数即可,对于m_bHasButton为FALSE的情况,直接调用父类函数,这样便不会影响不添加Button的行为
BOOL CMyMFCPropertyGridProperty::HasButton() const
{
if (m_bHasButton)
{
return m_bHasButton;
}
else
{
return __super::HasButton();
}
}
void CMyMFCPropertyGridProperty::OnClickButton(CPoint point)
{
if (m_bHasButton)
{
theApp.m_IRCameraCtrlMgr.DoNUCAction();
}
else
{
return __super::OnClickButton(point);
}
}
void CMyMFCPropertyGridProperty::AdjustButtonRect()
{
if (m_bHasButton)
{
m_rectButton = m_Rect;
m_rectButton.left = m_Rect.right-130;
m_rectButton.top ++;
}
else
{
return __super::AdjustButtonRect();
}
}
void CMyMFCPropertyGridProperty::OnDrawButton(CDC* pDC, CRect rectButton)
{
if (m_bHasButton)
{
ASSERT_VALID(this);
ASSERT_VALID(pDC);
ASSERT_VALID(m_pWndList);
pDC->FillRect(rectButton, &(GetGlobalData()->brBtnFace));
CString str = _T("My Button");
pDC->DrawText(str, rectButton, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
CRect rectFocus = rectButton;
rectFocus.DeflateRect(2, 2);
pDC->DrawFocusRect(rectFocus);
}
else
{
return __super::OnDrawButton(pDC, rectButton);
}
}
自定义CMFCPropertyGridProperty添加按钮
本文介绍如何在CMFCPropertyGridProperty的子类CMyMFCPropertyGridProperty中添加一个按钮功能。通过新增成员变量m_bHasButton来控制按钮的显示,并重载HasButton、OnClickButton、AdjustButtonRect和OnDrawButton等函数,实现按钮的显示、点击事件处理及布局调整。当m_bHasButton为FALSE时,行为与父类一致,确保不添加按钮时不影响原有功能。
1237

被折叠的 条评论
为什么被折叠?



