QQ登录

只需一步,快速开始

上位机MFC实现动画按钮

[ 复制链接 ]
效果展示

上位机MFC实现动画按钮

上位机MFC实现动画按钮

例程实现动画按钮效果,通过上位机MFC实现动画按钮。
使用这两个类的方法非常简单:
将CAniButton.h (cpp)和CDib.h (cpp)文件添加到工程中,有必要重新构造ClassWizard,使之知道这两个新的类。
然后,在对话框编辑器中添加一个自绘制按钮,并用ClassWizard将该按钮的类型设置为CAniButton。
在对话框的OnInitDialog中,调用按钮的AutoLoad成员函数,按钮就被创建了。
同时,需要处理ON_WM_PALETTECHANGED和ON_WM_QUERYNEWPALETTE消息,以完成一些调色板的工作。
当前例程不处理这两消息。
请点击此处下载

请先注册会员后在进行下载

已注册会员,请先登录后下载

文件名称:Btn.rar 
文件大小:272.3 KB  售价:10金币
下载权限: 不限 以上或 VIP会员   [购买捐助会员]   [充值积分]   有问题联系我



实现过程
1.新建一对话框工程,如上图添加控件并排版。
2.将根目录四个文件复制到自己项目工程根目录,并导入到项目中。
这样操作后,项目中就多出两个新的集成类CDIB,CAniButton

上位机MFC实现动画按钮

上位机MFC实现动画按钮

3.在主对话框中包含类的头文件,并添加或关联成员变量,初始化这些变量
#include "CAniButton.h"
        CAniButton        m_btnFree;
        CAniButton        m_btnFlag;
        CAniButton        m_btnGlobe3;
        CAniButton        m_btnGlobe2;
        CAniButton        m_btnGlobe1;
        BOOL        m_bGlobeEnabled;
        BOOL        m_bFreeEnabled;


void CBtnTestDlg:oDataExchange(CDataExchange* pDX)
{
        CDialog:oDataExchange(pDX);
        //{{AFX_DATA_MAP(CBtnTestDlg)
        DDX_Control(pDX, IDC_FREE, m_btnFree);
        DDX_Control(pDX, IDC_FLAG, m_btnFlag);
        DDX_Control(pDX, IDC_GLOBE3, m_btnGlobe3);
        DDX_Control(pDX, IDC_GLOBE2, m_btnGlobe2);
        DDX_Control(pDX, IDC_GLOBE1, m_btnGlobe1);
        DDX_Check(pDX, IDC_GLOBE_ENABLE, m_bGlobeEnabled);
        DDX_Check(pDX, IDC_FREE_ENABLE, m_bFreeEnabled);
        //}}AFX_DATA_MAP
}

初始化
        m_bGlobeEnabled = TRUE;
    m_btnFree.EnableWindow(FALSE);
    UpdateData(FALSE);

4.然后是按钮图标的设置,添加自定义函数实现。
在主对话框类中添加函数
  1. BOOL CBtnDlg::SetupAniButtons()
  2. {

  3.         m_btnGlobe1.AutoLoad(IDC_GLOBE1,         // Resource ID
  4.                          this,               // Parent Window
  5.                          IDB_GLOBE_BUTTON,   // Main Bitmap Resource ID
  6.                          IDB_GLOBE_DISABLED, // Disabled Bitmap Resource ID
  7.                          5,                  // Frames per Second
  8.                          0,                  // Calculate Number of Frames
  9.                          TRUE);              // Stretch To fit
  10.        
  11.         m_btnGlobe2.AutoLoad(IDC_GLOBE2,         // Resource ID
  12.                          this,               // Parent Window
  13.                          IDB_GLOBE_BUTTON,   // Main Bitmap Resource ID
  14.                          IDB_GLOBE_DISABLED, // Disabled Bitmap Resource ID
  15.                          10,                 // Frames per Second
  16.                          0,                  // Calculate Number of Frames
  17.                          FALSE,              // Do NOT Stretch to fit
  18.                          TRUE,               // Replace Face Color
  19.                          IDC_PLANE_CURSOR);  // Cursor Resourse ID
  20.            
  21.         m_btnGlobe3.AutoLoad(IDC_GLOBE3,         // Resource ID
  22.                          this,               // Parent Window
  23.                          IDB_GLOBE_BUTTON,   // Main Bitmap Resource ID
  24.                          IDB_GLOBE_DISABLED, // Disabled Bitmap Resource ID
  25.                          5,                  // Frames per Second
  26.                          0,                  // Calculate Number of Frames
  27.                          FALSE,              // Do NOT Stretch to fit
  28.                          FALSE);             // Do NOT Replace Face Color
  29.        
  30.    
  31.     m_btnFree.AutoLoad(IDC_FREE, this, IDB_FREE_BUTTON,
  32.                        IDB_FREE_DISABLED, 2);
  33.        
  34.     m_btnFlag.AutoLoad(IDC_FLAG, this, IDB_FLAG_BUTTON,
  35.                        0, 5, 10, FALSE, TRUE, IDR_BALDIE);

  36.     // I'm not in the mood for error checking...
  37.     return TRUE;
  38. }
