位图(bitmap)
1、加载位图,从文件中加载位图对象
2、根据设备DC创建兼容DC,建立一个与窗口设备环境DC兼容的内存环境DC
3、选用位图对象,兼容DC使用步骤1中所建立的位图对象
4、进行贴图
实例如下:
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,_T("back.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE );
HDC hDcTemp = CreateCompatibleDC(hdc);
SelectObject(hDcTemp,hBitmap);
BITMAP bitInfo;
GetObject(hBitmap,sizeof(BITMAP),&BITMAP);
BitBlt(hdc,0,0,bitInfo.bmWidth,bitInfo.bmHeight,hDcTemp,0,0,SRCCOPY);//SRCCOPY,SRCAND,SRCPAINT 代表资源复制、要绘制的图和原有图对应像素点做与运算、要绘制的图与原有图做或运算
DeleteObject(hBitmap);
DeleteObject(hDcTemp);
透明色,文字的处理设置
hdc = BeginPaint(hWnd, &ps);
HBITMAP hBitmap1 = (HBITMAP)LoadImage(NULL,_T("test.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HDC hDcTemp = CreateCompatibleDC(hdc);
SelectObject(hDcTemp,hBitmap1);
GetObject(hBitmap1,sizeof(BITMAP),&bitInfo);
TransparentBlt(hdc,150,150,bitInfo.bmWidth,bitInfo.bmHeight,hDcTemp,0,0,bitInfo.bmWidth,bitInfo.bmHeight,RGB(237,28,36));//把某一个RGB值变成透明色
DeleteObject(hBitmap1);
DeleteObject(hDcTemp);
SetBkMode(hdc,TRANSPARENT);//设置背景为透明
SetTextColor(hdc,RGB(255,0,0));//设置字体颜色
//HFONT hFont = CreateFont(); //创建字体
LOGFONT font;
memset(&font,0,sizeof(LOGFONT));
font.lfCharSet = HANGUL_CHARSET;//设置字体类型
font.lfWidth = 10 ;//字体宽度
font.lfHeight = 20;//字体高度
font.lfWeight = 900; //字体加粗
font.lfUnderline = 5;//字体下划线
HFONT hFont = CreateFontIndirect(&font);
SelectObject(hdc,hFont);
EndPaint(hWnd, &ps);
hdc = BeginPaint(hWnd, &ps);
HBITMAP hBitmap1 = (HBITMAP)LoadImage(NULL,_T("test.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HDC hDcTemp = CreateCompatibleDC(hdc);
SelectObject(hDcTemp,hBitmap1);
GetObject(hBitmap1,sizeof(BITMAP),&bitInfo);
TransparentBlt(hdc,150,150,bitInfo.bmWidth,bitInfo.bmHeight,hDcTemp,0,0,bitInfo.bmWidth,bitInfo.bmHeight,RGB(237,28,36));//把某一个RGB值变成透明色
DeleteObject(hBitmap1);
DeleteObject(hDcTemp);
SetBkMode(hdc,TRANSPARENT);//设置背景为透明
SetTextColor(hdc,RGB(255,0,0));//设置字体颜色
//HFONT hFont = CreateFont(); //创建字体
LOGFONT font;
memset(&font,0,sizeof(LOGFONT));
font.lfCharSet = HANGUL_CHARSET;//设置字体类型
font.lfWidth = 10 ;//字体宽度
font.lfHeight = 20;//字体高度
font.lfWeight = 900; //字体加粗
font.lfUnderline = 5;//字体下划线
HFONT hFont = CreateFontIndirect(&font);
SelectObject(hdc,hFont);
EndPaint(hWnd, &ps);