[SHELL/EXPERIMENTS]
[reactos.git] / base / applications / mscutils / servman / progress.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/progress.c
5 * PURPOSE: Progress dialog box message handler
6 * COPYRIGHT: Copyright 2006-2010 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10 #include "precomp.h"
11
12 #define PROGRESSRANGE 20
13
14 VOID
15 CompleteProgressBar(HWND hProgDlg)
16 {
17 HWND hProgBar;
18 UINT Pos = 0;
19
20 /* Get a handle to the progress bar */
21 hProgBar = GetDlgItem(hProgDlg,
22 IDC_SERVCON_PROGRESS);
23 if (hProgBar)
24 {
25 /* Get the current position */
26 Pos = SendMessageW(hProgBar,
27 PBM_GETPOS,
28 0,
29 0);
30
31 /* Loop until we hit the max */
32 while (Pos <= PROGRESSRANGE)
33 {
34 /* Increment the progress bar */
35 SendMessageW(hProgBar,
36 PBM_DELTAPOS,
37 Pos,
38 0);
39
40 /* Wait for 15ms, it gives it a smooth feel */
41 Sleep(15);
42 Pos++;
43 }
44 }
45 }
46
47 VOID
48 IncrementProgressBar(HWND hProgDlg,
49 UINT NewPos)
50 {
51 HWND hProgBar;
52
53 /* Get a handle to the progress bar */
54 hProgBar = GetDlgItem(hProgDlg,
55 IDC_SERVCON_PROGRESS);
56 if (hProgBar)
57 {
58 /* Do we want to increment the default amount? */
59 if (NewPos == DEFAULT_STEP)
60 {
61 /* Yes, use the step value we set on create */
62 SendMessageW(hProgBar,
63 PBM_STEPIT,
64 0,
65 0);
66 }
67 else
68 {
69 /* No, use the value passed */
70 SendMessageW(hProgBar,
71 PBM_SETPOS,
72 NewPos,
73 0);
74 }
75 }
76 }
77
78 VOID
79 InitializeProgressDialog(HWND hProgDlg,
80 LPWSTR lpServiceName)
81 {
82 /* Write the service name to the dialog */
83 SendDlgItemMessageW(hProgDlg,
84 IDC_SERVCON_NAME,
85 WM_SETTEXT,
86 0,
87 (LPARAM)lpServiceName);
88
89 /* Set the progress bar to the start */
90 SendDlgItemMessageW(hProgDlg,
91 IDC_SERVCON_PROGRESS,
92 PBM_SETPOS,
93 0,
94 0);
95 }
96
97 INT_PTR CALLBACK
98 ProgressDialogProc(HWND hDlg,
99 UINT Message,
100 WPARAM wParam,
101 LPARAM lParam)
102 {
103 switch(Message)
104 {
105 case WM_INITDIALOG:
106 {
107 HWND hProgBar;
108
109 /* Get a handle to the progress bar */
110 hProgBar = GetDlgItem(hDlg,
111 IDC_SERVCON_PROGRESS);
112
113 /* Set the progress bar range */
114 SendMessageW(hProgBar,
115 PBM_SETRANGE,
116 0,
117 MAKELPARAM(0, PROGRESSRANGE));
118
119 /* Set the progress bar step */
120 SendMessageW(hProgBar,
121 PBM_SETSTEP,
122 (WPARAM)1,
123 0);
124 }
125 break;
126
127 case WM_COMMAND:
128 switch(LOWORD(wParam))
129 {
130 case IDOK:
131 DestroyWindow(hDlg);
132 break;
133
134 }
135 break;
136
137 default:
138 return FALSE;
139 }
140
141 return TRUE;
142 }
143
144 HWND
145 CreateProgressDialog(HWND hParent,
146 UINT LabelId)
147 {
148 HWND hProgDlg;
149 LPWSTR lpProgStr;
150
151 /* open the progress dialog */
152 hProgDlg = CreateDialogW(hInstance,
153 MAKEINTRESOURCEW(IDD_DLG_PROGRESS),
154 hParent,
155 ProgressDialogProc);
156 if (hProgDlg != NULL)
157 {
158 /* Load the label Id */
159 if (AllocAndLoadString(&lpProgStr,
160 hInstance,
161 LabelId))
162 {
163 /* Write it to the dialog */
164 SendDlgItemMessageW(hProgDlg,
165 IDC_SERVCON_INFO,
166 WM_SETTEXT,
167 0,
168 (LPARAM)lpProgStr);
169
170 HeapFree(GetProcessHeap(),
171 0,
172 lpProgStr);
173 }
174
175 /* Finally, show and update the progress dialog */
176 ShowWindow(hProgDlg, SW_SHOWNORMAL);
177 UpdateWindow(hProgDlg);
178
179 // TODO: Add a message loop for it ?
180 }
181
182 return hProgDlg;
183 }
184
185 BOOL
186 DestroyProgressDialog(HWND hwnd,
187 BOOL bComplete)
188 {
189 BOOL bRet = FALSE;
190
191 if (hwnd)
192 {
193 if (bComplete)
194 {
195 /* Complete the progress bar */
196 CompleteProgressBar(hwnd);
197
198 /* Wait, for asthetics */
199 Sleep(500);
200 }
201
202 bRet = DestroyWindow(hwnd);
203 }
204
205 return bRet;
206 }