复制代码
函数中调用了一些资源,所以添加这些资源,ID和上面函数一至。
添加位图资源IDB_FLAG_BUTTON
IDB_FREE_BUTTON
IDB_FREE_DISABLED
IDB_FREE_DISABLED
IDB_GLOBE_DISABLED

添加鼠标资源
IDC_HPOINT
IDC_PLANE_CURSOR
添加光标资源
然后是在初始时调用此函数SetupAniButtons();
这里要注意的是调用的位置,例如在OnInitDialog中第一行调用
BOOL CBtnDlg::OnInitDialog()
{
        SetupAniButtons();               
        CDialog::OnInitDialog();

}

5.然后就是两个使能单选框的实现。
void CBtnDlg::OnGlobeEnable()
{
    UpdateData();
    m_btnGlobe1.EnableWindow(m_bGlobeEnabled);
    m_btnGlobe2.EnableWindow(m_bGlobeEnabled);
    m_btnGlobe3.EnableWindow(m_bGlobeEnabled);
}
void CBtnDlg::OnFreeEnable()
{
    UpdateData();
    m_btnFree.EnableWindow(m_bFreeEnabled);
}

6.编译运行例程,就可以查看效果了。

上位机MFC实现动画按钮

上位机MFC实现动画按钮

下面是四个文件的源代码
  1. // CDIB.H - Class header for DIB object


  2. #ifndef _CDIB_H__
  3. #define _CDIB_H__

  4. class CDIB
  5. {
  6. protected:
  7.     CBitmap   m_bmBitmap;   // The bitmap's pixel data

  8.     CPalette* m_pPalette;   // The bitmap's palette
  9.     BOOL      m_bPalLoaded; // Error flag
  10.     int       m_nWidth;     // Bitmap's width in pixels
  11.     int       m_nHeight;    // Bitmap's height in pixels

  12. public:

  13.     CDIB ();                       // Default Constructor
  14.     CDIB (const char* szFilename); // Constructor to load from a file
  15.     CDIB (UINT nResID);            // Constructor to load from resources

  16.    virtual ~CDIB(); // Destructor

  17.     // Accessors
  18.     CBitmap&     GetBits()          {return m_bmBitmap;}
  19.     LONG         GetWidth()         {return m_nWidth;}
  20.     LONG         GetHeight()        {return m_nHeight;}
  21.     CPalette*    GetPalette()       {return m_pPalette;}
  22.     BOOL         IsPaletteLoaded()  {return m_bPalLoaded;}

  23.     // Implementation Functions
  24.     BOOL LoadFromFile(const char* szFilename); // Load Bitmap from File
  25.     BOOL LoadFromResource(UINT nResID);        // Load Bitmap from Resource
  26.     void ConvertColor(int x, int y, COLORREF cr);

  27.     // Drawing functions
  28.     void Draw(CDC* pDC, int nX, int nY,
  29.               int nWidth,int nHeight, int nXSrc, int nYSrc);
  30.     void Stretch (CDC* pDC, int dx, int dy,
  31.                   int sw, int sh, int sx, int sy, int nW, int nH);
  32. };


  33. #endif
