实现文字投影光晕效果--上位机VC 
 
 实现文字投影光晕效果--上位机VC 功能展示 有时,程序界面上部分文字需要点缀效果,如光晕,投影,我们当前例程就实现这一功能,效果如图.点击<展示效果>就会显示指定文字的效果,文字颜色及光晕颜色可以通过例程按钮中变量  intFontColor = 255;int ShadowColor=0;进行设置     要点提示 例程是基于GDI+实现文字光晕或投影效果,在VC6.0中使用GDI+得手动初始化其环境,在更高版本则不用 GDI+使用前分三步初始化 1.在stdafx.h 中包含头文件 //使用GDI+第一步 #define UNICODE #ifndef ULONG_PTR #define ULONG_PTR unsigned long* #endif #include "Include\\gdiplus.h" using namespace Gdiplus;  #pragma comment(lib, "Include\\gdiplus.lib")   
2.程序初始化是初始化GDI+环境 //GDI+第二步   ULONG_PTR     diplusToken;   GdiplusStartupInputgdiplusStartupInput;    
  GdiplusStartup(&diplusToken,&gdiplusStartupInput, NULL); 在程序退出时 关闭环境 //GDI+第三步  
  GdiplusShutdown(diplusToken);  
实现功能 1.新建基于对话框的应用程序 2.复制例程根目录GDI+文件夹Include,并分三步初始化GDI+ //使用GDI+第一步 #define UNICODE #ifndef ULONG_PTR #define ULONG_PTR unsigned long* #endif #include "Include\\gdiplus.h" using namespace Gdiplus;  #pragma comment(lib, "Include\\gdiplus.lib")  //GDI+第二步   ULONG_PTR     diplusToken;   GdiplusStartupInputgdiplusStartupInput;     GdiplusStartup(&diplusToken,&gdiplusStartupInput, NULL);  //GDI+第三步  
  GdiplusShutdown(diplusToken); 3,添加自定义函数void Project (Graphics &g, int Fuzzy, Rect rectPaint, LPCWSTRText, Rect Textrect, Font &TextFont, int FontColor, int ShadowColor)用于实现光晕或投影效果; G为显示文字的设备上下文件, Fuzzy为投影或光晕大小, rectPaint为绘制在矩形, Text为要显示的文字 ,TextFont为文字的字体格式,FontColor为文字 的颜色,ShadowColor为背景颜色; 4.添加一按钮关联点击函数用于调用上面函数,实现效果 - void CMy123Dlg::OnButton1()
 
 - {
 
 -   LOGFONTW lfont; 
 
 -   memset( &lfont, 0, sizeof(lfont) ); 
 
 -   lfont.lfHeight = -130, //   nHeight   注意使用负值,表示character height,  正值表示 cell height 
 
 -   lfont.lfWidth  = 0,  //   nWidth 
 
 -   //0,     //   nEscapement 
 
 -   //0,     //   nOrientation 
 
 -   lfont.lfWeight      = FW_NORMAL,  //nWeight 
 
 -   lfont.lfItalic      = FALSE,      //bItalic 
 
 -   lfont.lfUnderline   = FALSE,   //   bUnderline 
 
 -   lfont.lfStrikeOut   = 0,         //   cStrikeOut 
 
 -   lfont.lfCharSet     = DEFAULT_CHARSET,   //   nCharSet 
 
 -   lfont.lfOutPrecision    = OUT_DEFAULT_PRECIS,//   nOutPrecision 
 
 -   lfont.lfClipPrecision   = CLIP_DEFAULT_PRECIS,  //   nClipPrecision 
 
 -   lfont.lfQuality         = DEFAULT_QUALITY,      //   nQuality 
 
 -   lfont.lfPitchAndFamily  = DEFAULT_PITCH | FF_SWISS,//   nPitchAndFamily 
 
 -   wcscpy( lfont.lfFaceName, (L"微软雅黑") );  //   lpszFacename 
 
 -    CDC *pDC = GetDC();
 
 -   Graphics g(pDC->m_hDC);
 
 -   int Fuzzy =30;
 
 -   CString strFileName="微软雅黑";
 
 -   LPCWSTR Text = strFileName.AllocSysString();
 
 -   Rect Textrect(12,12,555,655);
 
 -   Rect rectPaint(Textrect);
 
 -   rectPaint.Inflate(40,40);
 
 -   Font  TextFont(pDC->m_hDC, &lfont );
 
 -   int FontColor = 255;
 
 -   int ShadowColor=0;
 
 -   Project(g,  Fuzzy,  rectPaint,  Text,  Textrect, TextFont,  FontColor,  ShadowColor);
 
 -   ReleaseDC(pDC);
 
 - }
 
 
  复制代码 
 
我们来演示下功能实现的整个过程   如果您认可,可联系功能定制!   如果您着急,充值会员可直接联系发您资料!              
 |