-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressDlg.cpp
125 lines (98 loc) · 2.81 KB
/
ProgressDlg.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// WinDjView
// Copyright (C) 2004-2015 Andrew Zhezherun
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// http://www.gnu.org/copyleft/gpl.html
#include "stdafx.h"
#include "WinDjView.h"
#include "ProgressDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CProgressDlg dialog
IMPLEMENT_DYNAMIC(CProgressDlg, CMyDialog)
CProgressDlg::CProgressDlg(ThreadProcEx pfnThreadProc, CWnd* pParent)
: CMyDialog(CProgressDlg::IDD, pParent), m_nCode(0), m_nCancelled(0),
m_pfnThreadProc(pfnThreadProc), m_dwUserData(0), m_hThread(NULL)
{
}
CProgressDlg::~CProgressDlg()
{
if (m_hThread != NULL)
::CloseHandle(m_hThread);
}
void CProgressDlg::DoDataExchange(CDataExchange* pDX)
{
CMyDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS, m_progress);
DDX_Control(pDX, IDC_STATIC_TEXT, m_status);
}
BEGIN_MESSAGE_MAP(CProgressDlg, CMyDialog)
ON_MESSAGE(WM_ENDDIALOG, OnEndDialog)
END_MESSAGE_MAP()
// CProgressDlg message handlers
void CProgressDlg::SetStatus(const CString& strText)
{
m_status.SetWindowText(strText);
}
void CProgressDlg::SetRange(int nStart, int nEnd)
{
m_progress.SetRange32(nStart, nEnd);
Invalidate(false);
UpdateWindow();
}
void CProgressDlg::SetPos(int nPos)
{
m_progress.SetPos(nPos);
Invalidate(false);
UpdateWindow();
}
bool CProgressDlg::IsCancelled()
{
return (InterlockedExchangeAdd(&m_nCancelled, 0) == 1);
}
long CProgressDlg::GetResultCode()
{
return InterlockedExchangeAdd(&m_nCode, 0);
}
void CProgressDlg::StopProgress(long nCode)
{
InterlockedExchange(&m_nCode, nCode);
SendMessage(WM_ENDDIALOG, m_nCancelled ? IDCANCEL : IDOK);
}
BOOL CProgressDlg::OnInitDialog()
{
CMyDialog::OnInitDialog();
m_progress.SetRange32(0, 1);
m_progress.SetPos(0);
m_status.SetWindowText(LoadString(IDS_PLEASE_WAIT));
UINT nThreadID;
m_hThread = (HANDLE)_beginthreadex(NULL, 0, m_pfnThreadProc,
static_cast<IProgressInfo*>(this), 0, &nThreadID);
::SetThreadPriority(m_hThread, THREAD_PRIORITY_BELOW_NORMAL);
return true;
}
void CProgressDlg::OnCancel()
{
}
void CProgressDlg::OnOK()
{
InterlockedExchange(&m_nCancelled, 1);
}
LRESULT CProgressDlg::OnEndDialog(WPARAM wParam, LPARAM lParam)
{
EndDialog((int)wParam);
return 0;
}