1.创建一个基于对话框的MFC应用:

发光字示列:

gdi+代码:

#include <gdiplus.h>
#pragma comment(lib,"GdiPlus.lib")
ULONG_PTR m_gdiplusToken;
using namespace Gdiplus;
#define white 0xffffff
#define guls 0xff
void ShadoTxt(HWND hWnd, LPCWSTR Text, int X, int Y, int Width, int Height, TCHAR *FontStr,int FonSize, int FontColor, int ShadowColor)
{Graphics *g = Graphics::FromHDC(::GetWindowDC(hWnd));Bitmap Bit1(Width, Height);Graphics g1(&Bit1);g1.SetSmoothingMode(SmoothingModeAntiAlias);g1.SetTextRenderingHint(TextRenderingHintAntiAlias);g1.SetCompositingQuality(CompositingQualityAssumeLinear);Bitmap Bit2(Width / 10/*模糊半径*/, Height / 10);Graphics g2(&Bit2);g2.SetInterpolationMode(InterpolationModeHighQualityBicubic);g2.SetPixelOffsetMode(PixelOffsetModeNone);//布局int cb = ShadowColor / 65536;int cg = (ShadowColor - cb * 65536) / 256;int cr = ShadowColor - (cb * 65536) - (cg * 256);SolidBrush B(Color(255, cr, cg, cb));GraphicsPath path;FontFamily    ftFamily(FontStr);Gdiplus::Font TextFont(&ftFamily, FonSize, FontStyleBold, UnitPixel);Rect Textrect;Textrect.X = X;Textrect.Y = Y;Textrect.Width = Width;Textrect.Height = Height;path.AddString(Text, -1, &ftFamily, (int)(FontStyleBold), TextFont.GetSize(), Textrect, NULL);g1.FillPath(&B, &path);//绘制文字g2.DrawImage(&Bit1, 0, 0, Width / 10, Height / 10);g1.Clear(Color(0));g1.DrawImage(&Bit2, 0, 0, Width, Height);g1.SetTextRenderingHint(TextRenderingHintAntiAlias);//发光字底图GraphicsPath path1;path1.AddString(Text, -1, &ftFamily, (int)(FontStyleBold), TextFont.GetSize(), Textrect, NULL/* new StringFormat()*/);cb = FontColor / 65536;cg = (FontColor - cb * 65536) / 256;cr = FontColor - (cb * 65536) - (cg * 256);B.SetColor(Color(255, cr, cg, cb));g1.FillPath(&B, &path1);//绘制文字g->DrawImage(&Bit1, X, Y);//释放资源DeleteObject(g);
}

调用代码:

    /*初始化gdi*/Gdiplus::GdiplusStartupInput StartupInput;GdiplusStartup(&m_gdiplusToken, &StartupInput, NULL);/**/ShadoTxt(m_hWnd, L"hello Word", 40, 40, 300, 200, L"微软雅黑", 30, white, guls);

效果:

全部代码:

