ReactOS 0.4.15-dev-7953-g1f49173
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 149 of file CProgressDialog.cpp.

150{
152
153 switch (msg)
154 {
155 case WM_INITDIALOG:
156 {
157 struct create_params *params = (struct create_params *)lParam;
158
159 /* Note: until we set the hEvent, the object is protected by
160 * the critical section held by StartProgress */
162 This = params->This;
163 This->hwnd = hwnd;
164
165 if (This->dwFlags & PROGDLG_NOPROGRESSBAR)
167 if (This->dwFlags & PROGDLG_NOCANCEL)
169 if (This->dwFlags & PROGDLG_MARQUEEPROGRESS)
170 This->set_progress_marquee();
171 if (This->dwFlags & PROGDLG_NOMINIMIZE)
173
174 This->update_dialog(0xffffffff);
175 This->dwUpdate = 0;
176 This->isCancelled = FALSE;
177
178 SetTimer(hwnd, ID_3SECONDS, 3 * 1000, NULL);
179
180 SetEvent(params->hEvent);
181 return TRUE;
182 }
183
184 case WM_DLG_UPDATE:
186 This->update_dialog(This->dwUpdate);
187 This->dwUpdate = 0;
189 return TRUE;
190
191 case WM_DLG_DESTROY:
193 PostThreadMessageW(GetCurrentThreadId(), WM_NULL, 0, 0); /* wake up the GetMessage */
195
196 return TRUE;
197
198 case WM_CLOSE:
199 case WM_COMMAND:
200 if (msg == WM_CLOSE || wParam == IDCANCEL)
201 {
203 This->isCancelled = TRUE;
204
205 if (!This->cancelMsg[0]) {
206 load_string(&This->cancelMsg, _AtlBaseModule.GetResourceInstance(), IDS_CANCELLING);
207 }
208
209 This->set_progress_marquee();
213 }
214 return TRUE;
215
216 case WM_TIMER:
218 if (This->progressClock[29].ullMark != 0ull) {
219 // We have enough info to take a guess
220 ULONGLONG sizeDiff = This->progressClock[This->clockHand].ullMark -
221 This->progressClock[(This->clockHand + 29) % 30].ullMark;
222 DWORD timeDiff = This->progressClock[This->clockHand].dwTime -
223 This->progressClock[(This->clockHand + 29) % 30].dwTime;
224 DWORD runDiff = This->progressClock[This->clockHand].dwTime -
225 This->dwStartTime;
226 ULONGLONG sizeLeft = This->ullTotal - This->progressClock[This->clockHand].ullMark;
227
228 // A guess for time remaining based on the recent slope.
229 DWORD timeLeftD = (DWORD) timeDiff * ((double) sizeLeft) / ((double) sizeDiff);
230 // A guess for time remaining based on the start time and current position
231 DWORD timeLeftI = (DWORD) runDiff * ((double) sizeLeft) / ((double) This->progressClock[This->clockHand].ullMark);
232
233 StrFromTimeIntervalW(This->lines[2], 128, timeLeftD * 0.3 + timeLeftI * 0.7 , 2);
234 This->update_dialog( UPDATE_LINE1 << 2 );
235 }
237
238 return TRUE;
239 }
240 return FALSE;
241}
#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:135
#define IDC_PROGRESS_BAR
Definition: resource.h:138
INT WINAPI StrFromTimeIntervalW(LPWSTR lpszStr, UINT cchMax, DWORD dwMS, int iDigits)
Definition: string.c:2147
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:962
#define PROGDLG_NOCANCEL
Definition: shlobj.h:964
#define PROGDLG_MARQUEEPROGRESS
Definition: shlobj.h:963
#define PROGDLG_NOMINIMIZE
Definition: shlobj.h:961
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:768
#define WM_CLOSE
Definition: winuser.h:1621
#define DWLP_USER
Definition: winuser.h:872
#define GetWindowLongPtrW
Definition: winuser.h:4829
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IDCANCEL
Definition: winuser.h:831
LONG WINAPI SetWindowLongW(_In_ HWND, _In_ int, _In_ LONG)
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
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:1742
#define WM_NULL
Definition: winuser.h:1607
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SetWindowLongPtrW
Definition: winuser.h:5346
#define GWL_STYLE
Definition: winuser.h:852
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by dialog_thread().

◆ dialog_thread()

static DWORD WINAPI dialog_thread ( LPVOID  lpParameter)
static

Definition at line 243 of file CProgressDialog.cpp.

244{
245 /* Note: until we set the hEvent in WM_INITDIALOG, the ProgressDialog object
246 * is protected by the critical section held by StartProgress */
247 struct create_params *params = (struct create_params *) lpParameter;
248 HWND hwnd;
249 MSG msg;
250
251 hwnd = CreateDialogParamW(_AtlBaseModule.GetResourceInstance(),
253 params->hwndParent,
255 (LPARAM)params);
256
257 while (GetMessageW(&msg, NULL, 0, 0) > 0)
258 {
259 if (!IsWindow(hwnd))
260 break;
262 {
265 }
266 }
267
268 return 0;
269}
static INT_PTR CALLBACK dialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
#define IDD_PROGRESS_DLG
Definition: resource.h:140
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 93 of file CProgressDialog.cpp.

94{
95 WCHAR string[256];
96
97 LoadStringW(hInstance, uiResourceId, string, sizeof(string)/sizeof(string[0]));
98
99 set_buffer(buffer, string);
100}
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 75 of file CProgressDialog.cpp.

76{
77 if (!string)
78 {
79 (*buffer)[0] = UNICODE_NULL;
80 return;
81 }
82
84}
#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().