各位大神帮帮忙,我在MFC的单文档中通过静态切分划分出两个View,在其中一个View中放了一个Picture控件,然后在Picture控件上放置属性表单,为什么其他控件(包括属性表单)的背景色都可以改变,而Picture控件的背景色始终不会改变,试了OnEraseBkgnd,OnCtlColor都不行啊?
有关Picture控件的基本代码如下,在所在View的OnInitialUpdate()函数中
1、首先把Picture控件的type属性改为Enhanced Metafile/Icon/Bitmap
2、声明定义一个HBRUSH m_hrPicture为类成员变量,类初始化时创建出来:
'Picture控件上放置属性表单'
属性表单 初始化时:
SetDialogBkColor(RGB(255,255,255),RGB(0,0,0));
SetBkColor是不可以的,你安装我8楼说的试试先
'通过静态切分窗格的单文档结构的视图中创建这些“
看看 你的创建代码
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CDispView), CSize(w, h1), pContext);
CDispView 应该派生自 CFormView
1. 创建应该 对话框 资源 (PropertyPage )
2. 关联到 CFormView
3. 在 CDispView EraseBkGround 中 画 背景,
4. 不需要 picture, 因为 // fit the property sheet into the place holder window, and show it
把 picture 覆盖 了。
HBRUSH CDispView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if ((pWnd->GetDlgCtrlID() == IDC_PLACEHOLDER) && (nCtlColor == CTLCOLOR_STATIC)) //IDC_PLACEHOLDER是Picture控件ID,后面一部分是看到网上的一种说法,去掉后也不行
{
pDC->SetBkColor(RGB(0,0,255));
return m_brush; //作为约定,返回背景色对应的刷子句柄
}
// TODO: Return a different brush if the default is not desired
return m_brush;
}
以上是你的代码,请问if里面执行了吗?
另外,你的if里面返回的画刷和非if返回的画刷是同一个(view默认的画刷),这个怎么解释?
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CDispView), CSize(w, h1), pContext);
CDispView 应该派生自 CFormView
1. 创建应该 对话框 资源 (PropertyPage )
2. 关联到 CFormView
3. 在 CDispView EraseBkGround 中 画 背景,
4. 不需要 picture, 因为 // fit the property sheet into the place holder window, and show it
把 picture 覆盖 了。
// fit the property sheet into the place holder window, and show it
既然是 fit 那就是 一样大, 不就覆盖了, 那个 proppage 要小一点。
联系客服