#include <gdiplus.h>
#pragma comment(lib,"GdiPlus.lib")
ULONG_PTR m_gdiplusToken;
using namespace Gdiplus;
#define white 0xffffff
#define guls 0xff
void ShadoTxt(HWND hWnd, LPCWSTR Text, int X, int Y, int Width, int Height, TCHAR *FontStr,int FonSize, int FontColor, int ShadowColor)
{Graphics *g = Graphics::FromHDC(::GetWindowDC(hWnd));Bitmap Bit1(Width, Height);Graphics g1(&Bit1);g1.SetSmoothingMode(SmoothingModeAntiAlias);g1.SetTextRenderingHint(TextRenderingHintAntiAlias);g1.SetCompositingQuality(CompositingQualityAssumeLinear);Bitmap Bit2(Width / 10/*模糊半径*/, Height / 10);Graphics g2(&Bit2);g2.SetInterpolationMode(InterpolationModeHighQualityBicubic);g2.SetPixelOffsetMode(PixelOffsetModeNone);//布局int cb = ShadowColor / 65536;int cg = (ShadowColor - cb * 65536) / 256;int cr = ShadowColor - (cb * 65536) - (cg * 256);SolidBrush B(Color(255, cr, cg, cb));GraphicsPath path;FontFamily    ftFamily(FontStr);Gdiplus::Font TextFont(&ftFamily, FonSize, FontStyleBold, UnitPixel);Rect Textrect;Textrect.X = X;Textrect.Y = Y;Textrect.Width = Width;Textrect.Height = Height;path.AddString(Text, -1, &ftFamily, (int)(FontStyleBold), TextFont.GetSize(), Textrect, NULL);g1.FillPath(&B, &path);//绘制文字g2.DrawImage(&Bit1, 0, 0, Width / 10, Height / 10);g1.Clear(Color(0));g1.DrawImage(&Bit2, 0, 0, Width, Height);g1.SetTextRenderingHint(TextRenderingHintAntiAlias);//发光字底图GraphicsPath path1;path1.AddString(Text, -1, &ftFamily, (int)(FontStyleBold), TextFont.GetSize(), Textrect, NULL/* new StringFormat()*/);cb = FontColor / 65536;cg = (FontColor - cb * 65536) / 256;cr = FontColor - (cb * 65536) - (cg * 256);B.SetColor(Color(255, cr, cg, cb));g1.FillPath(&B, &path1);//绘制文字g->DrawImage(&Bit1, X, Y);//释放资源DeleteObject(g);
}void onclick(){
/*初始化gdi*/Gdiplus::GdiplusStartupInput StartupInput;GdiplusStartup(&m_gdiplusToken, &StartupInput, NULL);/**/ShadoTxt(m_hWnd, L"hello Word", 40, 40, 300, 200, L"微软雅黑", 30, white, guls);
}

2.绘制窗口示列

注意这里绘制窗口实际上是绘制一个方框,它需要一个hdc画布。

这里不是真正的去创建一个窗口,而是在画布上画一个方框,在经过gdi+处理一下。

绘制代码:

void DrawFrame(HDC mDc/*hdc*/, Size  st/*窗口尺寸*/, int Fillet/*圆角*/, Color ShineColor/*边框外阴影*/, Color InteriorColor/*边框内阴影*/,COLORREF WindowsBgColor,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(WindowsBgColor);   //内部颜色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);
}

用法:

    /*初始化gdi*/Gdiplus::GdiplusStartupInput StartupInput;GdiplusStartup(&m_gdiplusToken, &StartupInput, NULL);CDC* pORIDC = GetDC();HDC hdc = pORIDC->GetSafeHdc();Size s;s.Width = 300;s.Height = 300;Size d;d.Width = 0;d.Height = 0;Color s1;DrawFrame(hdc, s, 10, 500, 500, 0xdf58,5, d);

效果:

将文字画法与窗口结合:

代码:

    /*初始化gdi*/Gdiplus::GdiplusStartupInput StartupInput;GdiplusStartup(&m_gdiplusToken, &StartupInput, NULL);CDC* pORIDC = GetDC();HDC hdc = pORIDC->GetSafeHdc();Size s;s.Width = 300;s.Height = 300;Size d;d.Width = 0;d.Height = 0;Color s1;DrawFrame(hdc, s, 10, 500, 500, 0xdf58,5, d);ShadoTxt(m_hWnd, L"hello Word", 40, 40, 300, 200, L"微软雅黑", 30, white, guls);

效果:

