ReactOS 0.4.16-dev-598-gc07fba4
CProgressDialog.cpp File Reference
#include <precomp.h>
Include dependency graph for CProgressDialog.cpp:

Go to the source code of this file.

Classes

struct  create_params
 

Macros

#define COBJMACROS
 
#define CANCEL_MSG_LINE   2
 
#define UPDATE_PROGRESS   0x1
 
#define UPDATE_TITLE   0x2
 
#define UPDATE_LINE1   0x4
 
#define UPDATE_LINE2   (UPDATE_LINE1<<1)
 
#define UPDATE_LINE3   (UPDATE_LINE1<<2)
 
#define WM_DLG_UPDATE   (WM_APP+1) /* set to the dialog when it should update */
 
#define WM_DLG_DESTROY   (WM_APP+2) /* DestroyWindow must be called from the owning thread */
 
#define ID_3SECONDS   101
 
#define BUFFER_SIZE   256
 

Functions

static void set_buffer (LPWSTR *buffer, LPCWSTR string)
 
static void load_string (LPWSTR *buffer, HINSTANCE hInstance, UINT uiResourceId)
 
static INT_PTR CALLBACK dialog_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static DWORD WINAPI dialog_thread (LPVOID lpParameter)
 

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   256

Definition at line 43 of file CProgressDialog.cpp.

◆ CANCEL_MSG_LINE

#define CANCEL_MSG_LINE   2

Definition at line 26 of file CProgressDialog.cpp.

◆ COBJMACROS

#define COBJMACROS

Definition at line 24 of file CProgressDialog.cpp.

◆ ID_3SECONDS

#define ID_3SECONDS   101

Definition at line 41 of file CProgressDialog.cpp.

◆ UPDATE_LINE1

#define UPDATE_LINE1   0x4

Definition at line 33 of file CProgressDialog.cpp.

◆ UPDATE_LINE2

#define UPDATE_LINE2   (UPDATE_LINE1<<1)

Definition at line 34 of file CProgressDialog.cpp.

◆ UPDATE_LINE3

#define UPDATE_LINE3   (UPDATE_LINE1<<2)

Definition at line 35 of file CProgressDialog.cpp.

◆ UPDATE_PROGRESS

#define UPDATE_PROGRESS   0x1

Definition at line 31 of file CProgressDialog.cpp.

◆ UPDATE_TITLE

#define UPDATE_TITLE   0x2

Definition at line 32 of file CProgressDialog.cpp.

◆ WM_DLG_DESTROY

#define WM_DLG_DESTROY   (WM_APP+2) /* DestroyWindow must be called from the owning thread */

Definition at line 39 of file CProgressDialog.cpp.

◆ WM_DLG_UPDATE

#define WM_DLG_UPDATE   (WM_APP+1) /* set to the dialog when it should update */

Definition at line 38 of file CProgressDialog.cpp.

Function Documentation

◆ dialog_proc()

static INT_PTR CALLBACK dialog_proc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 150 of file CProgressDialog.cpp.

