源代码:http://download.csdn.net/detail/nuptboyzhb/4219669

源代码:

1.       插入一个对话框的资源,删除默认控件,并为对话框创建一个类,命名为ClyricDlg;

2.       在对话框的头文件中添加GDI+相关的头文件和动态库

#define UNICODE

#ifndef ULONG_PTR

#define ULONG_PTR unsigned long*

#endif

#include "GDIPlus\\Includes\\GdiPlus.h"   ////Modify your path

using namespace Gdiplus;

#pragma comment(lib, "GDIPlus\\Lib\\gdiplus.lib") //Modify your lib path

3.       新增公有成员变量:

int m_kind;

int cx;

BOOL UpdateDisplay(int Transparent=255);

HINSTANCE hFuncInst ;

typedef BOOL (WINAPI *MYFUNC)(HWND,HDC,

POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);

MYFUNC UpdateLayeredWindow;

BLENDFUNCTION m_Blend;

HDC m_hdcMemory;

4.       新增私有成员变量:

BOOL m_bBack;

GdiplusStartupInput gdiplusStartupInput;

ULONG_PTR           gdiplusToken;

5.       在构造函数中初始化如下成员变量:

m_bBack=false;

m_kind=cx=0;

GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

6.       为对话框添加OnCreate函数,并编辑代码如下:

hFuncInst = LoadLibrary("User32.DLL");

BOOL bRet=FALSE;

if(hFuncInst)

UpdateLayeredWindow=(MYFUNC)GetProcAddress(hFuncInst, "UpdateLayeredWindow");

else

{

AfxMessageBox("User32.dll ERROR!");

exit(0);

}

// Initialize GDI+.

m_Blend.BlendOp=0; //theonlyBlendOpdefinedinWindows2000

m_Blend.BlendFlags=0; //nothingelseisspecial...

m_Blend.AlphaFormat=1; //...

m_Blend.SourceConstantAlpha=255;//AC_SRC_ALPHA

