您的位置:首页 > 大数据 > 人工智能

MFC对话框背景图添加与自适应缩放(通过OnPaint DC)

2017-06-19 10:30 232 查看

一、资源视图添加BITMAP位图资源

二、#include “resource.h”


二、 在该对话框类视图中(或者类向导消息函数或者别的什么方法)找到OnPaint函数,在else{后添加代码;

CBitmap bmp;

bmp.LoadBitmap(IDB_BITMAP1); //载入位图

int nBmpWidth, nBmpHeight;

BITMAP bmInfo;

bmp.GetBitmap(&bmInfo);

nBmpWidth=bmInfo.bmWidth;

nBmpHeight=bmInfo.bmHeight;  //获取位图的实际大小

CRect clientRC;

GetClientRect(clientRC);  //获取客户区域的大小

CDC *pDC=GetDC();  //屏幕DC

CDC memDC;

memDC.CreateCompatibleDC(pDC); //内存DC

memDC.SelectObject(&bmp);

pDC->StretchBlt(0,0,clientRC.Width(),clientRC.Height(),&memDC,0,0, nBmpWidth, nBmpHeight, SRCCOPY);  //在窗口绘图

memDC.DeleteDC();  

bmp.DeleteObject();

ReleaseDC(pDC);//释放


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息