set most of trunk svn property eol-style:native
[reactos.git] / reactos / base / applications / servman / propsheet.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/servman/propsheet.c
5 * PURPOSE: Property dialog box message handler
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
7 *
8 */
9
10 #include "precomp.h"
11
12 static VOID
13 SetButtonStates(PMAIN_WND_INFO Info)
14 {
15 HWND hButton;
16 DWORD Flags, State;
17
18 Flags = Info->CurrentService->ServiceStatusProcess.dwControlsAccepted;
19 State = Info->CurrentService->ServiceStatusProcess.dwCurrentState;
20
21 if (State == SERVICE_STOPPED)
22 {
23 hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_START);
24 EnableWindow (hButton, TRUE);
25 }
26
27 if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
28 {
29 hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_STOP);
30 EnableWindow (hButton, TRUE);
31 }
32
33 if ( (Flags & SERVICE_ACCEPT_PAUSE_CONTINUE) && (State == SERVICE_RUNNING) )
34 {
35 hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_PAUSE);
36 EnableWindow (hButton, TRUE);
37 }
38
39 if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
40 {
41 hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_PAUSE);
42 EnableWindow (hButton, TRUE);
43 }
44 }
45
46 /*
47 * Fills the 'startup type' combo box with possible
48 * values and sets it to value of the selected item
49 */
50 static VOID
51 SetStartupType(PMAIN_WND_INFO Info)
52 {
53 HWND hList;
54 HKEY hKey;
55 TCHAR buf[25];
56 DWORD dwValueSize = 0;
57 DWORD StartUp = 0;
58 LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
59 TCHAR KeyBuf[300];
60
61 /* open the registry key for the service */
62 _sntprintf(KeyBuf,
63 sizeof(KeyBuf) / sizeof(TCHAR),
64 Path,
65 Info->CurrentService->lpServiceName);
66
67 RegOpenKeyEx(HKEY_LOCAL_MACHINE,
68 KeyBuf,
69 0,
70 KEY_READ,
71 &hKey);
72
73 hList = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_START_TYPE);
74
75 LoadString(hInstance, IDS_SERVICES_AUTO, buf, sizeof(buf) / sizeof(TCHAR));
76 SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
77 LoadString(hInstance, IDS_SERVICES_MAN, buf, sizeof(buf) / sizeof(TCHAR));
78 SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
79 LoadString(hInstance, IDS_SERVICES_DIS, buf, sizeof(buf) / sizeof(TCHAR));
80 SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
81
82 dwValueSize = sizeof(DWORD);
83 if (RegQueryValueEx(hKey,
84 _T("Start"),
85 NULL,
86 NULL,
87 (LPBYTE)&StartUp,
88 &dwValueSize))
89 {
90 RegCloseKey(hKey);
91 return;
92 }
93
94 if (StartUp == 0x02)
95 SendMessage(hList, CB_SETCURSEL, 0, 0);
96 else if (StartUp == 0x03)
97 SendMessage(hList, CB_SETCURSEL, 1, 0);
98 else if (StartUp == 0x04)
99 SendMessage(hList, CB_SETCURSEL, 2, 0);
100
101 }
102
103
104 /*
105 * Populates the General Properties dialog with
106 * the relevant service information
107 */
108 static VOID
109 GetDlgInfo(PMAIN_WND_INFO Info)
110 {
111 /* set the service name */
112 Info->PropSheet->lpServiceName = Info->CurrentService->lpServiceName;
113 SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
114 IDC_SERV_NAME,
115 WM_SETTEXT,
116 0,
117 (LPARAM)Info->PropSheet->lpServiceName);
118
119 /* set the display name */
120 Info->PropSheet->lpDisplayName = Info->CurrentService->lpDisplayName;
121 SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
122 IDC_DISP_NAME,
123 WM_SETTEXT,
124 0,
125 (LPARAM)Info->PropSheet->lpDisplayName);
126
127 /* set the description */
128 if (GetDescription(Info->CurrentService->lpServiceName, &Info->PropSheet->lpDescription))
129 SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
130 IDC_DESCRIPTION,
131 WM_SETTEXT,
132 0,
133 (LPARAM)Info->PropSheet->lpDescription);
134
135 /* set the executable path */
136 if (GetExecutablePath(Info, &Info->PropSheet->lpPathToExe))
137 SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
138 IDC_EXEPATH,
139 WM_SETTEXT,
140 0,
141 (LPARAM)Info->PropSheet->lpPathToExe);
142
143 /* set startup type */
144 SetStartupType(Info);
145
146 /* set service status */
147 if (Info->CurrentService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
148 {
149 LoadString(hInstance,
150 IDS_SERVICES_STARTED,
151 Info->PropSheet->szServiceStatus,
152 sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
153
154 SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
155 IDC_SERV_STATUS,
156 WM_SETTEXT,
157 0,
158 (LPARAM)Info->PropSheet->szServiceStatus);
159 }
160 else
161 {
162 LoadString(hInstance,
163 IDS_SERVICES_STOPPED,
164 Info->PropSheet->szServiceStatus,
165 sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
166
167 SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
168 IDC_SERV_STATUS,
169 WM_SETTEXT,
170 0,
171 (LPARAM)Info->PropSheet->szServiceStatus);
172 }
173
174 }
175
176
177
178 /*
179 * General Property dialog callback.
180 * Controls messages to the General dialog
181 */
182 static INT_PTR CALLBACK
183 GeneralPageProc(HWND hwndDlg,
184 UINT uMsg,
185 WPARAM wParam,
186 LPARAM lParam)
187 {
188 PMAIN_WND_INFO Info;
189
190 /* Get the window context */
191 Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg,
192 GWLP_USERDATA);
193
194 if (Info == NULL && uMsg != WM_INITDIALOG)
195 {
196 return FALSE;
197 }
198
199 switch (uMsg)
200 {
201 case WM_INITDIALOG:
202 {
203 Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
204 if (Info != NULL)
205 {
206 Info->PropSheet->hwndGenDlg = hwndDlg;
207
208 SetWindowLongPtr(hwndDlg,
209 GWLP_USERDATA,
210 (LONG_PTR)Info);
211 GetDlgInfo(Info);
212 SetButtonStates(Info);
213 }
214 }
215 break;
216
217 case WM_COMMAND:
218 switch(LOWORD(wParam))
219 {
220 case IDC_START_TYPE:
221 /* Enable the 'Apply' button */
222 //PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
223 break;
224
225 case IDC_START:
226 SendMessage(Info->hMainWnd, WM_COMMAND, ID_START, 0);
227 break;
228
229 case IDC_STOP:
230 SendMessage(Info->hMainWnd, WM_COMMAND, ID_STOP, 0);
231 break;
232
233 case IDC_PAUSE:
234 SendMessage(Info->hMainWnd, WM_COMMAND, ID_PAUSE, 0);
235 break;
236
237 case IDC_RESUME:
238 SendMessage(Info->hMainWnd, WM_COMMAND, ID_RESUME, 0);
239 break;
240
241 case IDC_START_PARAM:
242 /* Enable the 'Apply' button */
243 //PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
244 break;
245
246 }
247 break;
248
249 case WM_DESTROY:
250 break;
251
252 case WM_NOTIFY:
253 {
254 LPNMHDR lpnm = (LPNMHDR)lParam;
255
256 switch (lpnm->code)
257 {
258 case MCN_SELECT:
259 /* Enable the 'Apply' button */
260 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
261 break;
262 }
263 }
264 break;
265 }
266
267 return FALSE;
268 }
269
270
271
272 /*
273 * Dependancies Property dialog callback.
274 * Controls messages to the Dependancies dialog
275 */
276 static INT_PTR CALLBACK
277 DependanciesPageProc(HWND hwndDlg,
278 UINT uMsg,
279 WPARAM wParam,
280 LPARAM lParam)
281 {
282 PMAIN_WND_INFO Info;
283
284 /* Get the window context */
285 Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg,
286 GWLP_USERDATA);
287
288 if (Info == NULL && uMsg != WM_INITDIALOG)
289 {
290 return FALSE;
291 }
292
293 switch (uMsg)
294 {
295 case WM_INITDIALOG:
296 {
297 Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
298 if (Info != NULL)
299 {
300 Info->PropSheet->hwndDepDlg = hwndDlg;
301
302 SetWindowLongPtr(hwndDlg,
303 GWLP_USERDATA,
304 (LONG_PTR)Info);
305 }
306 }
307 break;
308
309 case WM_COMMAND:
310 switch(LOWORD(wParam))
311 {
312
313 }
314 break;
315
316 case WM_DESTROY:
317 break;
318
319 case WM_NOTIFY:
320 {
321 LPNMHDR lpnm = (LPNMHDR)lParam;
322
323 switch (lpnm->code)
324 {
325
326 }
327
328 }
329 break;
330 }
331
332 return FALSE;
333 }
334
335
336 static INT CALLBACK
337 AddEditButton(HWND hwnd, UINT message, LPARAM lParam)
338 {
339 HWND hEditButton;
340
341 switch (message)
342 {
343 case PSCB_PRECREATE:
344 /*hEditButton = CreateWindowEx(0,
345 WC_BUTTON,
346 NULL,
347 WS_CHILD | WS_VISIBLE,
348 20, 300, 30, 15,
349 hwnd,
350 NULL,
351 hInstance,
352 NULL);
353 if (hEditButton == NULL)
354 GetError(0);*/
355
356 hEditButton = GetDlgItem(hwnd, PSBTN_OK);
357 DestroyWindow(hEditButton);
358 //SetWindowText(hEditButton, _T("test"));
359
360 return TRUE;
361 }
362 return TRUE;
363 }
364
365
366
367
368 static VOID
369 InitPropSheetPage(PROPSHEETPAGE *psp,
370 PMAIN_WND_INFO Info,
371 WORD idDlg,
372 DLGPROC DlgProc)
373 {
374 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
375 psp->dwSize = sizeof(PROPSHEETPAGE);
376 psp->dwFlags = PSP_DEFAULT;
377 psp->hInstance = hInstance;
378 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
379 psp->pfnDlgProc = DlgProc;
380 psp->lParam = (LPARAM)Info;
381 }
382
383
384 LONG APIENTRY
385 OpenPropSheet(PMAIN_WND_INFO Info)
386 {
387 PROPSHEETHEADER psh;
388 PROPSHEETPAGE psp[2];
389
390 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
391 psh.dwSize = sizeof(PROPSHEETHEADER);
392 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_USECALLBACK;
393 psh.hwndParent = Info->hMainWnd;
394 psh.hInstance = hInstance;
395 psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
396 psh.pszCaption = Info->CurrentService->lpDisplayName;
397 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
398 psh.nStartPage = 0;
399 psh.pfnCallback = AddEditButton;
400 psh.ppsp = psp;
401
402
403 InitPropSheetPage(&psp[0], Info, IDD_DLG_GENERAL, GeneralPageProc);
404 //InitPropSheetPage(&psp[1], Info, IDD_DLG_GENERAL, LogonPageProc);
405 //InitPropSheetPage(&psp[2], Info, IDD_DLG_GENERAL, RecoveryPageProc);
406 InitPropSheetPage(&psp[1], Info, IDD_DLG_DEPEND, DependanciesPageProc);
407
408 return (LONG)(PropertySheet(&psh) != -1);
409 }
410