Change the icon of a dynamic thread: cj_ict
Download this article The sample code has seen a "How to display the Dynamic Icon" article in the title bar, the author is a Chongqing Construction Group Tang Xingbin. I feel that it is troublesome with setTimer and takes up resources. The hand itching will change it to threads and package threads in the class. Use simple, no need to set SETIMER to call in the ONTIMER function. Just call directly
M_animicon.setimagelist (idb_bitmap_anim, 6, rgb (0,0,0));
m_animicon.draw (this);
I.e. Other parts of the program is to use Tang Xingbin, I just changed the part of the ONTIMER implementation.
Class Canimateicon
{
protected:
// Create a list variable for saving the image column
CIMAGELIST M_IMGLIST;
// Current image number
INT M_IIMAGECUNTER;
// Total number of images
INT m_nmaxnumofimages;
// Turn off the thread
Bool M_Bexit;
/ / Window pointer with the window of the icon
CWND * m_pwnd;
// Icon brush new interval
DWORD M_DWMILLISECONDS;
PUBLIC:
Void ChangeInterval (DWORD DWTIMES); / / Change the icon refresh
BOOL DRAW (CWND * PWND, DWORD DWTIMES = 1000);
CANIMATECION ();
~ CaniMateicon ();
Bool SetImagelist (int IDofimagelistResource, Int Numberofimages, ColorRef TransparentColor);
protected:
Static uint WinAPI _threadAnimation (LPVOID PPARAM);
}
Bool Canimateicon :: DRAW (CWND * PWND, DWORD DWTIMES)
{
/ / Window pointer with the window of the icon
M_PWND = PWND;
AskERT (m_pwnd);
// Icon brush new interval
m_dwmilliseconds = dwtimes;
Unsigned int NDummy;
// Note: Pointer to pass the threaded instance
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); // no longer need thread handle, close it
Return True;
}
Uint WinApi CANIMATEICON :: _ ThreadArmation (LPVOID PPARAM)
{
// From the passed instance pointer, you can operate different instances.
// Note The thread function is unique and static.
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;
}
Compiled in VC6.0 Win2000 SP3!