复制代码
  1. #include "stdafx.h"
  2. #include "cdib.h"
  3. #include <io.h>


  4. // Default Constructor
  5. CDIB::CDIB()
  6. {
  7.     m_pPalette   = NULL;
  8.     m_bPalLoaded = FALSE;
  9.     m_nWidth     = 0;
  10.     m_nHeight    = 0;
  11. }


  12. // Constructor to load from a file
  13. CDIB::CDIB(const char* szFilename)
  14. {
  15.     m_pPalette   = NULL;
  16.     m_bPalLoaded = FALSE;
  17.     m_nWidth     = 0;
  18.     m_nHeight    = 0;

  19.     LoadFromFile(szFilename);
  20. }


  21. // Constructor to load from app resources
  22. CDIB::CDIB(UINT nResID)
  23. {
  24.     m_pPalette   = NULL;
  25.     m_bPalLoaded = FALSE;
  26.     m_nWidth     = 0;
  27.     m_nHeight    = 0;

  28.     LoadFromResource(nResID);
  29. }


  30. // Destructor
  31. CDIB::~CDIB()
  32. {
  33.     if(m_pPalette) delete m_pPalette;
  34. }


  35. // Load Bitmap data from a File
  36. BOOL CDIB::LoadFromFile(const char* szFilename)
  37. {
  38.     // 1. Read bits from file
  39.     HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,
  40.                                          szFilename,
  41.                                          IMAGE_BITMAP,
  42.                                          0, 0,
  43.                                          LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  44.     m_bmBitmap.Attach(hBitmap);


  45.     // 2. Get palette from the file
  46.     // Open the file
  47.     int nFile = _lopen(szFilename, OF_READ);


  48.     // Only proceed if file could be opened
  49.     if (nFile != -1)
  50.     {
  51.         BITMAPINFOHEADER bminfo;
  52.         BITMAPFILEHEADER bmfile;
  53.         PALETTEENTRY     PalEntries[256];
  54.         int              nNumEntries;
  55.         HANDLE           hlogpal;
  56.         LPLOGPALETTE     lplogpal;


  57.         // Read headers and palette entries out of file
  58.         _lread (nFile, &bmfile, sizeof(bmfile));
  59.         _lread (nFile, &bminfo, sizeof(bminfo));
  60.         _lread (nFile, &PalEntries, sizeof(PalEntries));


  61.         if ((bminfo.biSize != sizeof(BITMAPINFOHEADER)) ||
  62.             (bminfo.biBitCount > 8))
  63.         {
  64.             _lclose (nFile);
  65.             return FALSE;   
  66.             // Bad header or more than 256 colors - can't go on
  67.         }


  68.         // if biClrUsed is 0, palette is using max number of
  69.         // entries for its bitwidth.  Otherwise, biClrUsed
  70.         // specifies the actual number of palette entries in use.
  71.         if (bminfo.biClrUsed == 0)
  72.         {
  73.             nNumEntries = 1 << bminfo.biBitCount;
  74.         }
  75.         else
  76.         {
  77.             nNumEntries = bminfo.biClrUsed;
  78.         }


  79.         // Remember the bitmap's width and height
  80.         m_nWidth = bminfo.biWidth;
  81.         m_nHeight = bminfo.biHeight;


  82.         LONG lInfoSize = sizeof(BITMAPINFO) +
  83.                          sizeof(RGBQUAD)*nNumEntries;

  84.         HANDLE hInfo = GlobalAlloc (GHND, lInfoSize);

  85.         if (!hInfo)
  86.         {
  87.             _lclose(nFile);
  88.             return FALSE;
  89.         }

  90.         LPBITMAPINFO lpInfo = (LPBITMAPINFO)GlobalLock(hInfo);

  91.         if (!lpInfo)
  92.         {
  93.             _lclose(nFile);
  94.             GlobalFree(hInfo);
  95.             return FALSE;
  96.         }

  97.         // Rewind file and read whole BITMAPINFO for later use
  98.         _lseek (nFile, 0, SEEK_SET);
  99.         _lread (nFile, lpInfo, lInfoSize);
  100.         _lclose(nFile);

  101.         // Allocate storage for the LOGPALETTE
  102.         hlogpal = GlobalAlloc (GHND, sizeof(LOGPALETTE) +
  103.                                      sizeof(PALETTEENTRY)*nNumEntries);

  104.         if (!hlogpal)
  105.         {
  106.             GlobalUnlock(hInfo);
  107.             GlobalFree(hInfo);
  108.             return FALSE;
  109.         }

  110.         lplogpal = (LPLOGPALETTE)GlobalLock (hlogpal);

  111.         lplogpal->palVersion = 0x300;
  112.         lplogpal->palNumEntries = nNumEntries;


  113.         // Copy entries into LOGPALETTE
  114.         for (int i=0; i < nNumEntries; i++)
  115.         {
  116.             lplogpal->palPalEntry[i].peRed   = PalEntries[i].peBlue;
  117.             lplogpal->palPalEntry[i].peGreen = PalEntries[i].peGreen;
  118.             lplogpal->palPalEntry[i].peBlue  = PalEntries[i].peRed;
  119.             lplogpal->palPalEntry[i].peFlags = 0;
  120.         }


  121.         // Create the palette
  122.         m_pPalette = new CPalette;
  123.         m_pPalette->CreatePalette (lplogpal);

  124.         // Clean up
  125.         GlobalUnlock(hlogpal);
  126.         GlobalFree(hlogpal);
  127.         GlobalUnlock(hInfo);
  128.         GlobalFree(hInfo);

  129.         m_bPalLoaded = TRUE;
  130.     }
  131.     else
  132.     {
  133.         return FALSE;
  134.     }

  135.     return TRUE;
  136. }


  137. // Load bitmap data from app resources
  138. BOOL CDIB::LoadFromResource(UINT nResID)
  139. {
  140.     HBITMAP hBitmap;

  141.     // 1. Read bits from resource
  142.     hBitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(nResID),
  143.                                  IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);

  144.     m_bmBitmap.Attach(hBitmap);


  145.     // 2. Get palette from file or resource

  146.     m_bPalLoaded = FALSE;
  147.     m_pPalette = 0;

  148.     // Load palette from resource
  149.     HRSRC        hbmres = FindResource (NULL, MAKEINTRESOURCE(nResID), RT_BITMAP);

  150.     if (hbmres)
  151.     {
  152.         LPBITMAPINFOHEADER lpbminfo =
  153.                    (LPBITMAPINFOHEADER)LockResource(LoadResource(NULL,hbmres));

  154.         int               nNumEntries;
  155.         HANDLE            hlogpal;
  156.         LPLOGPALETTE      lplogpal;


  157.         if (lpbminfo &&
  158.             (lpbminfo->biSize >= sizeof(BITMAPINFOHEADER)) &&
  159.             (lpbminfo->biBitCount <= 8))
  160.         {
  161.             RGBQUAD*  PalEntries = (RGBQUAD*)((BYTE*)lpbminfo
  162.                                             + lpbminfo->biSize);

  163.             // if biClrUsed is 0, palette is using max number of
  164.             // entries for its bitwidth.  Otherwise, biClrUsed
  165.             // specifies the actual number of palette entries
  166.             // in use.
  167.             if (lpbminfo->biClrUsed == 0)
  168.             {
  169.                 nNumEntries = 1 << lpbminfo->biBitCount;
  170.             }
  171.             else
  172.             {
  173.                 nNumEntries = lpbminfo->biClrUsed;
  174.             }


  175.             // Remember the bitmap's width and height
  176.             m_nWidth = lpbminfo->biWidth;
  177.             m_nHeight = lpbminfo->biHeight;

  178.             LONG lInfoSize = sizeof(BITMAPINFO) +
  179.                              sizeof(RGBQUAD)*nNumEntries;

  180.             HANDLE hInfo = GlobalAlloc (GHND, lInfoSize);

  181.             if (!hInfo)
  182.             {
  183.                 return FALSE;
  184.             }

  185.             LPBITMAPINFO lpInfo = (LPBITMAPINFO)GlobalLock(hInfo);

  186.             if (!lpInfo)
  187.             {
  188.                 GlobalFree(hInfo);
  189.                 return FALSE;
  190.             }

  191.             // Copy BITMAPINFO
  192.             memcpy(lpInfo, lpbminfo, lInfoSize);


  193.             // Allocate storage for the LOGPALETTE
  194.             hlogpal = GlobalAlloc (GHND, sizeof(LOGPALETTE) +
  195.                                          sizeof(PALETTEENTRY)*nNumEntries);

  196.             if (!hlogpal)
  197.             {
  198.                 GlobalUnlock(hInfo);
  199.                 GlobalFree(hInfo);
  200.                 return FALSE;
  201.             }

  202.             lplogpal = (LPLOGPALETTE)GlobalLock (hlogpal);

  203.             lplogpal->palVersion = 0x300;
  204.             lplogpal->palNumEntries = nNumEntries;


  205.             // Copy entries into LOGPALETTE
  206.             for (int i=0; i<nNumEntries; i++)
  207.             {
  208.                 lplogpal->palPalEntry[i].peBlue  = PalEntries[i].rgbBlue;
  209.                 lplogpal->palPalEntry[i].peGreen = PalEntries[i].rgbGreen;
  210.                 lplogpal->palPalEntry[i].peRed   = PalEntries[i].rgbRed;
  211.                 lplogpal->palPalEntry[i].peFlags = 0;
  212.             }

  213.             // Create the palette
  214.             m_pPalette = new CPalette;
  215.             m_pPalette->CreatePalette (lplogpal);

  216.             // Clean up
  217.             GlobalUnlock(hlogpal);
  218.             GlobalFree(hlogpal);
  219.             GlobalUnlock(hInfo);
  220.             GlobalFree(hInfo);

  221.             m_bPalLoaded = TRUE;
  222.         }
  223.         else
  224.         {
  225.             return FALSE;
  226.         }
  227.     }
  228.     else
  229.     {
  230.         return FALSE;
  231.     }

  232.     return TRUE;
  233. }


  234. // Convert all pixels with the same color as the pixel at point (x,y).
  235. // All pixels will be converted to the given color (cr).
  236. void CDIB::ConvertColor(int x, int y, COLORREF cr)
  237. {
  238.     // Get a DC for BitBlt purposes (anyone will do).
  239.     HDC hdc = ::GetDC(NULL);
  240.     CDC dc;
  241.     dc.Attach(hdc);
  242.    
  243.     // Now create a memory DC for the Bitmap and select it into the DC.
  244.     CDC dcBitmap;
  245.     dcBitmap.CreateCompatibleDC(&dc);
  246.     dcBitmap.SelectObject(&m_bmBitmap);

  247.     // create a mask device context
  248.     CDC dcMask;
  249.     dcMask.CreateCompatibleDC(&dc);
  250.     CBitmap bmMask;

  251.     // Create the monochrome mask bitmap and select it into the DC.
  252.     bmMask.CreateBitmap(m_nWidth, m_nHeight, 1, 1, NULL);
  253.     dcMask.SelectObject(&bmMask);

  254.     // Set the Bitmap DC's background color to the desired color to change.
  255.     dcBitmap.SetBkColor( dcBitmap.GetPixel(x,y) );
  256.    
  257.     //
  258.     // Now BitBlt the Plane DC (which is color) to the Mask DC
  259.     // (which is monochrome).  The BitBlt method will convert any
  260.     // bit with a color equal to the transparent color (which has
  261.     // been set to the background color) to WHITE and any other color
  262.     // to BLACK.  Thus creating a perfect mask for the source bitmap!
  263.     //
  264.     dcMask.BitBlt(0, 0, m_nWidth, m_nHeight, &dcBitmap, 0, 0, SRCCOPY);

  265.     //
  266.     // We need to set the Bitmap DC's Background color to WHITE
  267.     // and it's Foreground color to BLACK.  Then do a BitBlt using
  268.     // the SRCPAINT Raster-operation.  Then we need to set the
  269.     // Bitmap DC's Background color to (cr) the desired color and
  270.     // it's Foreground color to WHITE.  Then do a BitBlt using
  271.     // the SRCAND Raster-operation.  This will change the all pixels
  272.     // of the color of pixel (x,y) to now be color (cr). Whew!
  273.     //
  274.     int nBkColor   = dcBitmap.SetBkColor( RGB(255,255,255) ); // White
  275.     int nForeColor = dcBitmap.SetTextColor( RGB(0,0,0) ); // Blace
  276.    
  277.     dcBitmap.BitBlt(0, 0, m_nWidth, m_nHeight, &dcMask, 0, 0, SRCPAINT);

  278.     dcBitmap.SetBkColor(cr);
  279.     dcBitmap.SetTextColor( RGB(255,255,255) ); // White

  280.     dcBitmap.BitBlt(0, 0, m_nWidth, m_nHeight, &dcMask, 0, 0, SRCAND);

  281.     // Reset the device context.
  282.     dcBitmap.SetBkColor(nBkColor);
  283.     dcBitmap.SetTextColor(nForeColor);

  284.     dc.Detach();
  285.     ReleaseDC(NULL, hdc);
  286. }


  287. // Draw the DIB to the given Device Context.
  288. // Basically Realize the palette and do a BitBlt.
  289. void CDIB::Draw(CDC* pDC, int nX, int nY,
  290.                 int nWidth,int nHeight, int nXSrc, int nYSrc)
  291. {
  292.     ASSERT(m_bPalLoaded);

  293.     //
  294.     // Select the palette into the screen DC and realize it  
  295.     // Force background, because palette should already be realized in
  296.     // foreground if necessary
  297.     //
  298.     CPalette* pOldPalette = pDC->SelectPalette(m_pPalette, TRUE);
  299.     pDC->RealizePalette();

  300.     // Create a memory DC compatible with the screen DC
  301.     CDC dcMem;
  302.     dcMem.CreateCompatibleDC(pDC);

  303.     // Put the bitmap bits into the memory DC
  304.     CBitmap* pOldBitmap = dcMem.SelectObject(&m_bmBitmap);

  305.     // Copy the bitmap bits to the screen DC
  306.     pDC->BitBlt(nX, nY, nWidth, nHeight, &dcMem, nXSrc, nYSrc, SRCCOPY);

  307.     // Put the original bitmap back
  308.     dcMem.SelectObject(pOldBitmap);

  309.     // Put the original palette back
  310.     pDC->SelectPalette(pOldPalette, TRUE);
  311.     pDC->RealizePalette();
  312. }


  313. // Stretch (fit) the DIB to the given Device Context.
  314. // Basically Realize the palette and do a StretchBlt.
  315. void CDIB::Stretch (CDC* pDC, int nX, int nY, int nWidth, int nHeight,
  316.                     int nXSrc, int nYSrc, int nSrcWidth, int nSrcHeight)
  317. {
  318.     ASSERT(m_bPalLoaded);

  319.     //
  320.     // Select the palette into the screen DC and realize it  
  321.     // Force background, because palette should already be realized in
  322.     // foreground if necessary
  323.     //
  324.     CPalette* pOldPalette = pDC->SelectPalette(m_pPalette, TRUE);
  325.     pDC->RealizePalette();

  326.     // Create a memory DC compatible with the screen DC
  327.     CDC dcMem;
  328.     dcMem.CreateCompatibleDC(pDC);

  329.     // Put the bitmap bits into the memory DC
  330.     CBitmap* pOldBitmap = dcMem.SelectObject(&m_bmBitmap);

  331.     // Copy the bitmap bits to the screen DC
  332.     pDC->StretchBlt(nX, nY, nWidth, nHeight, &dcMem,
  333.                     nXSrc, nYSrc, nSrcWidth, nSrcHeight, SRCCOPY);

  334.     // Put the original bitmap back
  335.     dcMem.SelectObject(pOldBitmap);

  336.     // Put the original palette back
  337.     pDC->SelectPalette(pOldPalette, TRUE);
  338.     pDC->RealizePalette();
  339. }

