2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/propsheet_general.c
5 * PURPOSE: Property dialog box message handler
6 * COPYRIGHT: Copyright 2006-2009 Ged Murphy <gedmurphy@reactos.org>
13 SetButtonStates(PSERVICEPROPSHEET dlgInfo
,
17 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
21 Flags
= dlgInfo
->pService
->ServiceStatusProcess
.dwControlsAccepted
;
22 State
= dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
;
24 for (i
= IDC_START
; i
<= IDC_RESUME
; i
++)
26 hButton
= GetDlgItem(hwndDlg
, i
);
27 EnableWindow (hButton
, FALSE
);
30 lpServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
31 if (State
== SERVICE_STOPPED
&&
32 lpServiceConfig
&& lpServiceConfig
->dwStartType
!= SERVICE_DISABLED
)
34 hButton
= GetDlgItem(hwndDlg
, IDC_START
);
35 EnableWindow (hButton
, TRUE
);
37 else if ( (Flags
& SERVICE_ACCEPT_STOP
) && (State
== SERVICE_RUNNING
) )
39 hButton
= GetDlgItem(hwndDlg
, IDC_STOP
);
40 EnableWindow (hButton
, TRUE
);
42 else if ( (Flags
& SERVICE_ACCEPT_PAUSE_CONTINUE
) && (State
== SERVICE_RUNNING
) )
44 hButton
= GetDlgItem(hwndDlg
, IDC_PAUSE
);
45 EnableWindow (hButton
, TRUE
);
49 HeapFree(GetProcessHeap(), 0, lpServiceConfig
);
51 hButton
= GetDlgItem(hwndDlg
, IDC_START_PARAM
);
52 EnableWindow(hButton
, (State
== SERVICE_STOPPED
));
54 /* set the main toolbar */
55 SetMenuAndButtonStates(dlgInfo
->Info
);
59 SetServiceStatusText(PSERVICEPROPSHEET dlgInfo
,
65 if (dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
67 id
= IDS_SERVICES_STARTED
;
71 id
= IDS_SERVICES_STOPPED
;
74 if (AllocAndLoadString(&lpStatus
,
78 SendDlgItemMessageW(hwndDlg
,
88 * Fills the 'startup type' combo box with possible
89 * values and sets it to value of the selected item
92 SetStartupType(LPWSTR lpServiceName
,
96 LPQUERY_SERVICE_CONFIG pServiceConfig
;
101 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
103 for (i
= IDS_SERVICES_AUTO
; i
<= IDS_SERVICES_DIS
; i
++)
105 if (AllocAndLoadString(&lpBuf
,
117 pServiceConfig
= GetServiceConfig(lpServiceName
);
121 switch (pServiceConfig
->dwStartType
)
123 case SERVICE_AUTO_START
: StartUp
= 0; break;
124 case SERVICE_DEMAND_START
: StartUp
= 1; break;
125 case SERVICE_DISABLED
: StartUp
= 2; break;
133 HeapFree(ProcessHeap
,
140 * Populates the General Properties dialog with
141 * the relevant service information
144 InitGeneralPage(PSERVICEPROPSHEET dlgInfo
,
147 LPQUERY_SERVICE_CONFIG pServiceConfig
;
148 LPWSTR lpDescription
;
150 /* set the service name */
151 SendDlgItemMessageW(hwndDlg
,
155 (LPARAM
)dlgInfo
->pService
->lpServiceName
);
157 /* set the display name */
158 SendDlgItemMessageW(hwndDlg
,
162 (LPARAM
)dlgInfo
->pService
->lpDisplayName
);
164 /* set the description */
165 if ((lpDescription
= GetServiceDescription(dlgInfo
->pService
->lpServiceName
)))
167 SendDlgItemMessageW(hwndDlg
,
171 (LPARAM
)lpDescription
);
173 HeapFree(ProcessHeap
,
178 pServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
181 SendDlgItemMessageW(hwndDlg
,
185 (LPARAM
)pServiceConfig
->lpBinaryPathName
);
186 HeapFree(ProcessHeap
,
192 /* set startup type */
193 SetStartupType(dlgInfo
->pService
->lpServiceName
, hwndDlg
);
195 SetServiceStatusText(dlgInfo
,
198 if (dlgInfo
->Info
->bIsUserAnAdmin
)
200 HWND hEdit
= GetDlgItem(hwndDlg
,
208 SaveDlgInfo(PSERVICEPROPSHEET dlgInfo
,
211 LPQUERY_SERVICE_CONFIG pServiceConfig
= NULL
;
215 pServiceConfig
= HeapAlloc(ProcessHeap
,
217 sizeof(*pServiceConfig
));
220 pServiceConfig
->dwServiceType
= SERVICE_NO_CHANGE
;
221 pServiceConfig
->dwErrorControl
= SERVICE_NO_CHANGE
;
223 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
224 StartUp
= SendMessage(hList
,
230 case 0: pServiceConfig
->dwStartType
= SERVICE_AUTO_START
; break;
231 case 1: pServiceConfig
->dwStartType
= SERVICE_DEMAND_START
; break;
232 case 2: pServiceConfig
->dwStartType
= SERVICE_DISABLED
; break;
235 if (SetServiceConfig(pServiceConfig
,
236 dlgInfo
->pService
->lpServiceName
,
239 ChangeListViewText(dlgInfo
->Info
,
244 HeapFree(ProcessHeap
,
251 * General Property dialog callback.
252 * Controls messages to the General dialog
255 GeneralPageProc(HWND hwndDlg
,
260 PSERVICEPROPSHEET dlgInfo
;
262 /* Get the window context */
263 dlgInfo
= (PSERVICEPROPSHEET
)GetWindowLongPtr(hwndDlg
,
265 if (dlgInfo
== NULL
&& uMsg
!= WM_INITDIALOG
)
274 dlgInfo
= (PSERVICEPROPSHEET
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
277 SetWindowLongPtr(hwndDlg
,
280 InitGeneralPage(dlgInfo
, hwndDlg
);
281 SetButtonStates(dlgInfo
, hwndDlg
);
287 switch(LOWORD(wParam
))
290 if (HIWORD(wParam
) == CBN_SELCHANGE
)
291 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
296 WCHAR szStartParams
[256];
297 LPWSTR lpStartParams
= NULL
;
299 if (GetDlgItemText(hwndDlg
, IDC_START_PARAM
, szStartParams
, 256) > 0)
300 lpStartParams
= szStartParams
;
302 RunActionWithProgress(hwndDlg
,
303 dlgInfo
->pService
->lpServiceName
,
304 dlgInfo
->pService
->lpDisplayName
,
308 UpdateServiceStatus(dlgInfo
->pService
);
309 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
310 SetButtonStates(dlgInfo
, hwndDlg
);
311 SetServiceStatusText(dlgInfo
, hwndDlg
);
316 RunActionWithProgress(hwndDlg
,
317 dlgInfo
->pService
->lpServiceName
,
318 dlgInfo
->pService
->lpDisplayName
,
322 UpdateServiceStatus(dlgInfo
->pService
);
323 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
324 SetButtonStates(dlgInfo
, hwndDlg
);
325 SetServiceStatusText(dlgInfo
, hwndDlg
);
329 RunActionWithProgress(hwndDlg
,
330 dlgInfo
->pService
->lpServiceName
,
331 dlgInfo
->pService
->lpDisplayName
,
335 UpdateServiceStatus(dlgInfo
->pService
);
336 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
337 SetButtonStates(dlgInfo
, hwndDlg
);
338 SetServiceStatusText(dlgInfo
, hwndDlg
);
342 RunActionWithProgress(hwndDlg
,
343 dlgInfo
->pService
->lpServiceName
,
344 dlgInfo
->pService
->lpDisplayName
,
348 UpdateServiceStatus(dlgInfo
->pService
);
349 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
350 SetButtonStates(dlgInfo
, hwndDlg
);
351 SetServiceStatusText(dlgInfo
, hwndDlg
);
356 HWND hName
, hDesc
, hExePath
;
358 hName
= GetDlgItem(hwndDlg
, IDC_DISP_NAME
);
359 hDesc
= GetDlgItem(hwndDlg
, IDC_DESCRIPTION
);
360 hExePath
= GetDlgItem(hwndDlg
, IDC_EXEPATH
);
362 SendMessage(hName
, EM_SETREADONLY
, FALSE
, 0);
363 SendMessage(hDesc
, EM_SETREADONLY
, FALSE
, 0);
364 SendMessage(hExePath
, EM_SETREADONLY
, FALSE
, 0);
368 case IDC_START_PARAM
:
369 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
376 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
381 SaveDlgInfo(dlgInfo
, hwndDlg
);
382 SetButtonStates(dlgInfo
, hwndDlg
);