7.       实现其成员函数UpdataDisplay

  1. BOOL CLyricDlg::UpdateDisplay(int Transparent)
  2. {
  3. //获得DC,创建兼容DC
  4. HDC hdcTemp=GetDC()->m_hDC;
  5. m_hdcMemory=CreateCompatibleDC(hdcTemp);
  6. HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp,755,350);
  7. SelectObject(m_hdcMemory,hBitMap);
  8. //设置透明度最大值为100
  9. if(Transparent<0||Transparent>100)      Transparent=100;
  10. //将透明度参数,传递给BLENDFUNCTION;
  11. m_Blend.SourceConstantAlpha=int(Transparent*2.55);//1~255
  12. RECT rct;
  13. //获取窗口的屏幕位置
  14. GetWindowRect(&rct);
  15. //窗口左上角的坐标
  16. POINT ptWinPos={rct.left,rct.top};
  17. //创建2个兼容DC的画笔,Graphics类在GDI+中定义
  18. Graphics graph(m_hdcMemory);
  19. Graphics graphics(m_hdcMemory);
  20. //设置平滑模式
  21. graphics.SetSmoothingMode(SmoothingModeAntiAlias);
  22. graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  23. //设置字体,FontFamily也在GDI+中定义
  24. FontFamily fontFamily(L"Arial Black");
  25. StringFormat strformat;
  26. //获取系统时间
  27. CTime time=CTime::GetCurrentTime();
  28. CString timestr=time.Format("%H-%M-%M");
  29. wchar_t pszbuf[][80]={{L"http://blog.csdn.net/nuptboyzhb"},
  30. {L"南京邮电大学郑海波"},
  31. {L"I wish you will lead a  happy life!"},
  32. {L"zhb931706659@126.com"},
  33. {L"NUPT"}
  34. };
  35. //创建一个画笔的路径
  36. GraphicsPath path;
  37. path.AddString(pszbuf[m_kind],wcslen(pszbuf[m_kind]),&fontFamily,
  38. FontStyleRegular,38,Point(10,10),&strformat);
  39. //创建一支画笔
  40. Pen pen(Color(155,215,215,215),3);
  41. //画笔画出已经创建的路径
  42. graphics.DrawPath(&pen,&path);
  43. /*画出字体的边缘部分*/
  44. for(int i=1; i<9; i+=1)
  45. {
  46. Pen pen(Color(62, 0, 2, 2),(float)i);
  47. pen.SetLineJoin(LineJoinRound);
  48. graphics.DrawPath(&pen, &path);
  49. }
  50. SolidBrush brush(Color(25,228,228,228));
  51. Pen pen1(Color(155,223,223,223));
  52. Pen pen2(Color(55,223,223,223));
  53. Image image(L"1.png");
  54. if(m_bBack)//画背景和图片
  55. {
  56. graphics.FillRectangle(&brush,3,5,750,90);
  57. graphics.DrawRectangle(&pen1,2,6,751,91);
  58. graphics.DrawRectangle(&pen2,1,5,753,93);
  59. graphics.DrawImage(&image,600,5);
  60. }
  61. //创建线性渐变画刷
  62. LinearGradientBrush linGrBrush(
  63. Point(0,0),Point(0,90),
  64. Color(255,255,255,255),
  65. Color(255,30,120,195));
  66. LinearGradientBrush linGrBrushW(
  67. Point(0,10),Point(0,60),
  68. Color(255,255,255,255),
  69. Color(15,1,1,1));
  70. //用线性渐变画刷填充路径
  71. graphics.FillPath(&linGrBrush,&path);
  72. graphics.FillPath(&linGrBrushW,&path);
  73. //设置窗口的风格
  74. DWORD dwExStyle=GetWindowLong(m_hWnd,GWL_EXSTYLE);
  75. if((dwExStyle&0x80000)!=0x80000)
  76. SetWindowLong(m_hWnd,GWL_EXSTYLE,dwExStyle^0x80000);
  77. //更新窗口层
  78. SIZE sizeWindow={755,350};
  79. POINT ptSrc={0,0};
  80. BOOL bRet=FALSE;
  81. HDC hdcScreen=::GetDC (m_hWnd);
  82. //UpdateLayeredWindow功能是更新一个窗口的位置、大小、形状、内容和透明度
  83. bRet= UpdateLayeredWindow( m_hWnd,hdcScreen,&ptWinPos,
  84. &sizeWindow,m_hdcMemory,&ptSrc,0,&m_Blend,2);
  85. graph.ReleaseHDC(m_hdcMemory);
  86. ::ReleaseDC(m_hWnd,hdcScreen);
  87. hdcScreen=NULL;
  88. ::ReleaseDC(m_hWnd,hdcTemp);
  89. hdcTemp=NULL;
  90. DeleteObject(hBitMap);
  91. DeleteDC(m_hdcMemory);
  92. m_hdcMemory=NULL;
  93. return bRet;
  94. }

8.       添加OnTimer(UINT nIDEvent)消息响应函数,编辑代码如下:

cx+=1;

if(cx>20)

{

m_kind++;

m_bBack=false;

UpdateDisplay();

cx=0;

}

if(m_kind>3)

m_kind=0;

9.       编辑OnInitDialog()函数

// TODO: Add extra initialization here

UpdateDisplay();

SetTimer(1,50,NULL);

