ReactOS 0.4.15-dev-7942-gd23573b
progress.c File Reference
#include "precomp.h"
#include <process.h>
Include dependency graph for progress.c:

Go to the source code of this file.

Classes

struct  _PROGRESS_DATA
 

Macros

#define PROGRESS_RANGE   20
 
#define PROGRESS_STEP_MAX   15
 

Typedefs

typedef struct _PROGRESS_DATA PROGRESS_DATA
 
typedef struct _PROGRESS_DATAPPROGRESS_DATA
 

Functions

VOID ShowError (DWORD dwLastError)
 
static VOID ResetProgressDialog (HWND hDlg, LPWSTR ServiceName, ULONG LabelId)
 
unsigned int __stdcall ActionThread (void *Param)
 
static BOOL InitProgressDialog (HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
 
INT_PTR CALLBACK ProgressDialogProc (HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
 
VOID CompleteProgressBar (HANDLE hProgress)
 
VOID IncrementProgressBar (HANDLE hProgress, UINT Step)
 
BOOL RunActionWithProgress (HWND hParent, LPWSTR ServiceName, LPWSTR DisplayName, UINT Action, PVOID Param)
 

Macro Definition Documentation

◆ PROGRESS_RANGE

#define PROGRESS_RANGE   20

Definition at line 14 of file progress.c.

◆ PROGRESS_STEP_MAX

#define PROGRESS_STEP_MAX   15

Definition at line 15 of file progress.c.

Typedef Documentation

◆ PPROGRESS_DATA

◆ PROGRESS_DATA

Function Documentation

◆ ActionThread()

unsigned int __stdcall ActionThread ( void Param)

Definition at line 86 of file progress.c.

87{
88 PPROGRESS_DATA ProgressData = (PPROGRESS_DATA)Param;
89 DWORD dwResult;
90
91 if (ProgressData->Action == ACTION_START)
92 {
93 /* Setup the progress dialog for this action */
94 ResetProgressDialog(ProgressData->hDlg,
95 ProgressData->ServiceName,
97
98 /* Start the service */
99 dwResult = DoStartService(ProgressData->ServiceName,
100 ProgressData->hProgress,
101 ProgressData->Param);
102 if (dwResult == ERROR_SUCCESS)
103 {
104 /* We're done, slide the progress bar up to the top */
105 CompleteProgressBar(ProgressData->hProgress);
106 }
107 else
108 {
109 ShowError(dwResult);
110 }
111 }
112 else if (ProgressData->Action == ACTION_STOP || ProgressData->Action == ACTION_RESTART)
113 {
114 /* Check if there are and dependants to stop */
115 if (ProgressData->StopDepends && ProgressData->ServiceList)
116 {
117 LPWSTR lpStr = ProgressData->ServiceList;
118
119 /* Loop through all the services in the list */
120 for (;;)
121 {
122 /* Break when we hit the double null */
123 if (*lpStr == L'\0' && *(lpStr + 1) == L'\0')
124 break;
125
126 /* If this isn't our first time in the loop we'll
127 have been left on a null char */
128 if (*lpStr == L'\0')
129 lpStr++;
130
131 ResetProgressDialog(ProgressData->hDlg,
132 lpStr,
134
135 /* Stop the requested service */
136 dwResult = DoStopService(ProgressData->ServiceName,
137 ProgressData->hProgress);
138 if (dwResult == ERROR_SUCCESS)
139 {
140 CompleteProgressBar(ProgressData->hProgress);
141 }
142 else
143 {
144 ShowError(dwResult);
145 }
146
147 /* Move onto the next string */
148 while (*lpStr != L'\0')
149 lpStr++;
150 }
151 }
152
153 ResetProgressDialog(ProgressData->hDlg,
154 ProgressData->ServiceName,
156
157 dwResult = DoStopService(ProgressData->ServiceName,
158 ProgressData->hProgress);
159 if (dwResult == ERROR_SUCCESS)
160 {
161 CompleteProgressBar(ProgressData->hProgress);
162 }
163 else
164 {
165 ShowError(dwResult);
166 }
167
168
169 /* If this was a restart, we'll need to start the service back up */
170 if (ProgressData->Action == ACTION_RESTART)
171 {
172 /* Setup the progress dialog for this action */
173 ResetProgressDialog(ProgressData->hDlg,
174 ProgressData->ServiceName,
176
177 /* Start the service */
178 dwResult = DoStartService(ProgressData->ServiceName,
179 ProgressData->hProgress,
180 NULL);
181 if (dwResult == ERROR_SUCCESS)
182 {
183 /* We're done, slide the progress bar up to the top */
184 CompleteProgressBar(ProgressData->hProgress);
185 }
186 else
187 {
188 ShowError(dwResult);
189 }
190 }
191 }
192 else if (ProgressData->Action == ACTION_PAUSE)
193 {
194 /* Setup the progress dialog for this action */
195 ResetProgressDialog(ProgressData->hDlg,
196 ProgressData->ServiceName,
198
199 /* Pause the service */
200 dwResult = DoControlService(ProgressData->ServiceName,
201 ProgressData->hProgress,
203 if (dwResult == ERROR_SUCCESS)
204 {
205 /* We're done, slide the progress bar up to the top */
206 CompleteProgressBar(ProgressData->hProgress);
207 }
208 else
209 {
210 ShowError(dwResult);
211 }
212 }
213 else if (ProgressData->Action == ACTION_RESUME)
214 {
215 /* Setup the progress dialog for this action */
216 ResetProgressDialog(ProgressData->hDlg,
217 ProgressData->ServiceName,
219
220 /* resume the service */
221 dwResult = DoControlService(ProgressData->ServiceName,
222 ProgressData->hProgress,
224 if (dwResult == ERROR_SUCCESS)
225 {
226 /* We're done, slide the progress bar up to the top */
227 CompleteProgressBar(ProgressData->hProgress);
228 }
229 else
230 {
231 ShowError(dwResult);
232 }
233 }
234
235
236 EndDialog(ProgressData->hDlg, IDOK);
237
238 _endthreadex(0);
239 return 0;
240}
DWORD DoControlService(LPWSTR ServiceName, HWND hProgress, DWORD Control)
Definition: control.c:18
#define ACTION_START
Definition: precomp.h:40
#define ACTION_RESTART
Definition: precomp.h:44
DWORD DoStartService(LPWSTR ServiceName, HANDLE hProgress, LPWSTR lpStartParams)
Definition: start.c:18
#define ACTION_PAUSE
Definition: precomp.h:42
DWORD DoStopService(LPWSTR ServiceName, HANDLE hProgress)
#define ACTION_STOP
Definition: precomp.h:41
#define ACTION_RESUME
Definition: precomp.h:43
struct _PROGRESS_DATA * PPROGRESS_DATA
static VOID ResetProgressDialog(HWND hDlg, LPWSTR ServiceName, ULONG LabelId)
Definition: progress.c:50
VOID ShowError(DWORD dwLastError)
Definition: progress.c:29
VOID CompleteProgressBar(HANDLE hProgress)
Definition: progress.c:311
#define IDS_PROGRESS_INFO_STOP
Definition: resource.h:208
#define IDS_PROGRESS_INFO_START
Definition: resource.h:207
#define IDS_PROGRESS_INFO_PAUSE
Definition: resource.h:209
#define IDS_PROGRESS_INFO_RESUME
Definition: resource.h:210
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
#define L(x)
Definition: ntvdm.h:50
_CRTIMP void __cdecl _endthreadex(_In_ unsigned _Retval)
LPWSTR ServiceList
Definition: progress.c:24
BOOL StopDepends
Definition: progress.c:23
HWND hProgress
Definition: progress.c:20
ULONG Action
Definition: progress.c:22
PVOID Param
Definition: progress.c:25
LPWSTR ServiceName
Definition: progress.c:21
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define IDOK
Definition: winuser.h:830
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by InitProgressDialog().

◆ CompleteProgressBar()

VOID CompleteProgressBar ( HANDLE  hProgress)

Definition at line 311 of file progress.c.

312{
313 HWND hProgBar = (HWND)hProgress;
314 UINT Pos = 0;
315
316 /* Get the current position */
317 Pos = SendMessageW(hProgBar,
319 0,
320 0);
321
322 /* Loop until we hit the max */
323 while (Pos <= PROGRESS_RANGE)
324 {
325 /* Increment the progress bar */
326 SendMessageW(hProgBar,
328 Pos,
329 0);
330
331 /* Wait for 15ms to give it a smooth feel */
332 Sleep(15);
333 Pos++;
334 }
335}
#define PROGRESS_RANGE
Definition: progress.c:14
ush Pos
Definition: deflate.h:92
HANDLE HWND
Definition: compat.h:19
unsigned int UINT
Definition: ndis.h:50
#define PBM_GETPOS
Definition: commctrl.h:2194
#define PBM_DELTAPOS
Definition: commctrl.h:2185
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by ActionThread().

◆ IncrementProgressBar()

VOID IncrementProgressBar ( HANDLE  hProgress,
UINT  Step 
)

Definition at line 338 of file progress.c.

340{
341 HWND hProgBar = (HWND)hProgress;
343
344 /* Don't allow the progress to reach to complete*/
345 Position = SendMessageW(hProgBar,
347 0,
348 0);
350 {
351 /* Do we want to increment the default amount? */
352 if (Step == DEFAULT_STEP)
353 {
354 /* Use the step value we set on create */
355 SendMessageW(hProgBar,
357 0,
358 0);
359 }
360 else
361 {
362 /* Use the value passed */
363 SendMessageW(hProgBar,
365 Step,
366 0);
367 }
368 }
369}
#define DEFAULT_STEP
Definition: precomp.h:111
#define PROGRESS_STEP_MAX
Definition: progress.c:15
#define PBM_SETPOS
Definition: commctrl.h:2184
#define PBM_STEPIT
Definition: commctrl.h:2187
static COORD Position
Definition: mouse.c:34

Referenced by DoControlService(), DoStartService(), and DoStopService().

◆ InitProgressDialog()

static BOOL InitProgressDialog ( HWND  hDlg,
UINT  Message,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 243 of file progress.c.

247{
248 PPROGRESS_DATA ProgressData = (PPROGRESS_DATA)lParam;
250
251 ProgressData->hDlg = hDlg;
252
253 /* Get a handle to the progress bar */
254 ProgressData->hProgress = GetDlgItem(hDlg,
256 if (!ProgressData->hProgress)
257 return FALSE;
258
259 /* Set the progress bar range */
260 SendMessageW(ProgressData->hProgress,
262 0,
264
265 /* Set the progress bar step */
266 SendMessageW(ProgressData->hProgress,
268 (WPARAM)1,
269 0);
270
271 /* Create a thread to handle the service control */
272 hThread = (HANDLE)_beginthreadex(NULL, 0, &ActionThread, ProgressData, 0, NULL);
273 if (!hThread) return FALSE;
274
276
277 return TRUE;
278}
unsigned int __stdcall ActionThread(void *Param)
Definition: progress.c:86
#define IDC_SERVCON_PROGRESS
Definition: resource.h:204
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
HANDLE hThread
Definition: wizard.c:28
#define PBM_SETSTEP
Definition: commctrl.h:2186
#define PBM_SETRANGE
Definition: commctrl.h:2183
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
PVOID HANDLE
Definition: typedefs.h:73
UINT_PTR WPARAM
Definition: windef.h:207
#define MAKELPARAM(l, h)
Definition: winuser.h:4008
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)

Referenced by ProgressDialogProc().

◆ ProgressDialogProc()

INT_PTR CALLBACK ProgressDialogProc ( HWND  hDlg,
UINT  Message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 281 of file progress.c.

285{
286 switch(Message)
287 {
288 case WM_INITDIALOG:
289 {
290 return InitProgressDialog(hDlg, Message, wParam, lParam);
291 }
292
293 case WM_COMMAND:
294 switch(LOWORD(wParam))
295 {
296 case IDOK:
297 EndDialog(hDlg, wParam);
298 break;
299
300 }
301 break;
302
303 default:
304 return FALSE;
305 }
306
307 return TRUE;
308}
static BOOL InitProgressDialog(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: progress.c:243
WPARAM wParam
Definition: combotst.c:138
static const WCHAR Message[]
Definition: register.c:74
#define LOWORD(l)
Definition: pedump.c:82
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739

Referenced by RunActionWithProgress().

◆ ResetProgressDialog()

static VOID ResetProgressDialog ( HWND  hDlg,
LPWSTR  ServiceName,
ULONG  LabelId 
)
static

Definition at line 50 of file progress.c.

53{
54 LPWSTR lpProgStr;
55
56 /* Load the label Id */
57 if (AllocAndLoadString(&lpProgStr,
59 LabelId))
60 {
61 /* Write it to the dialog */
65 0,
66 (LPARAM)lpProgStr);
67
68 LocalFree(lpProgStr);
69 }
70
71 /* Write the service name to the dialog */
75 0,
77
78 /* Set the progress bar to the start */
82 0,
83 0);
84}
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
#define IDC_SERVCON_INFO
Definition: resource.h:205
#define IDC_SERVCON_NAME
Definition: resource.h:206
static WCHAR ServiceName[]
Definition: browser.c:19
HINSTANCE hInstance
Definition: charmap.c:19
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
LONG_PTR LPARAM
Definition: windef.h:208
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_SETTEXT
Definition: winuser.h:1617

Referenced by ActionThread().

◆ RunActionWithProgress()

BOOL RunActionWithProgress ( HWND  hParent,
LPWSTR  ServiceName,
LPWSTR  DisplayName,
UINT  Action,
PVOID  Param 
)

Definition at line 372 of file progress.c.

377{
378 PROGRESS_DATA ProgressData;
379 LPWSTR ServiceList;
380 BOOL StopDepends;
382
383 StopDepends = FALSE;
384 ServiceList = NULL;
385
386
387 /* Check if we'll be stopping the service */
389 {
390 /* Does the service have any dependent services which need stopping first */
392 if (ServiceList)
393 {
394 /* Ask the user if they want to stop the dependants */
395 StopDepends = CreateStopDependsDialog(hParent,
397 DisplayName,
398 ServiceList);
399
400 /* Exit early if the user decided not to stop the dependants */
401 if (StopDepends == FALSE)
402 {
403 HeapFree(GetProcessHeap(), 0, ServiceList);
404 return FALSE;
405 }
406 }
407 }
408
409 ProgressData.hDlg = NULL;
410 ProgressData.ServiceName = ServiceName;
411 ProgressData.Action = Action;
412 ProgressData.StopDepends = StopDepends;
413 ProgressData.ServiceList = ServiceList;
414 ProgressData.Param = Param;
415
418 hParent,
420 (LPARAM)&ProgressData);
421
422 if (ServiceList)
423 HeapFree(GetProcessHeap(), 0, ServiceList);
424
425 return (Result == IDOK);
426}
LPWSTR GetListOfServicesToStop(LPWSTR lpServiceName)
BOOL CreateStopDependsDialog(HWND hParent, LPWSTR ServiceName, LPWSTR DisplayName, LPWSTR ServiceList)
INT_PTR CALLBACK ProgressDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
Definition: progress.c:281
#define IDD_DLG_PROGRESS
Definition: resource.h:203
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
int32_t INT_PTR
Definition: typedefs.h:64
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by GeneralPageProc(), and MainWndCommand().

◆ ShowError()

VOID ShowError ( DWORD  dwLastError)

Definition at line 29 of file progress.c.

30{
31 LPWSTR lpMsg;
32
36 NULL,
37 dwLastError,
39 (LPWSTR)&lpMsg,
40 0, NULL))
41 {
42 return;
43 }
44
46 LocalFree(lpMsg);
47}
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:787
#define MB_OK
Definition: winuser.h:790

Referenced by ActionThread(), DoLoadImageFile(), CMainWindow::OnCommand(), and SaveDIBToFile().