这个是结果
下面是画法
自己包含头文件
问题是。。 我应该怎么即时释放掉GDI+的资源?
#pragma once
#include "stdafx.h"
using namespace Gdiplus;
WCHAR* ToWChar(char * str)
{
static WCHAR buffer[1024];
_wcsset_s(buffer,0);
MultiByteToWideChar(CP_ACP,0,str,strlen(str),buffer,1024);
return buffer;
}
void DrawFont(HDC mDc,int vague , RECT rect,char * text,char *fontname,int fontsize,Color color,Color shadowcolor,int offset)
{
if (mDc !=NULL && text !=NULL &&fontsize >0)
{
Graphics *g=Graphics ::FromHDC (mDc );
g->SetCompositingQuality (CompositingQualityAssumeLinear);
g->SetSmoothingMode(SmoothingModeAntiAlias);
g->SetTextRenderingHint(TextRenderingHintAntiAlias);
Bitmap bit1(rect .right ,rect .bottom,PixelFormat32bppARGB );
Graphics *g1 =Graphics ::FromImage (&bit1);
g1->SetCompositingQuality (CompositingQualityAssumeLinear);
g1->SetSmoothingMode(SmoothingModeAntiAlias);
g1->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit );
Bitmap bit2(rect .right / vague+strlen (text)/10,rect .bottom / vague ,PixelFormat32bppARGB );
Graphics *g2 =Graphics ::FromImage (&bit2);
g2->SetInterpolationMode(InterpolationModeHighQualityBicubic );
g2->SetPixelOffsetMode(PixelOffsetModeNone );
SolidBrush brush(shadowcolor);
FontFamily fontFamily(ToWChar(fontname ) );
Gdiplus::Font Font(&fontFamily, fontsize ,FontStyleRegular , UnitPoint);//
PointF p(3 ,3 );
g1->DrawString (ToWChar (text ),strlen (text),&Font,p ,&brush );
g1->DrawString (ToWChar (text ),strlen (text),&Font,p ,&brush );
g2->DrawImage (&bit1,0,0,rect .right / vague +strlen (text)/10,rect .bottom / vague );
g1->Clear (0);
g1->DrawImage (&bit2 ,offset,0,rect .right ,rect .bottom);
g1->SetTextRenderingHint (TextRenderingHintAntiAlias);
brush .SetColor (color);
g1->DrawString (ToWChar (text ),strlen (text),&Font,p ,&brush );
g->DrawImage (&bit1 ,rect .left ,rect.top );
}
}
void DrawFrame(HDC mDc,Size st,int Fillet,Color ShineColor,Color InteriorColor,int offset,Size zoom)
{
int Size_w,Size_h;
Size_w =st.Width ;
Size_h =st.Height ;
Graphics g(mDc );
g.SetPixelOffsetMode(PixelOffsetModeHalf );
g.SetSmoothingMode (SmoothingModeAntiAlias );
g.SetCompositingQuality (CompositingQualityHighQuality );
GraphicsPath path;
int r = Fillet ;
int l = 2 * r;
path.AddArc (offset , offset, l, l, 180, 90);
path.AddArc (Size_w - offset - l - zoom.Width , offset, l, l, 270, 90);
path.AddArc (Size_w - offset - l - zoom.Width , Size_h - offset - l - zoom.Height , l, l, 0, 90);
path.AddArc (offset, Size_h - offset - l - zoom.Height , l, l, 90, 90);
path.CloseAllFigures ();
int R=ShineColor .GetR (),G=ShineColor .GetG (),B=ShineColor .GetB ();
Pen p(Color (10,R ,G,B),11);
p.SetWidth (11);
p.SetColor (Color (10,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (9);
p.SetColor (Color (20,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (7);
p.SetColor (Color (40,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (5);
p.SetColor (Color (55,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (3);
p.SetColor (Color (70,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (1);
R= InteriorColor .GetR (),G=InteriorColor .GetG (),B=InteriorColor .GetB ();
p.SetColor (Color (255,R ,G,B));
g.DrawPath (&p,&path);
SolidBrush b(Color (2, 0, 0, 0));
HBRUSH br= CreateSolidBrush (0);
FillRgn (mDc , CreateRoundRectRgn (offset, offset,Size_w - offset + 1, Size_h - offset + 1 - zoom.Height , r + r / 3 * 2, r + r / 3 * 2),br );
g.FillRectangle(&b, offset + 1, offset + 2, Size_w - 1 - offset * 2 - 10 + Fillet, Size_h - 3 - offset * 2 - 10 +Fillet - zoom.Height );//底层图层,防止鼠标穿透
DeleteObject (br);
}