我已经在CDockablePane中创建了CMFCPropertyGridCtrl,我想用一个新的替换该CMFCPropertyGridCtrl,然后覆盖OnEraseBkgnd。OnEraseBkgnd仅在应用程序启动时调用,并且当我想通过Invalidate或InvalidateRect调用它时,它没有触发。我怎么打电话给OnEraseBkgnd?提前致谢。
void CCL2PropertiesPane::HostPropertyGridControl(CMFCPropertyGridCtrl* pPropertyGridControl)
{
if(NULL == pPropertyGridControl)
return;
if(m_pPropertyGridControl)
RemoveCurrentPropertyGridControl();
m_pPropertyGridControl = pPropertyGridControl;
SetWindowText(m_pPropertyGridControl->GetName());
CRect clientRectangle;
GetClientRect(&clientRectangle);
m_pPropertyGridControl->Create(WS_CHILD | WS_VISIBLE, clientRectangle, this, PROPERTIES_DOCKABLE_PANE_ID);
}
//--------------------------------------------------------------------------------
void CCL2PropertiesPane::RemoveCurrentPropertyGridControl()
{
m_pPropertyGridControl = NULL;
SetWindowText(GetPaneName());
CRect clientRectangle;
GetClientRect(&clientRectangle);
//here i want to call OnEraseBkgnd
InvalidateRect(clientRectangle);
//Invalidate();
}
//--------------------------------------------------------------------------------
BOOL CCL2PropertiesPane::OnEraseBkgnd(CDC* pDC)
{
CRect clientRectangle;
GetClientRect(&clientRectangle);
CBrush whiteBrush(RGB(250, 250, 250));
pDC->FillRect(clientRectangle, &whiteBrush);
return TRUE;
}
添加ON_WM_ERASEBKGND
到CCL2PropertiesPane
的消息图可正确删除背景。或将FillRect
功能移至OnPaint
。
关于:
void CCL2PropertiesPane::RemoveCurrentPropertyGridControl()
{
m_pPropertyGridControl = NULL;
...
}
上面的代码适用于初始化,但它不会删除或破坏任何东西。该控件仍然存在,它只会使程序忘记如何找到该控件。要隐藏控件,请使用:
m_pPropertyGridControl->ShowWindow(SW_HIDE);
要破坏控件,请使用DestroyWindow()
,但以上设置不建议这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句