<menu id="w8yyk"><menu id="w8yyk"></menu></menu>
  • <dd id="w8yyk"><nav id="w8yyk"></nav></dd>
    <menu id="w8yyk"></menu>
    <menu id="w8yyk"><code id="w8yyk"></code></menu>
    <menu id="w8yyk"></menu>
    <xmp id="w8yyk">
    <xmp id="w8yyk"><nav id="w8yyk"></nav>
  • 網站首頁 > 物聯資訊 > 技術分享

    MFC用GDI+動感歌詞的制作

    2016-09-28 00:00:00 廣州睿豐德信息科技有限公司 閱讀
    睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接

    源代碼: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

    [cpp] view plaincopy
    1. BOOL CLyricDlg::UpdateDisplay(int Transparent)  
    2.   
    3. {  
    4.   
    5. //獲得DC,創建兼容DC  
    6.   
    7. HDC hdcTemp=GetDC()->m_hDC;  
    8.   
    9. m_hdcMemory=CreateCompatibleDC(hdcTemp);  
    10.   
    11. HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp,755,350);  
    12.   
    13. SelectObject(m_hdcMemory,hBitMap);  
    14.   
    15. //設置透明度最大值為100  
    16.   
    17. if(Transparent<0||Transparent>100)      Transparent=100;  
    18.   
    19.     //將透明度參數,傳遞給BLENDFUNCTION;  
    20.   
    21. m_Blend.SourceConstantAlpha=int(Transparent*2.55);//1~255  
    22.   
    23. RECT rct;  
    24.   
    25. //獲取窗口的屏幕位置  
    26.   
    27. GetWindowRect(&rct);  
    28.   
    29. //窗口左上角的坐標  
    30.   
    31. POINT ptWinPos={rct.left,rct.top};  
    32.   
    33.     //創建2個兼容DC的畫筆,Graphics類在GDI+中定義  
    34.   
    35. Graphics graph(m_hdcMemory);  
    36.   
    37. Graphics graphics(m_hdcMemory);  
    38.   
    39.     //設置平滑模式  
    40.   
    41. graphics.SetSmoothingMode(SmoothingModeAntiAlias);  
    42.   
    43. graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);  
    44.   
    45.     //設置字體,FontFamily也在GDI+中定義  
    46.   
    47. FontFamily fontFamily(L"Arial Black");  
    48.   
    49. StringFormat strformat;  
    50.   
    51. //獲取系統時間  
    52.   
    53. CTime time=CTime::GetCurrentTime();  
    54.   
    55. CString timestr=time.Format("%H-%M-%M");  
    56.   
    57. wchar_t pszbuf[][80]={{L"http://blog.csdn.net/nuptboyzhb"},  
    58.   
    59. {L"南京郵電大學鄭海波"},  
    60.   
    61. {L"I wish you will lead a  happy life!"},  
    62.   
    63. {L"zhb931706659@126.com"},  
    64.   
    65. {L"NUPT"}  
    66.   
    67. };  
    68.   
    69.     //創建一個畫筆的路徑  
    70.   
    71. GraphicsPath path;  
    72.   
    73. path.AddString(pszbuf[m_kind],wcslen(pszbuf[m_kind]),&fontFamily,  
    74.   
    75.            FontStyleRegular,38,Point(10,10),&strformat);  
    76.   
    77.     //創建一支畫筆  
    78.   
    79. Pen pen(Color(155,215,215,215),3);  
    80.   
    81.     //畫筆畫出已經創建的路徑  
    82.   
    83. graphics.DrawPath(&pen,&path);  
    84.   
    85. /*畫出字體的邊緣部分*/  
    86.   
    87. for(int i=1; i<9; i+=1)  
    88.   
    89.     {  
    90.   
    91.         Pen pen(Color(62, 0, 2, 2),(float)i);  
    92.   
    93.         pen.SetLineJoin(LineJoinRound);  
    94.   
    95.         graphics.DrawPath(&pen, &path);  
    96.   
    97.     }   
    98.   
    99.   
    100. SolidBrush brush(Color(25,228,228,228));  
    101.   
    102. Pen pen1(Color(155,223,223,223));  
    103.   
    104. Pen pen2(Color(55,223,223,223));    
    105.   
    106. Image image(L"1.png");  
    107.   
    108. if(m_bBack)//畫背景和圖片  
    109.   
    110. {  
    111.   
    112.            graphics.FillRectangle(&brush,3,5,750,90);  
    113.   
    114.            graphics.DrawRectangle(&pen1,2,6,751,91);  
    115.   
    116.            graphics.DrawRectangle(&pen2,1,5,753,93);  
    117.   
    118.            graphics.DrawImage(&image,600,5);  
    119.   
    120. }  
    121.   
    122. //創建線性漸變畫刷  
    123.   
    124. LinearGradientBrush linGrBrush(  
    125.   
    126.            Point(0,0),Point(0,90),  
    127.   
    128.            Color(255,255,255,255),  
    129.   
    130.            Color(255,30,120,195));  
    131.   
    132. LinearGradientBrush linGrBrushW(  
    133.   
    134.            Point(0,10),Point(0,60),  
    135.   
    136.            Color(255,255,255,255),  
    137.   
    138.            Color(15,1,1,1));  
    139.   
    140. //用線性漸變畫刷填充路徑  
    141.   
    142. graphics.FillPath(&linGrBrush,&path);  
    143.   
    144. graphics.FillPath(&linGrBrushW,&path);  
    145.   
    146. //設置窗口的風格  
    147.   
    148. DWORD dwExStyle=GetWindowLong(m_hWnd,GWL_EXSTYLE);  
    149.   
    150. if((dwExStyle&0x80000)!=0x80000)  
    151.   
    152.            SetWindowLong(m_hWnd,GWL_EXSTYLE,dwExStyle^0x80000);  
    153.   
    154. //更新窗口層  
    155.   
    156. SIZE sizeWindow={755,350};  
    157.   
    158. POINT ptSrc={0,0};  
    159.   
    160. BOOL bRet=FALSE;  
    161.   
    162. HDC hdcScreen=::GetDC (m_hWnd);  
    163.   
    164. //UpdateLayeredWindow功能是更新一個窗口的位置、大小、形狀、內容和透明度  
    165.   
    166. bRet= UpdateLayeredWindow( m_hWnd,hdcScreen,&ptWinPos,  
    167.   
    168.            &sizeWindow,m_hdcMemory,&ptSrc,0,&m_Blend,2);  
    169.   
    170. graph.ReleaseHDC(m_hdcMemory);  
    171.   
    172. ::ReleaseDC(m_hWnd,hdcScreen);  
    173.   
    174. hdcScreen=NULL;  
    175.   
    176. ::ReleaseDC(m_hWnd,hdcTemp);  
    177.   
    178. hdcTemp=NULL;  
    179.   
    180. DeleteObject(hBitMap);  
    181.   
    182. DeleteDC(m_hdcMemory);  
    183.   
    184. m_hdcMemory=NULL;  
    185.   
    186. return bRet;  
    187.   
    188. }  


     

    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);

    RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成
    最近免费观看高清韩国日本大全