GDI+学习笔记9-绘制网站流量报表
AlphaBlend: 图片的Alpha混合贴图
BOOL AlphaBlend(
HDC hdcDest,
int xoriginDest,
int yoriginDest,
int wDest,
int hDest,
HDC hdcSrc,
int xoriginSrc,
int yoriginSrc,
int wSrc,
int hSrc,
BLENDFUNCTION ftn
);
hdcDest:目标DC,
ftn:设置图片混合信息(如透明度)的结构体
typedef struct _BLENDFUNCTION {
BYTE BlendOp;
BYTE BlendFlags;
BYTE SourceConstantAlpha;
BYTE AlphaFormat;
} BLENDFUNCTION, *PBLENDFUNCTION, *LPBLENDFUNCTION;
AlphaBlend的使用,需要设置半透明度的信息。通过BLENDFUNCTION结构体的SourceContantAlpha成员来设置,设置范围为0~255
解决界面闪烁问题:(拉伸窗体时,界面会闪烁):
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
RECT rcClient;
::GetClientRect(hWnd,&rcClient);
HDC hMemDC=::CreateCompatibleDC(hdc);
HBITMAP hBitMap = ::CreateCompatibleBitmap(hdc,rcClient.right-rcClient.left,rcClient.bottom-rcClient.top);
HBITMAP hOldBmp = (HBITMAP)::SelectObject(hMemDC,hBitMap);
// 画背景
PaintImage(hWnd, hMemDC);
// 画文字
PaintString(hWnd,hMemDC);
// 画线
PaintLine(hMemDC);
PaintRect(hMemDC);
PaintEllipse(hMemDC);
PaintPie(hMemDC);
::BitBlt(hdc,0,0,rcClient.right-rcClient.left,
rcClient.bottom-rcClient.top,
hMemDC,0,0,SRCCOPY);
::SelectObject(hMemDC,hOldBmp);
::DeleteObject(hBitMap);
::DeleteObject(hMemDC);
EndPaint(hWnd, &ps);
break;
}
case WM_ERASEBKGND:
{
return 0;
}
BOOL AlphaBlend(
HDC hdcDest,
int xoriginDest,
int yoriginDest,
int wDest,
int hDest,
HDC hdcSrc,
int xoriginSrc,
int yoriginSrc,
int wSrc,
int hSrc,
BLENDFUNCTION ftn
);
hdcDest:目标DC,
ftn:设置图片混合信息(如透明度)的结构体
typedef struct _BLENDFUNCTION {
BYTE BlendOp;
BYTE BlendFlags;
BYTE SourceConstantAlpha;
BYTE AlphaFormat;
} BLENDFUNCTION, *PBLENDFUNCTION, *LPBLENDFUNCTION;
AlphaBlend的使用,需要设置半透明度的信息。通过BLENDFUNCTION结构体的SourceContantAlpha成员来设置,设置范围为0~255
解决界面闪烁问题:(拉伸窗体时,界面会闪烁):
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
RECT rcClient;
::GetClientRect(hWnd,&rcClient);
HDC hMemDC=::CreateCompatibleDC(hdc);
HBITMAP hBitMap = ::CreateCompatibleBitmap(hdc,rcClient.right-rcClient.left,rcClient.bottom-rcClient.top);
HBITMAP hOldBmp = (HBITMAP)::SelectObject(hMemDC,hBitMap);
// 画背景
PaintImage(hWnd, hMemDC);
// 画文字
PaintString(hWnd,hMemDC);
// 画线
PaintLine(hMemDC);
PaintRect(hMemDC);
PaintEllipse(hMemDC);
PaintPie(hMemDC);
::BitBlt(hdc,0,0,rcClient.right-rcClient.left,
rcClient.bottom-rcClient.top,
hMemDC,0,0,SRCCOPY);
::SelectObject(hMemDC,hOldBmp);
::DeleteObject(hBitMap);
::DeleteObject(hMemDC);
EndPaint(hWnd, &ps);
break;
}
case WM_ERASEBKGND:
{
return 0;
}