复制代码
CAniButton类的源代码
  1. #if !defined(AFX_ANIBUTTON_H__CBAD41B1_3245_11D2_8C4F_000000000000__INCLUDED_)
  2. #define AFX_ANIBUTTON_H__CBAD41B1_3245_11D2_8C4F_000000000000__INCLUDED_

  3. #if _MSC_VER >= 1000
  4. #pragma once
  5. #endif // _MSC_VER >= 1000
  6. // AniButton.h : header file
  7. //

  8. /////////////////////////////////////////////////////////////////////////////
  9. // CAniButton window

  10. class CDIB;

  11. class CAniButton : public CButton
  12. {
  13. // Construction
  14. public:
  15.         CAniButton();

  16. // Attributes
  17. public:
  18.         CDIB*   m_pDIB;             // Main Bitmap Object
  19.         CDIB*   m_pDisabledDIB;     // Disabled Bitmap Object
  20.     UINT    m_uTimer;           // Animation Timer
  21.     int     m_nCurFrame;        // Curent Frame of Animation
  22.     int     m_nNumFrames;       // Total number of frames in animation
  23.     int     m_nFramesPerSecond; // Frames to show each second
  24.     int     m_nFrameWidth;      // Width of each frame in pixels
  25.     int     m_nFrameHeight;     // Height of each frame in pixels
  26.     BOOL    m_bStretchToFit;    // Flag for force fitting the bitmap
  27.     HCURSOR m_hCursor;          // Handle to the cursor to display

  28. // Operations
  29. public:

  30. // Overrides
  31.         // ClassWizard generated virtual function overrides
  32.         //{{AFX_VIRTUAL(CAniButton)
  33.         public:
  34.         virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  35.         //}}AFX_VIRTUAL

  36. // Implementation
  37. protected:
  38.     BOOL Init(UINT  nID,              // Resource ID for this button.
  39.               CWnd* pParent,          // Button's Parent window.
  40.               UINT  nFramesPerSecond, // Number of frames per second
  41.               UINT  nNumFrames,       // Total number of frames
  42.               BOOL  bStretchToFit,    // Flag for force fitting the bitmap
  43.               BOOL  bChangeFaceColor, // Flag to change the face color
  44.               UINT  nCursorID);       // Resource ID for cursor

  45. public:
  46.        
  47.     virtual ~CAniButton(); // Destructor

  48.     BOOL AutoLoad(UINT  nID,
  49.                   CWnd* pParent,
  50.                   UINT  nBitmapID,
  51.                   UINT  nDisabledID,
  52.                   UINT  nFramesPerSecond,
  53.                   UINT  nNumFrames = 0,
  54.                   BOOL  bStretchToFit = FALSE,
  55.                   BOOL  bChangeFaceColor = TRUE,
  56.                   UINT  nCursorID = 0);

  57.         BOOL AutoLoad(UINT  nID,
  58.                   CWnd* pParent,
  59.                   const char* szFilename,
  60.                   const char* szDisabledFilename,
  61.                   UINT  nFramesPerSecond,
  62.                   UINT  nNumFrames = 0,
  63.                   BOOL  bStretchToFit = FALSE,
  64.                   BOOL  bChangeFaceColor = TRUE,
  65.                   UINT  nCursorID = 0);

  66.     void RealizePalette();
  67.    
  68. // Generated message map functions
  69. protected:
  70.         //{{AFX_MSG(CAniButton)
  71.         afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  72.         afx_msg void OnDestroy();
  73.         afx_msg void OnTimer(UINT nIDEvent);
  74.         //}}AFX_MSG

  75.         DECLARE_MESSAGE_MAP()
  76. };

  77. /////////////////////////////////////////////////////////////////////////////

  78. //{{AFX_INSERT_LOCATION}}
  79. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.

  80. #endif // !defined(AFX_ANIBUTTON_H__CBAD41B1_3245_11D2_8C4F_000000000000__INCLUDED_)
