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 SendDlgItemMessage(hwndDlg
,
88 * Fills the 'startup type' combo box with possible
89 * values and sets it to value of the selected item
92 SetStartupType(LPTSTR 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 LPTSTR lpDescription
;
150 /* set the service name */
151 SendDlgItemMessage(hwndDlg
,
155 (LPARAM
)dlgInfo
->pService
->lpServiceName
);
157 /* set the display name */
158 SendDlgItemMessage(hwndDlg
,
162 (LPARAM
)dlgInfo
->pService
->lpDisplayName
);
164 /* set the description */
165 if ((lpDescription
= GetServiceDescription(dlgInfo
->pService
->lpServiceName
)))
167 SendDlgItemMessage(hwndDlg
,
171 (LPARAM
)lpDescription
);
173 HeapFree(ProcessHeap
,
178 pServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
181 SendDlgItemMessage(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
,
252 OnStart(HWND hwndDlg
,
253 PSERVICEPROPSHEET dlgInfo
)
255 WCHAR szStartParams
[256];
256 LPWSTR lpStartParams
= NULL
;
258 if (GetDlgItemText(hwndDlg
, IDC_START_PARAM
, szStartParams
, 256) > 0)
259 lpStartParams
= szStartParams
;
261 if (DoStart(dlgInfo
->Info
, lpStartParams
))
263 UpdateServiceStatus(dlgInfo
->pService
);
264 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
265 SetButtonStates(dlgInfo
, hwndDlg
);
266 SetServiceStatusText(dlgInfo
, hwndDlg
);
271 * General Property dialog callback.
272 * Controls messages to the General dialog
275 GeneralPageProc(HWND hwndDlg
,
280 PSERVICEPROPSHEET dlgInfo
;
282 /* Get the window context */
283 dlgInfo
= (PSERVICEPROPSHEET
)GetWindowLongPtr(hwndDlg
,
285 if (dlgInfo
== NULL
&& uMsg
!= WM_INITDIALOG
)
294 dlgInfo
= (PSERVICEPROPSHEET
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
297 SetWindowLongPtr(hwndDlg
,
300 InitGeneralPage(dlgInfo
, hwndDlg
);
301 SetButtonStates(dlgInfo
, hwndDlg
);
307 switch(LOWORD(wParam
))
310 if (HIWORD(wParam
) == CBN_SELCHANGE
)
311 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
315 OnStart(hwndDlg
, dlgInfo
);
319 if (DoStop(dlgInfo
->Info
))
321 UpdateServiceStatus(dlgInfo
->pService
);
322 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
323 SetButtonStates(dlgInfo
, hwndDlg
);
324 SetServiceStatusText(dlgInfo
, hwndDlg
);
329 if (DoPause(dlgInfo
->Info
))
331 UpdateServiceStatus(dlgInfo
->pService
);
332 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
333 SetButtonStates(dlgInfo
, hwndDlg
);
334 SetServiceStatusText(dlgInfo
, hwndDlg
);
339 if (DoResume(dlgInfo
->Info
))
341 UpdateServiceStatus(dlgInfo
->pService
);
342 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
343 SetButtonStates(dlgInfo
, hwndDlg
);
344 SetServiceStatusText(dlgInfo
, hwndDlg
);
350 HWND hName
, hDesc
, hExePath
;
352 hName
= GetDlgItem(hwndDlg
, IDC_DISP_NAME
);
353 hDesc
= GetDlgItem(hwndDlg
, IDC_DESCRIPTION
);
354 hExePath
= GetDlgItem(hwndDlg
, IDC_EXEPATH
);
356 SendMessage(hName
, EM_SETREADONLY
, FALSE
, 0);
357 SendMessage(hDesc
, EM_SETREADONLY
, FALSE
, 0);
358 SendMessage(hExePath
, EM_SETREADONLY
, FALSE
, 0);
362 case IDC_START_PARAM
:
363 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
370 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
375 SaveDlgInfo(dlgInfo
, hwndDlg
);
376 SetButtonStates(dlgInfo
, hwndDlg
);