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