复制代码

  1. #if !defined(AFX_ANIBUTTON_H__CBAD41B1_3245_11D2_8C4F_000000000000__INCLUDED_)
  2. #define AFX_ANIBUTTON_H__CBAD41B1_3245_11D2_8C4F_000000000000__INCLUDED_

  3. #if _MSC_VER >= 1000
  4. #pragma once
  5. #endif // _MSC_VER >= 1000
  6. // AniButton.h : header file
  7. //

  8. /////////////////////////////////////////////////////////////////////////////
  9. // CAniButton window

  10. class CDIB;

  11. class CAniButton : public CButton
  12. {
  13. // Construction
  14. public:
  15.         CAniButton();

  16. // Attributes
  17. public:
  18.         CDIB*   m_pDIB;             // Main Bitmap Object
  19.         CDIB*   m_pDisabledDIB;     // Disabled Bitmap Object
  20.     UINT    m_uTimer;           // Animation Timer
  21.     int     m_nCurFrame;        // Curent Frame of Animation
  22.     int     m_nNumFrames;       // Total number of frames in animation
  23.     int     m_nFramesPerSecond; // Frames to show each second
  24.     int     m_nFrameWidth;      // Width of each frame in pixels
  25.     int     m_nFrameHeight;     // Height of each frame in pixels
  26.     BOOL    m_bStretchToFit;    // Flag for force fitting the bitmap
  27.     HCURSOR m_hCursor;          // Handle to the cursor to display

  28. // Operations
  29. public:

  30. // Overrides
  31.         // ClassWizard generated virtual function overrides
  32.         //{{AFX_VIRTUAL(CAniButton)
  33.         public:
  34.         virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  35.         //}}AFX_VIRTUAL

  36. // Implementation
  37. protected:
  38.     BOOL Init(UINT  nID,              // Resource ID for this button.
  39.               CWnd* pParent,          // Button's Parent window.
  40.               UINT  nFramesPerSecond, // Number of frames per second
  41.               UINT  nNumFrames,       // Total number of frames
  42.               BOOL  bStretchToFit,    // Flag for force fitting the bitmap
  43.               BOOL  bChangeFaceColor, // Flag to change the face color
  44.               UINT  nCursorID);       // Resource ID for cursor

  45. public:
  46.        
  47.     virtual ~CAniButton(); // Destructor

  48.     BOOL AutoLoad(UINT  nID,
  49.                   CWnd* pParent,
  50.                   UINT  nBitmapID,
  51.                   UINT  nDisabledID,
  52.                   UINT  nFramesPerSecond,
  53.                   UINT  nNumFrames = 0,
  54.                   BOOL  bStretchToFit = FALSE,
  55.                   BOOL  bChangeFaceColor = TRUE,
  56.                   UINT  nCursorID = 0);

  57.         BOOL AutoLoad(UINT  nID,
  58.                   CWnd* pParent,
  59.                   const char* szFilename,
  60.                   const char* szDisabledFilename,
  61.                   UINT  nFramesPerSecond,
  62.                   UINT  nNumFrames = 0,
  63.                   BOOL  bStretchToFit = FALSE,
  64.                   BOOL  bChangeFaceColor = TRUE,
  65.                   UINT  nCursorID = 0);

  66.     void RealizePalette();
  67.    
  68. // Generated message map functions
  69. protected:
  70.         //{{AFX_MSG(CAniButton)
  71.         afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  72.         afx_msg void OnDestroy();
  73.         afx_msg void OnTimer(UINT nIDEvent);
  74.         //}}AFX_MSG

  75.         DECLARE_MESSAGE_MAP()
  76. };

  77. /////////////////////////////////////////////////////////////////////////////

  78. //{{AFX_INSERT_LOCATION}}
  79. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.

  80. #endif // !defined(AFX_ANIBUTTON_H__CBAD41B1_3245_11D2_8C4F_000000000000__INCLUDED_)
复制代码


  

如果您认可,可联系功能定制!

  

如果您着急,充值会员可直接联系发您资料!

  

QQ联系我

微信扫扫联系我

  

回复

使用道具 举报

点击查看
快速回复 返回列表 客服中心 搜索