GDI+ PNG背景透明窗口 初始化调用一次 必须有layer属性,image*注意赋值

本文介绍了一个使用MFC框架的对话框类CMFCApplication1Dlg中的DrawUI方法实现过程。该方法通过获取窗口尺寸、创建设备上下文、位图等步骤来绘制UI元素,并利用GDI+库进行复杂图形绘制,如椭圆填充与字符串显示。
摘要由CSDN通过智能技术生成
void CMFCApplication1Dlg::DrawUI()
{
CRect rect;
GetWindowRect(rect);
HDC dc = ::GetDC(m_hWnd);
HDC memdc = CreateCompatibleDC(dc);
HDC bmpdc = CreateCompatibleDC(dc);
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*)img;
BITMAPINFO bitmapinfo;
bitmapinfo.bmiHeader.biBitCount = 32;
bitmapinfo.bmiHeader.biClrImportant = 0;
bitmapinfo.bmiHeader.biClrUsed = 0;
bitmapinfo.bmiHeader.biCompression = BI_RGB;
bitmapinfo.bmiHeader.biWidth = rect.Width();
bitmapinfo.bmiHeader.biHeight = rect.Height();
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth*bitmapinfo.bmiHeader.biHeight*bitmapinfo.bmiHeader.biBitCount/8;
bitmapinfo.bmiHeader.biXPelsPerMeter = 0;
bitmapinfo.bmiHeader.biYPelsPerMeter = 0;
HBITMAP hbitmap = ::CreateDIBSection(memdc,&bitmapinfo,DIB_RGB_COLORS,NULL,0,0);
HBITMAP oldbit = (HBITMAP)::SelectObject(memdc,hbitmap);
Graphics g(memdc);
CRect r;
GetWindowRect(r);
Bitmap* bmp1 = (Bitmap*)img;  
HBITMAP hBitmap=NULL;  
Color color(255,255,255,255);  
bmp1->GetHBITMAP(color,&hBitmap);


::SelectObject(bmpdc,hBitmap);


BLENDFUNCTION blendFunc32bpp;
blendFunc32bpp.AlphaFormat = AC_SRC_ALPHA;
blendFunc32bpp.BlendFlags = 0;
blendFunc32bpp.BlendOp = AC_SRC_OVER;
blendFunc32bpp.SourceConstantAlpha = 200;


::SelectObject(bmpdc,hbitmap);
AlphaBlend(memdc,0,0,r.Width(),r.Height(),bmpdc,0,0,img->GetWidth(),img->GetHeight(),blendFunc32bpp);
Graphics graphics(memdc);
Gdiplus::SolidBrush blackBrush(Color(255, 0, 0, 0));


// Create the RectF object that defines the ellipse.
RectF ellipseRect(0.0f, 0.6f, 1200.8f, 1100.9f);


// Fill the ellipse.
//graphics.FillEllipse(&blackBrush, ellipseRect);
// Create a string.
CString string = L"发生的发的发生的发的是发生的发生";
// Initialize arguments.
Gdiplus::Font myFont(L"Arial", 16);
Gdiplus::PointF origin(0.0f, 0.0f);
// SolidBrush blackBrush(Color(255, 0, 0, 0));


// Draw string.
graphics.DrawString(
string,
string.GetLength(),
&myFont,
origin,
&blackBrush);


CPoint DestPt(0,0);
CSize psize(rect.Width(),rect.Height());
blendFunc32bpp.SourceConstantAlpha =255;
::UpdateLayeredWindow(m_hWnd,dc,NULL,&psize,memdc,&DestPt,0,&blendFunc32bpp,ULW_ALPHA);
SelectObject(memdc,oldbit);
::ReleaseDC(m_hWnd,memdc);


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值