2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/propsheet.c
5 * PURPOSE: Property dialog box message handler
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
12 typedef struct _SERVICEPROPSHEET
15 ENUM_SERVICE_STATUS_PROCESS
*pService
;
16 } SERVICEPROPSHEET
, *PSERVICEPROPSHEET
;
20 SetButtonStates(PSERVICEPROPSHEET dlgInfo
,
24 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
28 Flags
= dlgInfo
->pService
->ServiceStatusProcess
.dwControlsAccepted
;
29 State
= dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
;
31 for (i
= IDC_START
; i
<= IDC_RESUME
; i
++)
33 hButton
= GetDlgItem(hwndDlg
, i
);
34 EnableWindow (hButton
, FALSE
);
37 lpServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
38 if (State
== SERVICE_STOPPED
&&
39 lpServiceConfig
&& lpServiceConfig
->dwStartType
!= SERVICE_DISABLED
)
41 hButton
= GetDlgItem(hwndDlg
, IDC_START
);
42 EnableWindow (hButton
, TRUE
);
43 HeapFree(GetProcessHeap(), 0, lpServiceConfig
);
45 else if ( (Flags
& SERVICE_ACCEPT_STOP
) && (State
== SERVICE_RUNNING
) )
47 hButton
= GetDlgItem(hwndDlg
, IDC_STOP
);
48 EnableWindow (hButton
, TRUE
);
50 else if ( (Flags
& SERVICE_ACCEPT_PAUSE_CONTINUE
) && (State
== SERVICE_RUNNING
) )
52 hButton
= GetDlgItem(hwndDlg
, IDC_PAUSE
);
53 EnableWindow (hButton
, TRUE
);
56 /* set the main toolbar */
57 SetMenuAndButtonStates(dlgInfo
->Info
);
62 SetServiceStatusText(PSERVICEPROPSHEET dlgInfo
,
68 if (dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
70 id
= IDS_SERVICES_STARTED
;
74 id
= IDS_SERVICES_STOPPED
;
77 if (AllocAndLoadString(&lpStatus
,
81 SendDlgItemMessage(hwndDlg
,
91 * Fills the 'startup type' combo box with possible
92 * values and sets it to value of the selected item
95 SetStartupType(LPTSTR lpServiceName
,
99 LPQUERY_SERVICE_CONFIG pServiceConfig
;
104 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
106 for (i
= IDS_SERVICES_AUTO
; i
<= IDS_SERVICES_DIS
; i
++)
108 if (AllocAndLoadString(&lpBuf
,
120 pServiceConfig
= GetServiceConfig(lpServiceName
);
124 switch (pServiceConfig
->dwStartType
)
126 case SERVICE_AUTO_START
: StartUp
= 0; break;
127 case SERVICE_DEMAND_START
: StartUp
= 1; break;
128 case SERVICE_DISABLED
: StartUp
= 2; break;
136 HeapFree(ProcessHeap
,
144 * Populates the General Properties dialog with
145 * the relevant service information
148 InitGeneralPage(PSERVICEPROPSHEET dlgInfo
,
151 LPQUERY_SERVICE_CONFIG pServiceConfig
;
152 LPTSTR lpDescription
;
154 /* set the service name */
155 SendDlgItemMessage(hwndDlg
,
159 (LPARAM
)dlgInfo
->pService
->lpServiceName
);
161 /* set the display name */
162 SendDlgItemMessage(hwndDlg
,
166 (LPARAM
)dlgInfo
->pService
->lpDisplayName
);
168 /* set the description */
169 if ((lpDescription
= GetServiceDescription(dlgInfo
->pService
->lpServiceName
)))
171 SendDlgItemMessage(hwndDlg
,
175 (LPARAM
)lpDescription
);
177 HeapFree(ProcessHeap
,
182 pServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
185 SendDlgItemMessage(hwndDlg
,
189 (LPARAM
)pServiceConfig
->lpBinaryPathName
);
190 HeapFree(ProcessHeap
,
196 /* set startup type */
197 SetStartupType(dlgInfo
->pService
->lpServiceName
, hwndDlg
);
199 SetServiceStatusText(dlgInfo
,
202 if (dlgInfo
->Info
->bIsUserAnAdmin
)
204 HWND hEdit
= GetDlgItem(hwndDlg
,
213 SaveDlgInfo(PSERVICEPROPSHEET dlgInfo
,
216 LPQUERY_SERVICE_CONFIG pServiceConfig
= NULL
;
220 pServiceConfig
= HeapAlloc(ProcessHeap
,
222 sizeof(*pServiceConfig
));
225 pServiceConfig
->dwServiceType
= SERVICE_NO_CHANGE
;
226 pServiceConfig
->dwErrorControl
= SERVICE_NO_CHANGE
;
228 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
229 StartUp
= SendMessage(hList
,
235 case 0: pServiceConfig
->dwStartType
= SERVICE_AUTO_START
; break;
236 case 1: pServiceConfig
->dwStartType
= SERVICE_DEMAND_START
; break;
237 case 2: pServiceConfig
->dwStartType
= SERVICE_DISABLED
; break;
240 if (SetServiceConfig(pServiceConfig
,
241 dlgInfo
->pService
->lpServiceName
,
244 ChangeListViewText(dlgInfo
->Info
,
249 HeapFree(ProcessHeap
,
257 * General Property dialog callback.
258 * Controls messages to the General dialog
260 static INT_PTR CALLBACK
261 GeneralPageProc(HWND hwndDlg
,
266 PSERVICEPROPSHEET dlgInfo
;
268 /* Get the window context */
269 dlgInfo
= (PSERVICEPROPSHEET
)GetWindowLongPtr(hwndDlg
,
271 if (dlgInfo
== NULL
&& uMsg
!= WM_INITDIALOG
)
280 dlgInfo
= (PSERVICEPROPSHEET
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
283 SetWindowLongPtr(hwndDlg
,
286 InitGeneralPage(dlgInfo
, hwndDlg
);
287 SetButtonStates(dlgInfo
, hwndDlg
);
293 switch(LOWORD(wParam
))
296 if (HIWORD(wParam
) == CBN_SELCHANGE
)
297 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
301 if (DoStart(dlgInfo
->Info
))
303 UpdateServiceStatus(dlgInfo
->pService
);
304 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
305 SetButtonStates(dlgInfo
, hwndDlg
);
306 SetServiceStatusText(dlgInfo
, hwndDlg
);
311 if (DoStop(dlgInfo
->Info
))
313 UpdateServiceStatus(dlgInfo
->pService
);
314 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
315 SetButtonStates(dlgInfo
, hwndDlg
);
316 SetServiceStatusText(dlgInfo
, hwndDlg
);
321 if (DoPause(dlgInfo
->Info
))
323 UpdateServiceStatus(dlgInfo
->pService
);
324 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
325 SetButtonStates(dlgInfo
, hwndDlg
);
326 SetServiceStatusText(dlgInfo
, hwndDlg
);
331 if (DoResume(dlgInfo
->Info
))
333 UpdateServiceStatus(dlgInfo
->pService
);
334 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
335 SetButtonStates(dlgInfo
, hwndDlg
);
336 SetServiceStatusText(dlgInfo
, hwndDlg
);
342 HWND hName
, hDesc
, hExePath
;
344 hName
= GetDlgItem(hwndDlg
, IDC_DISP_NAME
);
345 hDesc
= GetDlgItem(hwndDlg
, IDC_DESCRIPTION
);
346 hExePath
= GetDlgItem(hwndDlg
, IDC_EXEPATH
);
348 SendMessage(hName
, EM_SETREADONLY
, FALSE
, 0);
349 SendMessage(hDesc
, EM_SETREADONLY
, FALSE
, 0);
350 SendMessage(hExePath
, EM_SETREADONLY
, FALSE
, 0);
354 case IDC_START_PARAM
:
355 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
362 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
367 SaveDlgInfo(dlgInfo
, hwndDlg
);
368 SetButtonStates(dlgInfo
, hwndDlg
);
379 InitDependPage(PSERVICEPROPSHEET dlgInfo,
389 * Dependancies Property dialog callback.
390 * Controls messages to the Dependancies dialog
392 static INT_PTR CALLBACK
393 DependanciesPageProc(HWND hwndDlg,
398 PSERVICEPROPSHEET dlgInfo;
400 dlgInfo = (PSERVICEPROPSHEET)GetWindowLongPtr(hwndDlg,
403 if (dlgInfo == NULL && uMsg != WM_INITDIALOG)
412 dlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam);
415 SetWindowLongPtr(hwndDlg,
419 InitDependPage(dlgInfo, hwndDlg);
425 switch(LOWORD(wParam))
437 InitPropSheetPage(PROPSHEETPAGE
*psp
,
438 PSERVICEPROPSHEET dlgInfo
,
442 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
443 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
444 psp
->dwFlags
= PSP_DEFAULT
;
445 psp
->hInstance
= hInstance
;
446 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
447 psp
->pfnDlgProc
= DlgProc
;
448 psp
->lParam
= (LPARAM
)dlgInfo
;
453 OpenPropSheet(PMAIN_WND_INFO Info
)
456 PROPSHEETPAGE psp
[1];
457 PSERVICEPROPSHEET pServicePropSheet
;
460 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
461 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
462 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
| PSH_USECALLBACK
;// | PSH_MODELESS;
463 psh
.hwndParent
= Info
->hMainWnd
;
464 psh
.hInstance
= hInstance
;
465 psh
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
));
466 psh
.pszCaption
= Info
->pCurrentService
->lpDisplayName
;
467 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
472 pServicePropSheet
= HeapAlloc(ProcessHeap
,
474 sizeof(*pServicePropSheet
));
475 if (pServicePropSheet
)
477 /* save current service, as it could change while the dialog is open */
478 pServicePropSheet
->pService
= Info
->pCurrentService
;
479 pServicePropSheet
->Info
= Info
;
481 InitPropSheetPage(&psp
[0], pServicePropSheet
, IDD_DLG_GENERAL
, GeneralPageProc
);
482 //InitPropSheetPage(&psp[1], Info, IDD_DLG_GENERAL, LogonPageProc);
483 //InitPropSheetPage(&psp[2], Info, IDD_DLG_GENERAL, RecoveryPageProc);
484 //InitPropSheetPage(&psp[1], pServicePropSheet, IDD_DLG_DEPEND, DependanciesPageProc);
486 Ret
= (LONG
)(PropertySheet(&psh
) != -1);
488 HeapFree(ProcessHeap
,