151{
153
154 switch (msg)
155 {
156 case WM_INITDIALOG:
157 {
158 struct create_params *params = (struct create_params *)lParam;
159
160 /* Note: until we set the hEvent, the object is protected by
161 * the critical section held by StartProgress */
163 This = params->This;
164 This->hwnd = hwnd;
165
166 if (This->dwFlags & PROGDLG_NOPROGRESSBAR)
168 if (This->dwFlags & PROGDLG_NOCANCEL)
170 if (This->dwFlags & PROGDLG_MARQUEEPROGRESS)
171 This->set_progress_marquee();
172 if (This->dwFlags & PROGDLG_NOMINIMIZE)
174
175 This->update_dialog(0xffffffff);
176 This->dwUpdate = 0;
177 This->isCancelled = FALSE;
178
179 SetTimer(hwnd, ID_3SECONDS, 3 * 1000, NULL);
180
181 SetEvent(params->hEvent);
182 return TRUE;
183 }
184
185 case WM_DLG_UPDATE:
187 This->update_dialog(This->dwUpdate);
188 This->dwUpdate = 0;
190 return TRUE;
191
192 case WM_DLG_DESTROY:
194 PostThreadMessageW(GetCurrentThreadId(), WM_NULL, 0, 0); /* wake up the GetMessage */
196
197 return TRUE;
198
199 case WM_CLOSE:
200 case WM_COMMAND:
201 if (msg == WM_CLOSE || wParam == IDCANCEL)
202 {
204 This->isCancelled = TRUE;
205
206 if (!This->cancelMsg[0]) {
207 load_string(&This->cancelMsg, _AtlBaseModule.GetResourceInstance(), IDS_CANCELLING);
208 }
209
210 This->set_progress_marquee();
214 }
215 return TRUE;
216
217 case WM_TIMER:
219 if (This->progressClock[29].ullMark != 0ull) {
220 // We have enough info to take a guess
221 ULONGLONG sizeDiff = This->progressClock[This->clockHand].ullMark -
222 This->progressClock[(This->clockHand + 29) % 30].ullMark;
223 DWORD timeDiff = This->progressClock[This->clockHand].dwTime -
224 This->progressClock[(This->clockHand + 29) % 30].dwTime;
225 DWORD runDiff = This->progressClock[This->clockHand].dwTime -
226 This->dwStartTime;
227 ULONGLONG sizeLeft = This->ullTotal - This->progressClock[This->clockHand].ullMark;
228
229 // A guess for time remaining based on the recent slope.
230 DWORD timeLeftD = (DWORD) timeDiff * ((double) sizeLeft) / ((double) sizeDiff);
231 // A guess for time remaining based on the start time and current position
232 DWORD timeLeftI = (DWORD) runDiff * ((double) sizeLeft) / ((double) This->progressClock[This->clockHand].ullMark);
233
234 StrFromTimeIntervalW(This->lines[2], 128, timeLeftD * 0.3 + timeLeftI * 0.7 , 2);
235 This->update_dialog( UPDATE_LINE1 << 2 );
236 }
238
239 return TRUE;
240 }
241 return FALSE;
242}
#define UPDATE_LINE2
#define WM_DLG_UPDATE
static void load_string(LPWSTR *buffer, HINSTANCE hInstance, UINT uiResourceId)
#define ID_3SECONDS
#define UPDATE_LINE3
#define WM_DLG_DESTROY
#define UPDATE_LINE1
#define msg(x)
Definition: auth_time.c:54
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDS_CANCELLING
Definition: resource.h:134
#define IDC_PROGRESS_BAR
Definition: resource.h:137
INT WINAPI StrFromTimeIntervalW(LPWSTR lpszStr, UINT cchMax, DWORD dwMS, int iDigits)
Definition: string.c:2153
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum const GLfloat * params
Definition: glext.h:5645
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define DWORD
Definition: nt_native.h:44
#define WS_MINIMIZEBOX
Definition: pedump.c:631
#define PROGDLG_NOPROGRESSBAR
Definition: shlobj.h:969
#define PROGDLG_NOCANCEL
Definition: shlobj.h:971
#define PROGDLG_MARQUEEPROGRESS
Definition: shlobj.h:970
#define PROGDLG_NOMINIMIZE
Definition: shlobj.h:968
DWORD dwTime
Definition: solitaire.cpp:27
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
uint64_t ULONGLONG
Definition: typedefs.h:67
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define SW_HIDE
Definition: winuser.h:771
#define WM_CLOSE
Definition: winuser.h:1624
#define DWLP_USER
Definition: winuser.h:875
#define GetWindowLongPtrW
Definition: winuser.h:4832
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IDCANCEL
Definition: winuser.h:834
LONG WINAPI SetWindowLongW(_In_ HWND, _In_ int, _In_ LONG)
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1743
#define WM_INITDIALOG
Definition: winuser.h:1742
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
BOOL WINAPI PostThreadMessageW(_In_ DWORD, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_TIMER
Definition: winuser.h:1745
#define WM_NULL
Definition: winuser.h:1610
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SetWindowLongPtrW
Definition: winuser.h:5358
#define GWL_STYLE
Definition: winuser.h:855
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by dialog_thread().

◆ dialog_thread()

static DWORD WINAPI dialog_thread ( LPVOID  lpParameter)
static

Definition at line 244 of file CProgressDialog.cpp.

245{
246 /* Note: until we set the hEvent in WM_INITDIALOG, the ProgressDialog object
247 * is protected by the critical section held by StartProgress */
248 struct create_params *params = (struct create_params *) lpParameter;
249 HWND hwnd;
250 MSG msg;
251
252 hwnd = CreateDialogParamW(_AtlBaseModule.GetResourceInstance(),
254 params->hwndParent,
256 (LPARAM)params);
257
258 while (GetMessageW(&msg, NULL, 0, 0) > 0)
259 {
260 if (!IsWindow(hwnd))
261 break;
263 {
266 }
267 }
268
269 return 0;
270}
static INT_PTR CALLBACK dialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
#define IDD_PROGRESS_DLG
Definition: resource.h:139
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
LONG_PTR LPARAM
Definition: windef.h:208
HWND WINAPI CreateDialogParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
BOOL WINAPI IsWindow(_In_opt_ HWND)
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI IsDialogMessageW(_In_ HWND, _In_ LPMSG)
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by CProgressDialog::StartProgressDialog().

◆ load_string()

static void load_string ( LPWSTR buffer,
HINSTANCE  hInstance,
UINT  uiResourceId 
)
static

Definition at line 94 of file CProgressDialog.cpp.

95{
96 WCHAR string[256];
97
98 LoadStringW(hInstance, uiResourceId, string, sizeof(string)/sizeof(string[0]));
99
100 set_buffer(buffer, string);
101}
static void set_buffer(LPWSTR *buffer, LPCWSTR string)
HINSTANCE hInstance
Definition: charmap.c:19
GLuint buffer
Definition: glext.h:5915
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by dialog_proc().

◆ set_buffer()

static void set_buffer ( LPWSTR buffer,
LPCWSTR  string 
)
static

Definition at line 76 of file CProgressDialog.cpp.

77{
78 if (!string)
79 {
80 (*buffer)[0] = UNICODE_NULL;
81 return;
82 }
83
85}
#define BUFFER_SIZE
#define UNICODE_NULL
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166

Referenced by load_string().