分类: C/C++
2008-08-04 09:31:20
m_animIcon.SetImageList(IDB_BITMAP_ANIM,6,RGB(0,0,0)); m_animIcon.Draw(this);即可。
class CAnimateIcon { protected: //创建一个列表变量,用于保存图像列 CImageList m_imgList; //当前图像序号 int m_iImageCounter; //图像总数 int m_nMaxNumOfImages; //关闭线程 bool m_bExit; //拥有图标的窗口的窗口类指针 CWnd * m_pWnd; //图标刷新间隔 DWORD m_dwMilliseconds; public: void ChangeInterval(DWORD dwTimes);//改变图标刷新时间间隔 BOOL Draw(CWnd *pWnd,DWORD dwTimes=1000); CAnimateIcon(); ~CAnimateIcon(); bool SetImageList(int IDOfImageListResource,int numberOfImages,COLORREF transparentColor); protected: static UINT WINAPI _ThreadAnimation(LPVOID pParam); }; BOOL CAnimateIcon::Draw(CWnd *pWnd,DWORD dwTimes) { //拥有图标的窗口的窗口类指针 m_pWnd=pWnd; ASSERT(m_pWnd); //图标刷新间隔 m_dwMilliseconds=dwTimes; unsigned int nDummy; //注意:传递给线程本实例的指针 HANDLE hThread = (HANDLE) _beginthreadex(NULL,0,_ThreadAnimation,this, CREATE_SUSPENDED,&nDummy); if (!hThread) { TRACE(_T("Draw: Couldn''t start a ICON animation thread\n")); return false; } else { ResumeThread(hThread); } CloseHandle(hThread);//不再需要线程句柄,将其关闭 return true; } UINT WINAPI CAnimateIcon::_ThreadAnimation(LPVOID pParam) { //从传递过来的实例指针,可以操作不同的实例, //注意线程函数是唯一和静态的。 CAnimateIcon &p=*(CAnimateIcon *)pParam; while(!p.m_bExit){ if(p.m_imgList.m_hImageList==NULL) return 0; p.m_iImageCounter ; if(p.m_iImageCounter>=p.m_nMaxNumOfImages) p.m_iImageCounter=0; HICON hIcon=p.m_imgList.ExtractIcon(p.m_iImageCounter); HICON hPrevIcon=(HICON)p.m_pWnd->SetIcon(hIcon,false); DestroyIcon(hPrevIcon); Sleep(p.m_dwMilliseconds); } return 1; }在VC6.0+WIN2000 SP3编译通过! 下载本文示例代码