Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / WINNT / afsapplib / al_progress.h
1 #ifndef AL_PROGRESS_H
2 #define AL_PROGRESS_H
3
4 #ifndef EXPORTED
5 #define EXPORTED
6 #endif
7
8 /*
9  * PROGRESS DIALOGS ___________________________________________________________
10  *
11  * The PROGRESSDISPLAY object is probably one of the most esoteric 
12  * utilities in this library. It provides a convenient way to package
13  * up a background thread, and associate it with a dialog telling the user
14  * what's going on. It sounds a little hokey, and honestly isn't that
15  * terribly useful, but you may find you need it at some point.
16  *
17  * Example:
18  *
19  *    // Copy the files onto the user's machine.
20  *    //
21  *    extern LPTSTR g_apszFilename[];
22  *
23  *    LPPROGRESSDISPLAY pProg;
24  *    pProg = new PROGRESSDISPLAY (hParent, IDD_COPYING_PROGRESS);
25  *    pProg->SetProgressRange (0, nFILES(g_apszFilename));
26  *    pProg->Show (fnCopyFiles, (LPARAM)g_apszFilename);
27  *
28  *    // By default, Show() is modal--it pumps messages until the
29  *    // background thread completes.  If you have specified a
30  *    // finish message ("pProg->SetFinishMessage (WM_USER+15)"),
31  *    // then Show() is modeless, returning immediately. The WM_USER+15
32  *    // message will be posted to the progress dialog when the background
33  *    // thread completes (you can specify a dlgproc for your progress
34  *    // dialog on the "new PROGRESSDISPLAY" line).
35  *
36  *    DWORD CALLBACK fnCopyFiles (LPPROGRESSDISPLAY pProg, LPARAM lp)
37  *    {
38  *       LPTSTR *apszFilename = (LPTSTR*)lp;
39  *
40  *       for (ii = 0; ii < nFILES(apszFilename); ++ii) {
41  *          pProg->SetOperation ("Copying "+apszFilename[ii]);
42  *          CopyFile (apszFilename[ii])
43  *          pProg->SetProgress (ii);
44  *       }
45  *
46  *       pProg->Close();
47  *       return 0;
48  *    }
49  *
50  */
51
52 #include <WINNT/TaLocale.h>
53 #include <WINNT/subclass.h>
54
55
56 /*
57  * DEFINITIONS ________________________________________________________________
58  *
59  */
60
61 #ifndef THIS_HINST
62 #define THIS_HINST   (HINSTANCE)GetModuleHandle(NULL)
63 #endif
64
65 #define IDC_OPERATION      900
66 #define IDC_PROGRESS       901
67 #define IDC_PROGRESSTEXT   902
68
69 typedef class EXPORTED PROGRESSDISPLAY PROGRESSDISPLAY, *LPPROGRESSDISPLAY;
70
71
72 /*
73  * PROGRESSDISPLAY CLASS ______________________________________________________
74  *
75  */
76
77 class PROGRESSDISPLAY
78    {
79    public:
80
81       PROGRESSDISPLAY (HWND hWnd);
82       PROGRESSDISPLAY (HWND hParent, int iddTemplate, DLGPROC dlgproc = 0);
83
84       static LPPROGRESSDISPLAY GetProgressDisplay (HWND hWnd);
85
86       void GetProgressRange (int *piStart, int *piFinish);
87       void SetProgressRange (int iStart, int iFinish);
88
89       int GetProgress (void);
90       void SetProgress (int iProgress);
91
92       void GetOperation (LPTSTR pszOperation);
93       void SetOperation (LPCTSTR pszOperation);
94
95       HWND GetWindow (void);
96
97       void SetFinishMessage (int msgFinish);
98       void Show (DWORD (CALLBACK *pfn)(LPPROGRESSDISPLAY ppd, LPARAM lp), LPARAM lp);
99       void Close (void);
100       DWORD GetStatus (void);
101
102    private:
103
104       ~PROGRESSDISPLAY (void);
105       void Init (HWND hWnd);
106       void Finish (DWORD dwStatus = 0);
107       void PROGRESSDISPLAY::OnUpdate (void);
108
109       static BOOL CALLBACK ProgressDisplay_StubProc (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
110       static BOOL CALLBACK ProgressDisplay_HookProc (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
111       static DWORD WINAPI PROGRESSDISPLAY::ThreadProc (PVOID lp);
112
113       BOOL m_fFinished;
114       LONG m_dwStatus;
115
116       LONG m_cRef;
117       CRITICAL_SECTION m_cs;
118       HWND m_hWnd;
119       BOOL m_fCreatedWindow;
120
121       int m_msgFinish;
122       DWORD (CALLBACK *m_pfnUser)(LPPROGRESSDISPLAY ppd, LPARAM lp);
123       LPARAM m_lpUser;
124       int m_iProgressStart;
125       int m_iProgressFinish;
126       int m_iProgress;
127       TCHAR m_szOperation[ cchRESOURCE ];
128       TCHAR m_szProgressText[ cchRESOURCE ];
129    };
130
131
132 #endif
133