GDI+桌面歌词 BCB版
jaffy 2011-05-31 11:04:20 前些天看到一个DELPHI的桌面歌词,用的是IGDI的接口,我用了一下那个接口,对DELPHI挺方便的;
但自我感觉还没有MAOZEFA封装的库好用;这两天找了时间写了这个程序,分别用的就是MAOZEFA的GDI+库,和妖哥的Gdiplus库
这里给出主要函数的源码,需要全部源码的去我空间下载吧!
bool __fastcall TForm1::UpdateDisplay(WideString pszbuf,bool bBack,int Transparent)
{
HDC hdcTemp,hdcScreen,m_hdcMemory;
HBITMAP hBitMap;
BLENDFUNCTION blend;
TPoint ptWinPos,ptSrc;
SIZE sizeWindow;
hdcTemp = GetDC(this->Handle);
m_hdcMemory = CreateCompatibleDC(hdcTemp);
hBitMap = CreateCompatibleBitmap(hdcTemp,755,350);
SelectObject(m_hdcMemory,hBitMap);
if ((Transparent < 0) ||(Transparent > 100))
Transparent = 100;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
blend.SourceConstantAlpha = int(Transparent * 2.55);;
hdcScreen = GetDC(this->Handle);
TRect rct;
GetWindowRect(this->Handle,&rct);
ptWinPos.x = rct.Left;
ptWinPos.y = rct.Top;
TGpGraphics *graphics = new TGpGraphics(m_hdcMemory);
graphics->SmoothingMode = SmoothingModeAntiAlias; //指定平滑(抗锯齿)
graphics->InterpolationMode = InterpolationModeHighQualityBicubic;//指定的高品质,双三次插值
TGpFontFamily *fontFamily = new TGpFontFamily(WideString("宋体")); //△字体,效果图为'微软雅黑'字体
TGpStringFormat *strFormat = new TGpStringFormat();
TGpGraphicsPath *path = new TGpGraphicsPath();
path->AddString(pszbuf,fontFamily,TFontStyles()<<fsBold,38,TGpPoint(10,10),strFormat);
TGpPen *pen = new TGpPen(TGpColor(155,215,215,215),3);
graphics->DrawPath(pen,path);
TGpLinearGradientBrush *linGrBrush;
linGrBrush = new TGpLinearGradientBrush(TGpPoint(0,0), //线性渐变起始点
TGpPoint(0,90), //线性渐变终结点
TGpColor(255,255,255,255), //线性渐变起始色
TGpColor(255,30,120,195));
TGpLinearGradientBrush *linGrBrushW;
linGrBrushW = new TGpLinearGradientBrush(TGpPoint(0,10),
TGpPoint(0,60),
TGpColor(255,255,255,255),
TGpColor(15,1,1,1));
//---------------------开始:画字符串阴影--------------------------------------
for(int i=0;i<8;i++)
{
pen->Width = i+1;
pen->Color = TGpColor(62, 0, 2,2);
pen->LineJoin = LineJoinRound;
graphics->DrawPath(pen,path);
}
//---------------------开始:画背景框和背景图----------------------------------
if(bBack)
{
TGpSolidBrush *brush = new TGpSolidBrush(TGpColor(25,228,228,228));
TGpPen *pen1 = new TGpPen(TGpColor(155, 223, 223,223),3);
TGpPen *pen2 = new TGpPen(TGpColor(55, 223, 223,223),3);
TGpImage *Image = new TGpImage("back.png");
graphics->FillRectangle(brush,3,5,750,90);
graphics->DrawRectangle(pen1,2,6,751,91);
graphics->DrawRectangle(pen2,1,5,753,93);
graphics->DrawImage(Image,600,25);
}
graphics->FillPath(linGrBrush,path);
graphics->FillPath(linGrBrushW,path);
sizeWindow.cx = 755;
sizeWindow.cy = 350;
ptSrc.x = 0;
ptSrc.y = 0;
UpdateLayeredWindow(this->Handle,hdcScreen,&ptWinPos,&sizeWindow,m_hdcMemory,
&ptSrc,0,&blend,ULW_ALPHA);
ReleaseDC(this->Handle,hdcScreen);
ReleaseDC(this->Handle,hdcTemp);
DeleteObject(hBitMap);
DeleteDC(m_hdcMemory);
return true;
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::UpdateDisplay(WideString pszbuf,bool bBack,int Transparent)
{
HDC hdcTemp,hdcScreen,m_hdcMemory;
HBITMAP hBitMap;
BLENDFUNCTION blend;
TRect rct;
TPoint ptWinPos,ptSrc;
SIZE sizeWindow;
hdcTemp = GetDC(Handle);
m_hdcMemory = CreateCompatibleDC(hdcTemp);
hBitMap = CreateCompatibleBitmap(hdcTemp,755,350);
SelectObject(m_hdcMemory,hBitMap);
if ((Transparent < 0) ||(Transparent > 100))
Transparent = 100;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
blend.SourceConstantAlpha = ceil(Transparent * 2.55);
hdcScreen = GetDC(Handle);
GetWindowRect(Handle,&rct);
ptWinPos.x = rct.Left;
ptWinPos.y = rct.Top;
Gdiplus::Graphics graphics(m_hdcMemory);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); //指定平滑(抗锯齿)
graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);//指定的高品质,双三次插值
Gdiplus::FontFamily fontFamily(WideString("宋体")); //△字体,效果图为'微软雅黑'字体
Gdiplus::StringFormat strFormat;
Gdiplus::GraphicsPath path;
path.AddString(pszbuf, -1, &fontFamily, 0,38,PointF(10,10),&strFormat);
Gdiplus::Pen pen(Gdiplus::Color(155, 215, 215,215),3);
graphics.DrawPath(&pen,&path);
Gdiplus::LinearGradientBrush linGrBrush(Gdiplus::Point(0,0),Gdiplus::Point(0,90)
,Gdiplus::Color(255,255,255,255),Gdiplus::Color(255,30,120,195)); //线性渐变起始色
Gdiplus::LinearGradientBrush linGrBrushW(Gdiplus::Point(0,10),Gdiplus::Point(0,60)
,Gdiplus::Color(255,255,255,255),Gdiplus::Color(15,1,1,1));
//---------------------开始:画字符串阴影--------------------------------------
for(int i=0;i<8;i++)
{
pen.SetWidth(i+1);
pen.SetColor(Gdiplus::Color(62, 0, 2,2));
pen.SetLineJoin(LineJoinRound);
graphics.DrawPath(&pen,&path);
}
//---------------------开始:画背景框和背景图----------------------------------
if(bBack)
{
Gdiplus::SolidBrush brush(Gdiplus::Color(25,228,228,228));
Gdiplus::Pen pen1(Gdiplus::Color(155, 223, 223,223),3);
Gdiplus::Pen pen2(Gdiplus::Color(55, 223, 223,223),3);
Image *image;
image = Gdiplus::Image::FromFile(L"back.png");
graphics.FillRectangle(&brush,3,5,750,90);
graphics.DrawRectangle(&pen1,2,6,751,91);
graphics.DrawRectangle(&pen2,1,5,753,93);
graphics.DrawImage(image,600,25);
}
graphics.FillPath(&linGrBrush,&path);
graphics.FillPath(&linGrBrushW,&path);
sizeWindow.cx = 755;
sizeWindow.cy = 350;
ptSrc.x = 0;
ptSrc.y = 0;
UpdateLayeredWindow(Handle,hdcScreen,&ptWinPos,&sizeWindow,m_hdcMemory,
&ptSrc,0,&blend,ULW_ALPHA);
ReleaseDC(0,hdcScreen);
ReleaseDC(0,hdcTemp);
DeleteObject(hBitMap);
DeleteDC(m_hdcMemory);
return true;
}
//---------------------------------------------------------------------------