ReactOS  0.4.14-dev-98-gb0d4763
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();
211  This->update_dialog(UPDATE_LINE1|UPDATE_LINE2|UPDATE_LINE3);
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 IDC_PROGRESS_BAR
Definition: resource.h:134
#define WM_NULL
Definition: winuser.h:1589
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
#define SW_HIDE
Definition: winuser.h:762
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
INT WINAPI StrFromTimeIntervalW(LPWSTR lpszStr, UINT cchMax, DWORD dwMS, int iDigits)
Definition: string.c:2139
#define GetWindowLongPtrW
Definition: winuser.h:4730
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define DWORD
Definition: nt_native.h:44
WPARAM wParam
Definition: combotst.c:138
GLenum const GLfloat * params
Definition: glext.h:5645
LONG WINAPI SetWindowLongW(_In_ HWND, _In_ int, _In_ LONG)
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
smooth NULL
Definition: ftsmooth.c:416
#define PROGDLG_NOMINIMIZE
Definition: shlobj.h:886
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define IDS_CANCELLING
Definition: resource.h:131
DWORD dwTime
Definition: solitaire.cpp:25
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
uint64_t ULONGLONG
Definition: typedefs.h:65
#define WM_TIMER
Definition: winuser.h:1724
#define WM_CLOSE
Definition: winuser.h:1603
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define DWLP_USER
Definition: winuser.h:866
#define UPDATE_LINE2
#define WM_COMMAND
Definition: winuser.h:1722
#define WM_DLG_DESTROY
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define GWL_STYLE
Definition: winuser.h:846
#define WS_MINIMIZEBOX
Definition: pedump.c:631
#define PROGDLG_MARQUEEPROGRESS
Definition: shlobj.h:888
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define UPDATE_LINE3
static void load_string(LPWSTR *buffer, HINSTANCE hInstance, UINT uiResourceId)
#define msg(x)
Definition: auth_time.c:54
#define SetWindowLongPtrW
Definition: winuser.h:5247
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define UPDATE_LINE1
#define WM_DLG_UPDATE
#define IDCANCEL
Definition: winuser.h:825
#define PROGDLG_NOCANCEL
Definition: shlobj.h:889
#define PROGDLG_NOPROGRESSBAR
Definition: shlobj.h:887
BOOL WINAPI PostThreadMessageW(_In_ DWORD, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define ID_3SECONDS

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,
254  dialog_proc,
255  (LPARAM)params);
256 
257  while (GetMessageW(&msg, NULL, 0, 0) > 0)
258  {
259  if (!IsWindow(hwnd))
260  break;
261  if(!IsDialogMessageW(hwnd, &msg))
262  {
265  }
266  }
267 
268  return 0;
269 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define IDD_PROGRESS_DLG
Definition: resource.h:136
BOOL WINAPI IsWindow(_In_opt_ HWND)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
GLenum const GLfloat * params
Definition: glext.h:5645
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
static INT_PTR CALLBACK dialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LPVOID lpParameter
Definition: kernel32.h:241
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define msg(x)
Definition: auth_time.c:54
HWND WINAPI CreateDialogParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
BOOL WINAPI IsDialogMessageW(_In_ HWND, _In_ LPMSG)

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 }
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)
HINSTANCE hInstance
Definition: charmap.c:20
__wchar_t WCHAR
Definition: xmlstorage.h:180
static void set_buffer(LPWSTR *buffer, LPCWSTR string)

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 
83  StringCbCopyW(*buffer, BUFFER_SIZE, string);
84 }
#define BUFFER_SIZE
GLuint buffer
Definition: glext.h:5915
#define UNICODE_NULL
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166

Referenced by load_string(), CProgressDialog::SetCancelMsg(), CProgressDialog::SetLine(), and CProgressDialog::SetTitle().