关于CDockablePane类使用中出现的问题。
1.定义一个派生自CDockablePane的类
在类里面定义:
- C/C++ code
CMFCPropertyGridCtrl m_prop;CMFCPropertyGridProperty *m_pp;
在OnCreate函数里面:
- C/C++ code
m_pp = new CMFCPropertyGridProperty(.......);m_prop.AddProperty(m_pp);
然后在类的析构函数里面:
- C/C++ code
delete m_pp;
删除的时候会出错,这是为什么?
2.也是在一个派生自CDockablePane的类里面。
在类里面嵌入一个对话框,我想动态改变对话框的颜色。
在类里面定义:
- C/C++ code
CBrush* m_pBrush;
在OnCtlColor函数里面
- C/C++ code
if(m_pBrush != NULL){ delete m_pBrush; // 删除会出现问题,为什么? m_pBrush = NULL;}m_pBrush = new CBrush;m_pBrush->CreateSolidBrush(afxGlobalData.clrBarFace);return *m_pBrush;3.CDockablePane不会自动重绘自身窗口吗?
[解决办法]
这点代码看不出什么问题,有可能你的CDockablePane本来就有delete this的操作。你看看PostNcDestroy里有没有这样的语句。
[解决办法]
MSDN:
Do not destroy the properties or allow them to go out of scope before the grid control is destroyed. When you are done with the property grid control, call CMFCPropertyGridCtrl::RemoveAll to delete all the added properties.