MFC用GDI+动感歌词的制作的更多相关文章

  1. MFC 用gdi绘制填充多边形区域

    MFC 用gdi绘制填充多边形区域 这里的代码是实现一个三角形的绘制,并用刷子填充颜色 在OnPaint()函数里面 运用的是给定的三角形的三个点,很多个点可以绘制多边形 CBrush br(RGB( ...

  2. mfc配置GDI+有106个错误

    mfc配置GDI+有106个错误,处理如下,参考http://bbs.csdn.net/topics/380054079 一开始#include...放在stdafx.h里有错误,后来上面修改好了,放 ...

  3. VS2010 MFC 使用GDI+给图片添加汉字

    1.配置GDI+ VS2010自带GDI+,直接使用. (1)首先要添加头文件和库 #pragma comment( lib, "gdiplus.lib" ) #include & ...

  4. MFC和GDI+一起使用

    VS2010,新建MFC项目,在头文件stdafx.h中添加: #include <gdiplus.h> using namespace Gdiplus; #pragma comment ...

  5. 基于MFC的Media Player播放器制作的SetTimer函数介绍

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. SetTimer是一种API函数,位于user32.dll中.你想每隔一段时间执行一件事的的时候,你可以使用它. 使用定时器的方法比 较简 ...

  6. MFC GDI绘图基础

    一.关于GDI的基本概念 什么是GDI? Windows绘图的实质就是利用Windows提供的图形设备接口GDI(Graphics Device Interface)将图形绘制在显示器上. 在Wind ...

  7. scxml 图像展示器 (基于C++ MFC GDI tinyxpath的实现)

    以前的时候学习新东西没有总结的习惯,周末把以前研究的东西翻了翻,稍微总结下. Scxml是w3c出来的基于状态机的对话脚本语言标准,具体内容可以谷歌到,这里讲述自己开发的一个把scxml转化为可交互图 ...

  8. 巧妙运用Camtasia制作爱豆的动感影集

    对于追星族来说,收集爱豆的图片.视频是日常必做的事情,而对于进阶型的追星族来说,为爱豆自制各种精美的视频.影集等,会让自己追星之路显得更为充实. 我们可以借助Camtasia教程录制软件为爱豆制作各种 ...

  9. GDI+编程说明及小结

    原文地址:http://blog.csdn.net/byxdaz/article/details/5972759 GDI+(Graphics Device Interface Plus图形设备接口加) ...

随机推荐

  1. caffe神经网络框架的辅助工具(将图片转换为leveldb格式)

    caffe中负责整个网络输入的datalayer是从leveldb里读取数据的,是一个google实现的很高效的kv数据库. 因此我们训练网络必须先把数据转成leveldb的格式. 这里我实现的是把一 ...

  2. struts2中根对象以及ognl .

    Struts2中的OGNL表达式语言是对Xwork的OGNL的封装.我们要理解一下几点: 1. Struts2中将ActionContext作为OGNL的上下文环境(ActionContext内部含有 ...

  3. 一种SpringMVC调用Javascript的方法

    在spring的controller里面,一般是进行业务逻辑的处理,组织数据模型,然后选择适当的显示模版进行展示,这种情况下,我们可以事先做一个js的模版,然后controller根据不同的参数调用此 ...

  4. Android学习笔记:如何高效显示图片,避免内存溢出 和 ImageView无法显示大尺寸的图片

    因为手机的内存资源是有限的,每个app可使用的内存是受限的.而现在采用高分辨率拍的照片往往很大.如果加载时不注意方法,很有可能会引起java.lang.OutofMemoryError: bitmap ...

  5. 180China丨the Agency for Brand Engagement and Experience

    180China丨the Agency for Brand Engagement and Experience Welcome to 180. Welcome to Creativity. Thank ...

  6. Matlab中S函数建立与应用

    function [sys,x0,str,ts] = sfuntmpl(t,x,u,flag) % SFUNTMPL 是M-文件 S函数模板 %  通过剪裁,用户可以生成自己的S函数,不过一定要重新命 ...

  7. 转载python并行运算实例

    Python的并发处理能力臭名昭著.先撇开线程以及GIL方面的问题不说,我觉得多线程问题的根源不在技术上而在于理念.大部分关于Pyhon线程和多进程的资料虽然都很不错,但却过于细节.这些资料讲的都是虎 ...

  8. WPF常用转换

    原文 WPF常用转换 以下是代码中常常用到的一些转换,整理如下,后续再不断完善: 1.string和Color的转换 //string转Color (Color)ColorConverter.Conv ...

  9. shell登录模式及其相应配置文件(转)

    参考<linux命令.编辑器与shell编程>(清华大学出版社) 当启动shell时,它将运行启动文件来初始化自己.具体运行哪个文件取决于该shell是登陆shell还是非登陆shell的 ...

  10. 基于visual Studio2013解决C语言竞赛题之0613递归求积

     题目