| 235 | //An Abstract Class that handles Animated Icons for the following two classes. |
| 236 | |
| 237 | class CAniIcon { |
| 238 | // Construction |
| 239 | public: |
| 240 | CAniIcon() : Icons(0), hIcon(0) {} //Needed for derived classes |
| 241 | virtual ~CAniIcon() {if(Icons) delete Icons;} |
| 242 | |
| 243 | // Attributes |
| 244 | private: |
| 245 | CTime StartTime; |
| 246 | int Duration; // Stop animating after Duration milliseconds |
| 247 | UINT_PTR TimerID; |
| 248 | HICON* Icons; // NULL Terminated Array of Icons to animate |
| 249 | HICON* it; // Frame Iterator |
| 250 | HICON hIcon; // A copy of the original (non-animated) Icon. |
| 251 | |
| 252 | // Operations |
| 253 | public: |
| 254 | virtual HICON GetIcon() const =0; |
| 255 | virtual BOOL SetIcon(HICON hIcon) =0; |
| 256 | |
| 257 | virtual UINT_PTR SetTimer(UINT nIDEvent, UINT nElapse, void (CALLBACK* lpfnTimer)(HWND, UINT, UINT_PTR, DWORD)) =0; |
| 258 | virtual BOOL KillTimer(INT_PTR nIDEvent) =0; |
| 259 | |
| 260 | void SetIcons(const UINT IconIDs[]) { // NULL Terminated Array of Icon Recource IDs to animate |
| 261 | const UINT* ptr=IconIDs; |
| 262 | int i; |
| 263 | for(i=1; *ptr++; ++i); //Count them |
| 264 | if(Icons) delete Icons; |
| 265 | it=Icons=new HICON[i]; //Prepare storage for their HICONs |
| 266 | const CWinApp* App=AfxGetApp(); |
| 267 | ASSERT(App); |
| 268 | for(ptr=IconIDs; i=*ptr++; *it++=App->LoadIcon(i)); //Store the HICONs |
| 269 | *it=0; //NULL Terminate the list |
| 270 | } |
| 271 | |
| 272 | #define TrayIconTimer 1032 |
| 273 | |
| 274 | BOOL Animate(UINT nDelayMilliSeconds, int nNumSeconds=-1) { |
| 275 | if(!Icons) return FALSE; |
| 276 | StopAnimating(); |
| 277 | it=Icons; |
| 278 | StartTime=CTime::GetCurrentTime(); |
| 279 | Duration=nNumSeconds; |
| 280 | hIcon=GetIcon(); |
| 281 | TimerID=SetTimer(TrayIconTimer, nDelayMilliSeconds, 0); |
| 282 | return TimerID != 0; |
| 283 | } |
| 284 | |
| 285 | void StopAnimating() { |
| 286 | if(TimerID) KillTimer(TimerID); |
| 287 | TimerID=0; |
| 288 | if(hIcon) SetIcon(hIcon); |
| 289 | hIcon=0; |
| 290 | } |
| 291 | |
| 292 | virtual LRESULT WindowProc(UINT Message, WPARAM wParam, LPARAM lParam) { |
| 293 | if(Message!=WM_TIMER || wParam!=TrayIconTimer) return false; |
| 294 | CTime CurrentTime=CTime::GetCurrentTime(); |
nothing calls this directly
no outgoing calls
no test coverage detected