Windows核心编程MFC_gdi+发光字相关推荐

  1. 《Windows核心编程(第5版•英文版)》暨《深入理解.NET(第2版•英文版)》有奖书评/读书笔记征集活动

    <Windows核心编程(第5版•英文版)>暨<深入理解.NET(第2版•英文版)>有奖书评/读书笔记征集活动 图灵公司自成立以来,得到了CSDN的很多专家和朋友的帮助.为了感 ...

  2. 结束处理程序——Windows核心编程学习手札之二十三

    结束处理程序 --Windows核心编程学习手札之二十三 使用SEH可以只关注程序要完成任务,而运行中发生的错误,系统将会发现并通知.Windows引入SHE是为了便于操作系统的开发,使用SHE所造成 ...

  3. Windows 核心编程研究系列之二 读取指定物理内存地址中的内容

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! [原创/ ...

  4. 《windows核心编程系列》二谈谈ANSI和Unicode字符集

    第二章:字符和字符串处理 使用vc编程时项目-->属性-->常规栏下我们可以设置项目字符集合,它可以是ANSI(多字节)字符集,也可以是unicode字符集.一般情况下说Unicode都是 ...

  5. 《windows核心编程系列》十八谈谈windows钩子

    windows应用程序是基于消息驱动的.各种应用程序对各种消息作出响应从而实现各种功能. windows钩子是windows消息处理机制的一个监视点,通过安装钩子能够达到监视指定窗体某种类型的消息的功 ...

  6. chHANDLE_DLGMSG(windows核心编程)讲解

    看完<Windows程序设计>后开始看<windows核心编程>, 结果看第一个案例的时候就很惊人的发现,Jeffery大牛的代码很深奥.乍一看好像没有包含<window ...

  7. C#学习路线:C#入门经典 -> CLR VIA C# -> WINDOWS核心编程

    C#入门经典:入门阶段 CLR VIA C#:理论基础 WINDOWS核心编程:理论提升

  8. 窗口消息——Windows核心编程学习手札之二十六

    窗口消息 --Windows核心编程学习手札之二十六 Windows允许一个进程至多建立10000个不同类型的用户对象(user object):图符.光标.窗口类.菜单.加速键表等,当一个线程调用一 ...

  9. 未处理异常和C++异常——Windows核心编程学习手札之二十五

    未处理异常和C++异常 --Windows核心编程学习手札之二十五 当一个异常过滤器返回EXCEPTION_CONTINUE_SEARCH标识符时是告诉系统继续上溯调用树,寻找另外的异常过滤器,但当每 ...

最新文章

  1. R语言数据热力图绘制实战(基于原生R函数、ggplot2包、plotly包)
  2. 将null转换成数组_把数组里面的值为 null 的转换为字符串 - - ,你们的方法都是什么呢?...
  3. CentOS 6 rpm方式安装mysql
  4. redis 主从复制 [转]
  5. 360私有云平台-HULK 5岁啦~
  6. 材料真的是朝阳行业吗?
  7. Bailian2915 字符串排序【排序】
  8. 杭电OJ分类题目(2)
  9. 如何用iMazing来管理ios设备音频文件
  10. C语言中字符串存储方法
  11. Java开发童年小游戏
  12. Vue - 图片放大镜(vue-piczoom)
  13. 音视频编解码之路:JPEG编码
  14. mysql冗余_如何合理使用数据库冗余字段的方法
  15. laragon mysql版本_laragon mysql8 安装
  16. 在win10+VS2019上编译支持Vulkan SDK的ncnn
  17. 使用google map v3 api 开发地图服务
  18. 施工部署主要不包括_施工部署包括哪些?
  19. oracle oca课程,Oracle OCA教材.pdf
  20. 解决 Mysql 1366 错误

热门文章

  1. mysql引擎 实际应用_MySQL数据库中的三个引擎
  2. ubuntu linux配置bond 网卡绑定 多个bond配置多网关
  3. History命令的显示带时间
  4. Idea中,Terminal 无法联接window终端解决
  5. 计算机应用水平考试dream,2016年职称计算机Dreamwaver使用教程:操作环境
  6. 服务器电源控制芯片,服务器电源中的PFC控制芯片HA16141的应用.pdf
  7. java 静态内部类 内部类_Java中内部类和静态内部类的区别
  8. 计算机管理创建新用户,win7系统添加新用户名的方法和win7系统计算机管理中没有本地用户和组的解决方法...
  9. linux 开机加载的文档,Linux 修改文档“打开方式”
  10. java 乱码 号处理器_java处理中日文字符串的乱码问题