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
);
36 HeapFree(GetProcessHeap(), 0, lpServiceConfig
);
38 else if ( (Flags
& SERVICE_ACCEPT_STOP
) && (State
== SERVICE_RUNNING
) )
40 hButton
= GetDlgItem(hwndDlg
, IDC_STOP
);
41 EnableWindow (hButton
, TRUE
);
43 else if ( (Flags
& SERVICE_ACCEPT_PAUSE_CONTINUE
) && (State
== SERVICE_RUNNING
) )
45 hButton
= GetDlgItem(hwndDlg
, IDC_PAUSE
);
46 EnableWindow (hButton
, TRUE
);
49 hButton
= GetDlgItem(hwndDlg
, IDC_START_PARAM
);
50 EnableWindow(hButton
, (State
== SERVICE_STOPPED
));
52 /* set the main toolbar */
53 SetMenuAndButtonStates(dlgInfo
->Info
);
57 SetServiceStatusText(PSERVICEPROPSHEET dlgInfo
,
63 if (dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
65 id
= IDS_SERVICES_STARTED
;
69 id
= IDS_SERVICES_STOPPED
;
72 if (AllocAndLoadString(&lpStatus
,
76 SendDlgItemMessage(hwndDlg
,
86 * Fills the 'startup type' combo box with possible
87 * values and sets it to value of the selected item
90 SetStartupType(LPTSTR lpServiceName
,
94 LPQUERY_SERVICE_CONFIG pServiceConfig
;
99 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
101 for (i
= IDS_SERVICES_AUTO
; i
<= IDS_SERVICES_DIS
; i
++)
103 if (AllocAndLoadString(&lpBuf
,
115 pServiceConfig
= GetServiceConfig(lpServiceName
);
119 switch (pServiceConfig
->dwStartType
)
121 case SERVICE_AUTO_START
: StartUp
= 0; break;
122 case SERVICE_DEMAND_START
: StartUp
= 1; break;
123 case SERVICE_DISABLED
: StartUp
= 2; break;
131 HeapFree(ProcessHeap
,
138 * Populates the General Properties dialog with
139 * the relevant service information
142 InitGeneralPage(PSERVICEPROPSHEET dlgInfo
,
145 LPQUERY_SERVICE_CONFIG pServiceConfig
;
146 LPTSTR lpDescription
;
148 /* set the service name */
149 SendDlgItemMessage(hwndDlg
,
153 (LPARAM
)dlgInfo
->pService
->lpServiceName
);
155 /* set the display name */
156 SendDlgItemMessage(hwndDlg
,
160 (LPARAM
)dlgInfo
->pService
->lpDisplayName
);
162 /* set the description */
163 if ((lpDescription
= GetServiceDescription(dlgInfo
->pService
->lpServiceName
)))
165 SendDlgItemMessage(hwndDlg
,
169 (LPARAM
)lpDescription
);
171 HeapFree(ProcessHeap
,
176 pServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
179 SendDlgItemMessage(hwndDlg
,
183 (LPARAM
)pServiceConfig
->lpBinaryPathName
);
184 HeapFree(ProcessHeap
,
190 /* set startup type */
191 SetStartupType(dlgInfo
->pService
->lpServiceName
, hwndDlg
);
193 SetServiceStatusText(dlgInfo
,
196 if (dlgInfo
->Info
->bIsUserAnAdmin
)
198 HWND hEdit
= GetDlgItem(hwndDlg
,
206 SaveDlgInfo(PSERVICEPROPSHEET dlgInfo
,
209 LPQUERY_SERVICE_CONFIG pServiceConfig
= NULL
;
213 pServiceConfig
= HeapAlloc(ProcessHeap
,
215 sizeof(*pServiceConfig
));
218 pServiceConfig
->dwServiceType
= SERVICE_NO_CHANGE
;
219 pServiceConfig
->dwErrorControl
= SERVICE_NO_CHANGE
;
221 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
222 StartUp
= SendMessage(hList
,
228 case 0: pServiceConfig
->dwStartType
= SERVICE_AUTO_START
; break;
229 case 1: pServiceConfig
->dwStartType
= SERVICE_DEMAND_START
; break;
230 case 2: pServiceConfig
->dwStartType
= SERVICE_DISABLED
; break;
233 if (SetServiceConfig(pServiceConfig
,
234 dlgInfo
->pService
->lpServiceName
,
237 ChangeListViewText(dlgInfo
->Info
,
242 HeapFree(ProcessHeap
,
250 OnStart(HWND hwndDlg
,
251 PSERVICEPROPSHEET dlgInfo
)
253 WCHAR szStartParams
[256];
254 LPWSTR lpStartParams
= NULL
;
256 if (GetDlgItemText(hwndDlg
, IDC_START_PARAM
, szStartParams
, 256) > 0)
257 lpStartParams
= szStartParams
;
259 if (DoStart(dlgInfo
->Info
, lpStartParams
))
261 UpdateServiceStatus(dlgInfo
->pService
);
262 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
263 SetButtonStates(dlgInfo
, hwndDlg
);
264 SetServiceStatusText(dlgInfo
, hwndDlg
);
269 * General Property dialog callback.
270 * Controls messages to the General dialog
273 GeneralPageProc(HWND hwndDlg
,
278 PSERVICEPROPSHEET dlgInfo
;
280 /* Get the window context */
281 dlgInfo
= (PSERVICEPROPSHEET
)GetWindowLongPtr(hwndDlg
,
283 if (dlgInfo
== NULL
&& uMsg
!= WM_INITDIALOG
)
292 dlgInfo
= (PSERVICEPROPSHEET
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
295 SetWindowLongPtr(hwndDlg
,
298 InitGeneralPage(dlgInfo
, hwndDlg
);
299 SetButtonStates(dlgInfo
, hwndDlg
);
305 switch(LOWORD(wParam
))
308 if (HIWORD(wParam
) == CBN_SELCHANGE
)
309 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
313 OnStart(hwndDlg
, dlgInfo
);
317 if (DoStop(dlgInfo
->Info
))
319 UpdateServiceStatus(dlgInfo
->pService
);
320 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
321 SetButtonStates(dlgInfo
, hwndDlg
);
322 SetServiceStatusText(dlgInfo
, hwndDlg
);
327 if (DoPause(dlgInfo
->Info
))
329 UpdateServiceStatus(dlgInfo
->pService
);
330 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
331 SetButtonStates(dlgInfo
, hwndDlg
);
332 SetServiceStatusText(dlgInfo
, hwndDlg
);
337 if (DoResume(dlgInfo
->Info
))
339 UpdateServiceStatus(dlgInfo
->pService
);
340 ChangeListViewText(dlgInfo
->Info
, dlgInfo
->pService
, LVSTATUS
);
341 SetButtonStates(dlgInfo
, hwndDlg
);
342 SetServiceStatusText(dlgInfo
, hwndDlg
);
348 HWND hName
, hDesc
, hExePath
;
350 hName
= GetDlgItem(hwndDlg
, IDC_DISP_NAME
);
351 hDesc
= GetDlgItem(hwndDlg
, IDC_DESCRIPTION
);
352 hExePath
= GetDlgItem(hwndDlg
, IDC_EXEPATH
);
354 SendMessage(hName
, EM_SETREADONLY
, FALSE
, 0);
355 SendMessage(hDesc
, EM_SETREADONLY
, FALSE
, 0);
356 SendMessage(hExePath
, EM_SETREADONLY
, FALSE
, 0);
360 case IDC_START_PARAM
:
361 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
368 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
373 SaveDlgInfo(dlgInfo
, hwndDlg
);
374 SetButtonStates(dlgInfo
, hwndDlg
);