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>
15 SetButtonStates(PSERVICEPROPSHEET dlgInfo
,
19 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
23 Flags
= dlgInfo
->pService
->ServiceStatusProcess
.dwControlsAccepted
;
24 State
= dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
;
26 for (i
= IDC_START
; i
<= IDC_RESUME
; i
++)
28 hButton
= GetDlgItem(hwndDlg
, i
);
29 EnableWindow (hButton
, FALSE
);
32 lpServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
33 if (State
== SERVICE_STOPPED
&&
34 lpServiceConfig
&& lpServiceConfig
->dwStartType
!= SERVICE_DISABLED
)
36 hButton
= GetDlgItem(hwndDlg
, IDC_START
);
37 EnableWindow (hButton
, TRUE
);
38 HeapFree(GetProcessHeap(), 0, lpServiceConfig
);
40 else if ( (Flags
& SERVICE_ACCEPT_STOP
) && (State
== SERVICE_RUNNING
) )
42 hButton
= GetDlgItem(hwndDlg
, IDC_STOP
);
43 EnableWindow (hButton
, TRUE
);
45 else if ( (Flags
& SERVICE_ACCEPT_PAUSE_CONTINUE
) && (State
== SERVICE_RUNNING
) )
47 hButton
= GetDlgItem(hwndDlg
, IDC_PAUSE
);
48 EnableWindow (hButton
, TRUE
);
51 hButton
= GetDlgItem(hwndDlg
, IDC_START_PARAM
);
52 EnableWindow(hButton
, (State
== SERVICE_STOPPED
));
54 /* set the main toolbar */
55 SetMenuAndButtonStates(dlgInfo
->Info
);
60 SetServiceStatusText(PSERVICEPROPSHEET dlgInfo
,
66 if (dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
68 id
= IDS_SERVICES_STARTED
;
72 id
= IDS_SERVICES_STOPPED
;
75 if (AllocAndLoadString(&lpStatus
,
79 SendDlgItemMessage(hwndDlg
,
89 * Fills the 'startup type' combo box with possible
90 * values and sets it to value of the selected item
93 SetStartupType(LPTSTR lpServiceName
,
97 LPQUERY_SERVICE_CONFIG pServiceConfig
;
102 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
104 for (i
= IDS_SERVICES_AUTO
; i
<= IDS_SERVICES_DIS
; i
++)
106 if (AllocAndLoadString(&lpBuf
,
118 pServiceConfig
= GetServiceConfig(lpServiceName
);
122 switch (pServiceConfig
->dwStartType
)
124 case SERVICE_AUTO_START
: StartUp
= 0; break;
125 case SERVICE_DEMAND_START
: StartUp
= 1; break;
126 case SERVICE_DISABLED
: StartUp
= 2; break;
134 HeapFree(ProcessHeap
,
142 * Populates the General Properties dialog with
143 * the relevant service information
146 InitGeneralPage(PSERVICEPROPSHEET dlgInfo
,
149 LPQUERY_SERVICE_CONFIG pServiceConfig
;
150 LPTSTR lpDescription
;
152 /* set the service name */
153 SendDlgItemMessage(hwndDlg
,
157 (LPARAM
)dlgInfo
->pService
->lpServiceName
);
159 /* set the display name */
160 SendDlgItemMessage(hwndDlg
,
164 (LPARAM
)dlgInfo
->pService
->lpDisplayName
);
166 /* set the description */
167 if ((lpDescription
= GetServiceDescription(dlgInfo
->pService
->lpServiceName
)))
169 SendDlgItemMessage(hwndDlg
,
173 (LPARAM
)lpDescription
);
175 HeapFree(ProcessHeap
,
180 pServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
183 SendDlgItemMessage(hwndDlg
,
187 (LPARAM
)pServiceConfig
->lpBinaryPathName
);
188 HeapFree(ProcessHeap
,
194 /* set startup type */
195 SetStartupType(dlgInfo
->pService
->lpServiceName
, hwndDlg
);
197 SetServiceStatusText(dlgInfo
,
200 if (dlgInfo
->Info
->bIsUserAnAdmin
)
202 HWND hEdit
= GetDlgItem(hwndDlg
,
211 SaveDlgInfo(PSERVICEPROPSHEET dlgInfo
,
214 LPQUERY_SERVICE_CONFIG pServiceConfig
= NULL
;
218 pServiceConfig
= HeapAlloc(ProcessHeap
,
220 sizeof(*pServiceConfig
));
223 pServiceConfig
->dwServiceType
= SERVICE_NO_CHANGE
;
224 pServiceConfig
->dwErrorControl
= SERVICE_NO_CHANGE
;
226 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
227 StartUp
= SendMessage(hList
,
233 case 0: pServiceConfig
->dwStartType
= SERVICE_AUTO_START
; break;
234 case 1: pServiceConfig
->dwStartType
= SERVICE_DEMAND_START
; break;
235 case 2: pServiceConfig
->dwStartType
= SERVICE_DISABLED
; break;
238 if (SetServiceConfig(pServiceConfig
,
239 dlgInfo
->pService
->lpServiceName
,
242 ChangeListViewText(dlgInfo
->Info
,
247 HeapFree(ProcessHeap
,
256 OnStart(HWND hwndDlg
,
257 PSERVICEPROPSHEET dlgInfo
)
259 WCHAR szStartParams
[256];
260 LPWSTR lpStartParams
= NULL
;
262 if (GetDlgItemText(hwndDlg
, IDC_START_PARAM
, szStartParams
, 256) > 0)
263 lpStartParams
= szStartParams
;
265 if (DoStart(dlgInfo
->Info
, lpStartParams
))
267 UpdateServiceStatus(dlgInfo
->pService
);
268 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
269 SetButtonStates(dlgInfo
, hwndDlg
);
270 SetServiceStatusText(dlgInfo
, hwndDlg
);
276 * General Property dialog callback.
277 * Controls messages to the General dialog
280 GeneralPageProc(HWND hwndDlg
,
285 PSERVICEPROPSHEET dlgInfo
;
287 /* Get the window context */
288 dlgInfo
= (PSERVICEPROPSHEET
)GetWindowLongPtr(hwndDlg
,
290 if (dlgInfo
== NULL
&& uMsg
!= WM_INITDIALOG
)
299 dlgInfo
= (PSERVICEPROPSHEET
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
302 SetWindowLongPtr(hwndDlg
,
305 InitGeneralPage(dlgInfo
, hwndDlg
);
306 SetButtonStates(dlgInfo
, hwndDlg
);
312 switch(LOWORD(wParam
))
315 if (HIWORD(wParam
) == CBN_SELCHANGE
)
316 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
320 OnStart(hwndDlg
, dlgInfo
);
324 if (DoStop(dlgInfo
->Info
))
326 UpdateServiceStatus(dlgInfo
->pService
);
327 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
328 SetButtonStates(dlgInfo
, hwndDlg
);
329 SetServiceStatusText(dlgInfo
, hwndDlg
);
334 if (DoPause(dlgInfo
->Info
))
336 UpdateServiceStatus(dlgInfo
->pService
);
337 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
338 SetButtonStates(dlgInfo
, hwndDlg
);
339 SetServiceStatusText(dlgInfo
, hwndDlg
);
344 if (DoResume(dlgInfo
->Info
))
346 UpdateServiceStatus(dlgInfo
->pService
);
347 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
348 SetButtonStates(dlgInfo
, hwndDlg
);
349 SetServiceStatusText(dlgInfo
, hwndDlg
);
355 HWND hName
, hDesc
, hExePath
;
357 hName
= GetDlgItem(hwndDlg
, IDC_DISP_NAME
);
358 hDesc
= GetDlgItem(hwndDlg
, IDC_DESCRIPTION
);
359 hExePath
= GetDlgItem(hwndDlg
, IDC_EXEPATH
);
361 SendMessage(hName
, EM_SETREADONLY
, FALSE
, 0);
362 SendMessage(hDesc
, EM_SETREADONLY
, FALSE
, 0);
363 SendMessage(hExePath
, EM_SETREADONLY
, FALSE
, 0);
367 case IDC_START_PARAM
:
368 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
375 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
380 SaveDlgInfo(dlgInfo
, hwndDlg
);
381 SetButtonStates(dlgInfo
, hwndDlg
);