注册 登录
编程论坛 VC++/MFC

新手一个关于背景填充的疑问!

tang_iphone 发布于 2013-01-11 11:59, 488 次点击
void CGAME_1View::OnPaint()
{
    CPaintDC dc(this); // device context for painting
   
    // TODO: Add your message handler code here
    CRect parentsRect;
    CBrush brush(RGB(255,0,0));
    this->GetClientRect(&parentsRect);
    dc.FillRect(&parentsRect,&brush);


    // Do not call CView::OnPaint() for painting messages
}
上面这段代码能运行,但是没有背景填充红色的效果。这是为什么啊?我百度了下,有的说是在OnEraseBkgnd函数中改变背景色。但是我在OnEraseBkgnd中写了代码还是不OK
8 回复
#2
玩出来的代码2013-01-11 13:04
你把在OnEraseBkgnd函数中的代码贴出来
#3
tang_iphone2013-01-11 14:32
回复 2楼 玩出来的代码
BOOL CGAME_1View::OnEraseBkgnd(CDC* pDC)
{
    // TODO: Add your message handler code here and/or call default
    CRect parentsRect;
    CBrush brush(RGB(255,0,0));
    this->GetClientRect(&parentsRect);
    pDC->FillRect(&parentsRect,&brush);
    return 0;
}
是这样的就是把DC改成了PDC。
#4
yuccn2013-01-11 17:02
CGAME_1View ~~

是否被其他窗口类挡住了?
#5
玩出来的代码2013-01-11 17:11
应该是其他地方的问题了,此段代码没问题
#6
tang_iphone2013-01-11 18:49
回复 4楼 yuccn
没有吧 新建立的MFC空单文档。就是稍微改了下控件菜单。
#7
pyw16882013-01-13 14:36
看孙鑫的C++视频 上面讲的很清楚啦,可以先看看在做
#8
tang_iphone2013-01-14 01:26
自己找出来问题了。 是改的时候多删了点东西。。
#9
々NARUTO2013-01-16 14:16
回复 8楼 tang_iphone
..............
1