windows-nsis-vs2005-20080409
[openafs.git] / src / WINNT / afs_setup_utils / animate_icon.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * INCLUDES ___________________________________________________________________
12  *
13  */
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 }
18
19 #include <windows.h>
20 #include <WINNT/talocale.h>
21 #include "../afsapplib/subclass.h"
22 #include "animate_icon.h"
23 #include "resource.h"
24
25
26 /*
27  * Definitions ___________________________________________________________________
28  *
29  */
30 #define GWD_ANIMATIONFRAME  TEXT("afsapplib/al_misc.cpp - next animation frame")
31
32
33 /*
34  * ANIMATION __________________________________________________________________
35  *
36  */
37
38 void AnimateIcon (HWND hIcon, int *piFrameLast)
39 {
40    static HICON hiStop;
41    static HICON hiFrame[8];
42    static BOOL fLoaded = FALSE;
43
44    if (!fLoaded)
45       {
46       hiStop     = TaLocale_LoadIcon (IDI_SPINSTOP);
47       hiFrame[0] = TaLocale_LoadIcon (IDI_SPIN1);
48       hiFrame[1] = TaLocale_LoadIcon (IDI_SPIN2);
49       hiFrame[2] = TaLocale_LoadIcon (IDI_SPIN3);
50       hiFrame[3] = TaLocale_LoadIcon (IDI_SPIN4);
51       hiFrame[4] = TaLocale_LoadIcon (IDI_SPIN5);
52       hiFrame[5] = TaLocale_LoadIcon (IDI_SPIN6);
53       hiFrame[6] = TaLocale_LoadIcon (IDI_SPIN7);
54       hiFrame[7] = TaLocale_LoadIcon (IDI_SPIN8);
55       fLoaded = TRUE;
56       }
57
58    if (piFrameLast)
59       {
60       *piFrameLast = (*piFrameLast == 7) ? 0 : (1+*piFrameLast);
61       }
62
63    SendMessage (hIcon, STM_SETICON, (WPARAM)((piFrameLast) ? hiFrame[ *piFrameLast ] : hiStop), 0);
64 }
65
66
67 BOOL CALLBACK AnimationHook (HWND hIcon, UINT msg, WPARAM wp, LPARAM lp)
68 {
69    PVOID oldProc = Subclass_FindNextHook (hIcon, AnimationHook);
70
71    static int iFrame = 0;
72
73    switch (msg)
74       {
75       case WM_TIMER:
76          AnimateIcon (hIcon, &iFrame);
77          break;
78
79       case WM_DESTROY:
80          Subclass_RemoveHook (hIcon, AnimationHook);
81          break;
82       }
83
84    if (oldProc)
85       return CallWindowProc ((WNDPROC)oldProc, hIcon, msg, wp, lp);
86    else
87       return DefWindowProc (hIcon, msg, wp, lp);
88 }
89
90 void StartAnimation (HWND hIcon, int fps)
91 {
92    Subclass_AddHook (hIcon, AnimationHook);
93    SetTimer (hIcon, 0, 1000/((fps) ? fps : 8), NULL);
94    AnimateIcon (hIcon);
95 }
96
97 void StopAnimation (HWND hIcon)
98 {
99    KillTimer (hIcon, 0);
100    AnimateIcon (hIcon);
101    Subclass_RemoveHook (hIcon, AnimationHook);
102 }
103