关于GDI+在win7 下绘制文字正常 在xp下绘制文字无法显示问题,请教大神,在线等!!!一共有300分,解决问题全给你

loveanybody 2013-12-26 12:28:09
目的是在MFC下png实现不规则窗体上绘制文字
文字绘制如下:
void CLoginDialog::DrawUI()
{
HDC hDC=::GetDC(m_hWnd);
HDC hMemDC=::CreateCompatibleDC(hDC);

BITMAPINFO bitmapinfo;
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo.bmiHeader.biBitCount = 32;
bitmapinfo.bmiHeader.biHeight = m_pSrcImage->GetHeight();
bitmapinfo.bmiHeader.biWidth = m_pSrcImage->GetWidth();
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biCompression=BI_RGB;
bitmapinfo.bmiHeader.biXPelsPerMeter=0;
bitmapinfo.bmiHeader.biYPelsPerMeter=0;
bitmapinfo.bmiHeader.biClrUsed=0;
bitmapinfo.bmiHeader.biClrImportant=0;
bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth * bitmapinfo.bmiHeader.biHeight * bitmapinfo.bmiHeader.biBitCount / 8;

HBITMAP hBitmap=::CreateDIBSection (hMemDC,&bitmapinfo, 0,NULL, 0, 0);
HBITMAP hOldBitmap = (HBITMAP)::SelectObject (hMemDC,hBitmap);

//画出各个界面元素----------------------
Graphics g(hMemDC);
g.DrawImage(m_pSrcImage,RectF(0,0,m_pSrcImage->GetWidth(),m_pSrcImage->GetHeight()),0,0,m_pSrcImage->GetWidth(),m_pSrcImage->GetHeight(),UnitPixel,NULL,NULL,NULL);

FontFamily* fontFamily = new FontFamily(L"微软雅黑");//选择一种字体

Gdiplus::SolidBrush* company_brush = new Gdiplus::SolidBrush(Color(255,24,120,197));
Gdiplus::Font* company_font = new Gdiplus::Font(fontFamily,11,FontStyleRegular,UnitPoint);
g.DrawString(L"Hello Word!",-1,company_font,PointF(335,346),company_brush);

delete fontFamily;
delete company_brush;
delete company_font;

//设置透明窗口-------------------------------------------------
CPoint DestPt(0,0);
CSize psize(m_pSrcImage->GetWidth(),m_pSrcImage->GetHeight());
BLENDFUNCTION blendFunc32bpp;
blendFunc32bpp.AlphaFormat = AC_SRC_ALPHA;
blendFunc32bpp.BlendFlags = 0;
blendFunc32bpp.BlendOp = AC_SRC_OVER;
blendFunc32bpp.SourceConstantAlpha = 255;
::UpdateLayeredWindow(m_hWnd,hDC,NULL,&psize,hMemDC,&DestPt,0,&blendFunc32bpp,ULW_ALPHA);
//释放资源-------------------------------------------------
::SelectObject (hMemDC,hOldBitmap);
::DeleteObject(hBitmap);
::DeleteDC(hMemDC);
::ReleaseDC(m_hWnd,hDC);
}
...全文
82 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveanybody 2013-12-26
  • 打赏
  • 举报
回复
问题解决了,是因为我用了png透明背景结果画在上面的字被背景透过去了,解决问题的方法是:GraphicsPath path; path.AddString; g->FillPath( brush, path); 就可以了。感谢捧场 分数给你了。

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