C++如何修改SDI程序的默认背景颜色

使用MFC建立的SDI应用程序默认为白色背景,你可以按下列步骤修改为其他背景颜色。

  1. Ctrl+W pops up the MFC classwizard property sheet.
  2. Select the Message Maps tab.
  3. From the drop-down list box under the Class Name static control, select the CxxxView option (xxx = Your project's name; for example, CNnoyeView).
  4. Make sure CxxxView is also selected in the Object ID's list box.
  5. Select the WM_ERASEBKGND option in the Messages list box.
  6. Click the Add Function button. The Class Wizard adds the "OnEraseBkgnd" member function.
  7. Click the Edit Code button. Add the following code before the return CView::OnEraseBkgnd(pDC) statement.
CBrush brNew(RGB(0,0,255));  //Creates a blue brushCBrush* pOldBrush = (CBrush*)pDC->SelectObject(&brNew);CRect rc;pDC->GetClipBox(rc); // Gets the co-ordinates of the client                     // area to repaint.pDC->PatBlt(0,0,rc.Width(),rc.Height(),PATCOPY);                     // Repaints client area with current brush.pDC->SelectObject(pOldBrush);return TRUE;    // Prevents the execution of return                // CView::OnEraseBkgnd(pDC) statement
 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1759567


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值