-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgressThread.h
73 lines (57 loc) · 2.14 KB
/
ProgressThread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
// CProgressThread - a UI thread that owns a CProgressCtrlWithTimer.
//
// Purpose:
//
// To indicate that the application is busy while doing a lengthy computation.
// The progress control will work even when the main thread is busy.
//
// Initialization:
//
// 1. Use resource editor to define a CProgressCtrl, and add a corresponding variable.
// This will only be used as reference - do not use it directly.
// 2. Construct, sending the CProgressCtrl object. It will be used to derive the
// style and position of the actual CProgressCtrlWithTimer.
// 3. Call CreateThread(). This is when the actual CProgressCtrlWithTimer is
// created.
//
// Activating and stopping the progress control:
//
// 1. Use the function Ctrl() to get access to the CProgressCtrlWithTimer object.
// Don't directly destroy the object returned by Ctrl().
// 2. Use the methods Play(), Stop(), IsPlaying() of the CProgressCtrlWithTimer object.
//
// Destroying the progress control:
//
// 1. Call EndThread(). This will send a message requesting
// to exit the thread, and will wait until the thread has ended.
// It will also delete the object. No need to call the destructor.
//
class CProgressCtrlWithTimer;
class CProgressThread : public CWinThread
{
DECLARE_DYNCREATE(CProgressThread)
private:
CProgressThread(); // Used by IMPLEMENT_DYNCREATE.
virtual ~CProgressThread(); // To delete the object, the user must call EndThread().
public:
CProgressThread(const CProgressCtrl* reference_ctrl);
virtual BOOL InitInstance();
void EndThread();
// Stop playing the progress bar
void Stop();
// Start to play the progress bar.
// Whenever timer_milliseconds pass, we advance the position of the progress bar by pos_advance
void Play(unsigned int timer_milliseconds, int pos_advance);
// Return true if currently playing.
bool IsPlaying() const { return m_is_playing; }
private:
afx_msg void OnPlayProgressBar(WPARAM wParam, LPARAM lParam);
afx_msg void OnStopProgressBar(WPARAM wParam, LPARAM lParam);
private:
CProgressCtrlWithTimer* m_progress_ctrl;
const CProgressCtrl* m_reference_ctrl;
bool m_is_playing;
protected:
DECLARE_MESSAGE_MAP()
};