AnimButton.cpp
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. // AnimButton.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "AnimButton.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. #define IDT_ANIMATE 1001
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CAnimButton
  24. CAnimButton::CAnimButton()
  25. {
  26. pImageList = NULL;
  27. imageCount = 0;
  28. frame = 0;
  29. }
  30. CAnimButton::~CAnimButton()
  31. {
  32. }
  33. void CAnimButton::stop(int frame)
  34. {
  35. this->frame = frame;
  36. OnTimer(IDT_ANIMATE);
  37. KillTimer(IDT_ANIMATE);
  38. }
  39. void CAnimButton::setImageList(CImageList *pImageList, int n)
  40. {
  41. this->pImageList = pImageList;
  42. if (n == -1)
  43. n = pImageList->GetImageCount();
  44. imageCount = n;
  45. OnTimer(IDT_ANIMATE);
  46. }
  47. void CAnimButton::start()
  48. {
  49. SetTimer(IDT_ANIMATE, 250, NULL);
  50. OnTimer(IDT_ANIMATE);
  51. }
  52. BEGIN_MESSAGE_MAP(CAnimButton, CButtonST)
  53. //{{AFX_MSG_MAP(CAnimButton)
  54. ON_WM_TIMER()
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CAnimButton message handlers
  59. void CAnimButton::OnTimer(UINT nIDEvent) 
  60. {
  61. if (nIDEvent == IDT_ANIMATE) {
  62. SetIcon(pImageList->ExtractIcon(frame));
  63. if (++frame >= imageCount)
  64. frame = 0;
  65. } else
  66. CButtonST::OnTimer(nIDEvent);
  67. }