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 typedef struct _PAGEDATA
15 PSERVICEPROPSHEET dlgInfo
;
17 } PAGEDATA
, *PPAGEDATA
;
21 SetButtonStates(PSERVICEPROPSHEET dlgInfo
,
25 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
29 Flags
= dlgInfo
->pService
->ServiceStatusProcess
.dwControlsAccepted
;
30 State
= dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
;
32 for (i
= IDC_START
; i
<= IDC_RESUME
; i
++)
34 hButton
= GetDlgItem(hwndDlg
, i
);
35 EnableWindow (hButton
, FALSE
);
38 lpServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
39 if (State
== SERVICE_STOPPED
&&
40 lpServiceConfig
&& lpServiceConfig
->dwStartType
!= SERVICE_DISABLED
)
42 hButton
= GetDlgItem(hwndDlg
, IDC_START
);
43 EnableWindow (hButton
, TRUE
);
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
);
57 HeapFree(GetProcessHeap(), 0, lpServiceConfig
);
59 hButton
= GetDlgItem(hwndDlg
, IDC_START_PARAM
);
60 EnableWindow(hButton
, (State
== SERVICE_STOPPED
));
62 /* set the main toolbar */
63 SetMenuAndButtonStates(dlgInfo
->Info
);
67 SetServiceStatusText(PSERVICEPROPSHEET dlgInfo
,
73 if (dlgInfo
->pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
75 id
= IDS_SERVICES_STARTED
;
79 id
= IDS_SERVICES_STOPPED
;
82 if (AllocAndLoadString(&lpStatus
,
86 SendDlgItemMessageW(hwndDlg
,
96 * Fills the 'startup type' combo box with possible
97 * values and sets it to value of the selected item
100 SetStartupType(LPWSTR lpServiceName
,
104 LPQUERY_SERVICE_CONFIG pServiceConfig
;
109 hList
= GetDlgItem(hwndDlg
, IDC_START_TYPE
);
111 for (i
= IDS_SERVICES_AUTO
; i
<= IDS_SERVICES_DIS
; i
++)
113 if (AllocAndLoadString(&lpBuf
,
125 pServiceConfig
= GetServiceConfig(lpServiceName
);
129 switch (pServiceConfig
->dwStartType
)
131 case SERVICE_AUTO_START
: StartUp
= 0; break;
132 case SERVICE_DEMAND_START
: StartUp
= 1; break;
133 case SERVICE_DISABLED
: StartUp
= 2; break;
141 HeapFree(ProcessHeap
,
148 * Populates the General Properties dialog with
149 * the relevant service information
152 InitGeneralPage(PSERVICEPROPSHEET dlgInfo
,
155 LPQUERY_SERVICE_CONFIG pServiceConfig
;
156 LPWSTR lpDescription
;
158 /* set the service name */
159 SendDlgItemMessageW(hwndDlg
,
163 (LPARAM
)dlgInfo
->pService
->lpServiceName
);
165 /* set the display name */
166 SendDlgItemMessageW(hwndDlg
,
170 (LPARAM
)dlgInfo
->pService
->lpDisplayName
);
172 /* set the description */
173 if ((lpDescription
= GetServiceDescription(dlgInfo
->pService
->lpServiceName
)))
175 SendDlgItemMessageW(hwndDlg
,
179 (LPARAM
)lpDescription
);
181 HeapFree(ProcessHeap
,
186 pServiceConfig
= GetServiceConfig(dlgInfo
->pService
->lpServiceName
);
189 SendDlgItemMessageW(hwndDlg
,
193 (LPARAM
)pServiceConfig
->lpBinaryPathName
);
194 HeapFree(ProcessHeap
,
200 /* set startup type */
201 SetStartupType(dlgInfo
->pService
->lpServiceName
, hwndDlg
);
203 SetServiceStatusText(dlgInfo
,
206 if (dlgInfo
->Info
->bIsUserAnAdmin
)
208 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT
), TRUE
);
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
,
256 * General Property dialog callback.
257 * Controls messages to the General dialog
260 GeneralPageProc(HWND hwndDlg
,
267 /* Get the window context */
268 pPageData
= (PPAGEDATA
)GetWindowLongPtr(hwndDlg
,
270 if (pPageData
== NULL
&& uMsg
!= WM_INITDIALOG
)
278 pPageData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(PAGEDATA
));
279 if (pPageData
!= NULL
)
281 SetWindowLongPtr(hwndDlg
,
283 (LONG_PTR
)pPageData
);
285 pPageData
->dlgInfo
= (PSERVICEPROPSHEET
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
286 if (pPageData
->dlgInfo
!= NULL
)
288 InitGeneralPage(pPageData
->dlgInfo
, hwndDlg
);
289 SetButtonStates(pPageData
->dlgInfo
, hwndDlg
);
295 HeapFree(GetProcessHeap(), 0, pPageData
);
299 switch(LOWORD(wParam
))
302 if (HIWORD(wParam
) == CBN_SELCHANGE
)
304 pPageData
->bPageChanged
= TRUE
;
305 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
311 WCHAR szStartParams
[256];
312 LPWSTR lpStartParams
= NULL
;
314 if (GetDlgItemText(hwndDlg
, IDC_START_PARAM
, szStartParams
, 256) > 0)
315 lpStartParams
= szStartParams
;
317 RunActionWithProgress(hwndDlg
,
318 pPageData
->dlgInfo
->pService
->lpServiceName
,
319 pPageData
->dlgInfo
->pService
->lpDisplayName
,
323 UpdateServiceStatus(pPageData
->dlgInfo
->pService
);
324 ChangeListViewText(pPageData
->dlgInfo
->Info
, pPageData
->dlgInfo
->pService
, LVSTATUS
);
325 SetButtonStates(pPageData
->dlgInfo
, hwndDlg
);
326 SetServiceStatusText(pPageData
->dlgInfo
, hwndDlg
);
331 RunActionWithProgress(hwndDlg
,
332 pPageData
->dlgInfo
->pService
->lpServiceName
,
333 pPageData
->dlgInfo
->pService
->lpDisplayName
,
337 UpdateServiceStatus(pPageData
->dlgInfo
->pService
);
338 ChangeListViewText(pPageData
->dlgInfo
->Info
, pPageData
->dlgInfo
->pService
, LVSTATUS
);
339 SetButtonStates(pPageData
->dlgInfo
, hwndDlg
);
340 SetServiceStatusText(pPageData
->dlgInfo
, hwndDlg
);
344 RunActionWithProgress(hwndDlg
,
345 pPageData
->dlgInfo
->pService
->lpServiceName
,
346 pPageData
->dlgInfo
->pService
->lpDisplayName
,
350 UpdateServiceStatus(pPageData
->dlgInfo
->pService
);
351 ChangeListViewText(pPageData
->dlgInfo
->Info
, pPageData
->dlgInfo
->pService
, LVSTATUS
);
352 SetButtonStates(pPageData
->dlgInfo
, hwndDlg
);
353 SetServiceStatusText(pPageData
->dlgInfo
, hwndDlg
);
357 RunActionWithProgress(hwndDlg
,
358 pPageData
->dlgInfo
->pService
->lpServiceName
,
359 pPageData
->dlgInfo
->pService
->lpDisplayName
,
363 UpdateServiceStatus(pPageData
->dlgInfo
->pService
);
364 ChangeListViewText(pPageData
->dlgInfo
->Info
, pPageData
->dlgInfo
->pService
, LVSTATUS
);
365 SetButtonStates(pPageData
->dlgInfo
, hwndDlg
);
366 SetServiceStatusText(pPageData
->dlgInfo
, hwndDlg
);
370 SendDlgItemMessage(hwndDlg
, IDC_DISP_NAME
, EM_SETREADONLY
, FALSE
, 0);
371 SendDlgItemMessage(hwndDlg
, IDC_DESCRIPTION
, EM_SETREADONLY
, FALSE
, 0);
372 SendDlgItemMessage(hwndDlg
, IDC_EXEPATH
, EM_SETREADONLY
, FALSE
, 0);
376 case IDC_DESCRIPTION
:
378 case IDC_START_PARAM
:
379 if (HIWORD(wParam
) == EN_CHANGE
)
381 pPageData
->bPageChanged
= TRUE
;
382 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
389 switch (((LPNMHDR
)lParam
)->code
)
392 if (pPageData
->bPageChanged
)
394 SaveDlgInfo(pPageData
->dlgInfo
, hwndDlg
);
395 SetButtonStates(pPageData
->dlgInfo
, hwndDlg
);
396 pPageData
->bPageChanged
= FALSE
;