又一个修改对话框背景颜色

 
BOOL CTestKEYDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnEraseBkgnd(pDC);
HBITMAP h_bitMap;
h_bitMap = SHLoadImageFile(L"bg.gif");
if(h_bitMap == NULL)
{
return false;
}
BITMAP bm;
GetObject(&h_bitMap,sizeof(HBITMAP),&bm);
/*
为一个图片赋值。
*/
HDC hDc = CreateCompatibleDC(pDC->GetSafeHdc());
/*
内存中的DC是仅仅存储在内存中的。当一个DC被创建的时候,它的外观(显示模式)只是一个象素大小。所以,在应用程序使用DC之前,
要先将一个大小合适的图片用"CreateCompatiableBitmap"“选择”到内存中,这样DC的大小就是图片的大小。
当内存中的一个DC被创建的时候,所有的属性都是默认值 ,如果想把它当做一个普通的DC,使用者必须设置它的属性,获得当前的设置,
和当前选中的画图用的画笔、画刷,的区域的大小。
CreateCompatibleDC函数只能用于支持光栅操作的设备。应用程序是否支持光栅操作,可以用"GetDeviceCaps"函数来获得。
当DC使用完后,用DeleteDC去销毁这个DC。
*/
/*
A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high.
Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. 
To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required. 
When a memory DC is created, all attributes are set to normal default values. The memory DC can be used as a normal DC.
You can set the attributes; obtain the current settings of its attributes; and select pens, brushes, and regions.
The CreateCompatibleDC function can only be used with devices that support raster operations. 
An application can determine whether a device supports these operations by calling the GetDeviceCaps function. 
When you no longer need the memory DC, call the DeleteDC function. 
*/
HBITMAP hOldBmp = NULL;
hOldBmp = (HBITMAP)SelectObject(hDc,&h_bitMap);
/*
保存原先的图片信息,以便恢复。(用完后,需要对系统的信息进行恢复)
*/
/*
This function returns the previously selected object of the specified type. 
An application should always replace a new object with the original, 
default object after it has finished drawing with the new object. 
*/
CRect rect;
GetClientRect(&rect);
/*
获取当前客户区的大小。
*/
StretchBlt(pDC->GetSafeHdc(),rect.left,rect.top,rect.Width(),rect.Height(),
hDc,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
/*
Draw the Picture .
*/
SelectObject(hDc,hOldBmp);
DeleteDC(hDc);
hDc = NULL;
if(h_bitMap != NULL)
{
DeleteObject(h_bitMap);
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值