2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/servman/propsheet.c
5 * PURPOSE: Property dialog box message handler
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
13 SetButtonStates(PMAIN_WND_INFO Info
)
18 Flags
= Info
->CurrentService
->ServiceStatusProcess
.dwControlsAccepted
;
19 State
= Info
->CurrentService
->ServiceStatusProcess
.dwCurrentState
;
21 if (State
== SERVICE_STOPPED
)
23 hButton
= GetDlgItem(Info
->PropSheet
->hwndGenDlg
, IDC_START
);
24 EnableWindow (hButton
, TRUE
);
27 if ( (Flags
& SERVICE_ACCEPT_STOP
) && (State
== SERVICE_RUNNING
) )
29 hButton
= GetDlgItem(Info
->PropSheet
->hwndGenDlg
, IDC_STOP
);
30 EnableWindow (hButton
, TRUE
);
33 if ( (Flags
& SERVICE_ACCEPT_PAUSE_CONTINUE
) && (State
== SERVICE_RUNNING
) )
35 hButton
= GetDlgItem(Info
->PropSheet
->hwndGenDlg
, IDC_PAUSE
);
36 EnableWindow (hButton
, TRUE
);
39 if ( (Flags
& SERVICE_ACCEPT_STOP
) && (State
== SERVICE_RUNNING
) )
41 hButton
= GetDlgItem(Info
->PropSheet
->hwndGenDlg
, IDC_PAUSE
);
42 EnableWindow (hButton
, TRUE
);
47 * Fills the 'startup type' combo box with possible
48 * values and sets it to value of the selected item
51 SetStartupType(PMAIN_WND_INFO Info
)
56 DWORD dwValueSize
= 0;
58 LPCTSTR Path
= _T("System\\CurrentControlSet\\Services\\%s");
61 /* open the registry key for the service */
63 sizeof(KeyBuf
) / sizeof(TCHAR
),
65 Info
->CurrentService
->lpServiceName
);
67 RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
73 hList
= GetDlgItem(Info
->PropSheet
->hwndGenDlg
, IDC_START_TYPE
);
75 LoadString(hInstance
, IDS_SERVICES_AUTO
, buf
, sizeof(buf
) / sizeof(TCHAR
));
76 SendMessage(hList
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
77 LoadString(hInstance
, IDS_SERVICES_MAN
, buf
, sizeof(buf
) / sizeof(TCHAR
));
78 SendMessage(hList
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
79 LoadString(hInstance
, IDS_SERVICES_DIS
, buf
, sizeof(buf
) / sizeof(TCHAR
));
80 SendMessage(hList
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
82 dwValueSize
= sizeof(DWORD
);
83 if (RegQueryValueEx(hKey
,
95 SendMessage(hList
, CB_SETCURSEL
, 0, 0);
96 else if (StartUp
== 0x03)
97 SendMessage(hList
, CB_SETCURSEL
, 1, 0);
98 else if (StartUp
== 0x04)
99 SendMessage(hList
, CB_SETCURSEL
, 2, 0);
105 * Populates the General Properties dialog with
106 * the relevant service information
109 GetDlgInfo(PMAIN_WND_INFO Info
)
111 /* set the service name */
112 Info
->PropSheet
->lpServiceName
= Info
->CurrentService
->lpServiceName
;
113 SendDlgItemMessage(Info
->PropSheet
->hwndGenDlg
,
117 (LPARAM
)Info
->PropSheet
->lpServiceName
);
119 /* set the display name */
120 Info
->PropSheet
->lpDisplayName
= Info
->CurrentService
->lpDisplayName
;
121 SendDlgItemMessage(Info
->PropSheet
->hwndGenDlg
,
125 (LPARAM
)Info
->PropSheet
->lpDisplayName
);
127 /* set the description */
128 if (GetDescription(Info
->CurrentService
->lpServiceName
, &Info
->PropSheet
->lpDescription
))
129 SendDlgItemMessage(Info
->PropSheet
->hwndGenDlg
,
133 (LPARAM
)Info
->PropSheet
->lpDescription
);
135 /* set the executable path */
136 if (GetExecutablePath(Info
, &Info
->PropSheet
->lpPathToExe
))
137 SendDlgItemMessage(Info
->PropSheet
->hwndGenDlg
,
141 (LPARAM
)Info
->PropSheet
->lpPathToExe
);
143 /* set startup type */
144 SetStartupType(Info
);
146 /* set service status */
147 if (Info
->CurrentService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
149 LoadString(hInstance
,
150 IDS_SERVICES_STARTED
,
151 Info
->PropSheet
->szServiceStatus
,
152 sizeof(Info
->PropSheet
->szServiceStatus
) / sizeof(TCHAR
));
154 SendDlgItemMessage(Info
->PropSheet
->hwndGenDlg
,
158 (LPARAM
)Info
->PropSheet
->szServiceStatus
);
162 LoadString(hInstance
,
163 IDS_SERVICES_STOPPED
,
164 Info
->PropSheet
->szServiceStatus
,
165 sizeof(Info
->PropSheet
->szServiceStatus
) / sizeof(TCHAR
));
167 SendDlgItemMessage(Info
->PropSheet
->hwndGenDlg
,
171 (LPARAM
)Info
->PropSheet
->szServiceStatus
);
179 * General Property dialog callback.
180 * Controls messages to the General dialog
182 static INT_PTR CALLBACK
183 GeneralPageProc(HWND hwndDlg
,
190 /* Get the window context */
191 Info
= (PMAIN_WND_INFO
)GetWindowLongPtr(hwndDlg
,
194 if (Info
== NULL
&& uMsg
!= WM_INITDIALOG
)
203 Info
= (PMAIN_WND_INFO
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
206 Info
->PropSheet
->hwndGenDlg
= hwndDlg
;
208 SetWindowLongPtr(hwndDlg
,
212 SetButtonStates(Info
);
218 switch(LOWORD(wParam
))
221 /* Enable the 'Apply' button */
222 //PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
226 SendMessage(Info
->hMainWnd
, WM_COMMAND
, ID_START
, 0);
230 SendMessage(Info
->hMainWnd
, WM_COMMAND
, ID_STOP
, 0);
234 SendMessage(Info
->hMainWnd
, WM_COMMAND
, ID_PAUSE
, 0);
238 SendMessage(Info
->hMainWnd
, WM_COMMAND
, ID_RESUME
, 0);
241 case IDC_START_PARAM
:
242 /* Enable the 'Apply' button */
243 //PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
254 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
259 /* Enable the 'Apply' button */
260 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
273 * Dependancies Property dialog callback.
274 * Controls messages to the Dependancies dialog
276 static INT_PTR CALLBACK
277 DependanciesPageProc(HWND hwndDlg
,
284 /* Get the window context */
285 Info
= (PMAIN_WND_INFO
)GetWindowLongPtr(hwndDlg
,
288 if (Info
== NULL
&& uMsg
!= WM_INITDIALOG
)
297 Info
= (PMAIN_WND_INFO
)(((LPPROPSHEETPAGE
)lParam
)->lParam
);
300 Info
->PropSheet
->hwndDepDlg
= hwndDlg
;
302 SetWindowLongPtr(hwndDlg
,
310 switch(LOWORD(wParam
))
321 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
337 AddEditButton(HWND hwnd
, UINT message
, LPARAM lParam
)
344 /*hEditButton = CreateWindowEx(0,
347 WS_CHILD | WS_VISIBLE,
353 if (hEditButton == NULL)
356 hEditButton
= GetDlgItem(hwnd
, PSBTN_OK
);
357 DestroyWindow(hEditButton
);
358 //SetWindowText(hEditButton, _T("test"));
369 InitPropSheetPage(PROPSHEETPAGE
*psp
,
374 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
375 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
376 psp
->dwFlags
= PSP_DEFAULT
;
377 psp
->hInstance
= hInstance
;
378 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
379 psp
->pfnDlgProc
= DlgProc
;
380 psp
->lParam
= (LPARAM
)Info
;
385 OpenPropSheet(PMAIN_WND_INFO Info
)
388 PROPSHEETPAGE psp
[2];
390 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
391 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
392 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
| PSH_USECALLBACK
;
393 psh
.hwndParent
= Info
->hMainWnd
;
394 psh
.hInstance
= hInstance
;
395 psh
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
));
396 psh
.pszCaption
= Info
->CurrentService
->lpDisplayName
;
397 psh
.nPages
= sizeof(psp
) / sizeof(PROPSHEETPAGE
);
399 psh
.pfnCallback
= AddEditButton
;
403 InitPropSheetPage(&psp
[0], Info
, IDD_DLG_GENERAL
, GeneralPageProc
);
404 //InitPropSheetPage(&psp[1], Info, IDD_DLG_GENERAL, LogonPageProc);
405 //InitPropSheetPage(&psp[2], Info, IDD_DLG_GENERAL, RecoveryPageProc);
406 InitPropSheetPage(&psp
[1], Info
, IDD_DLG_DEPEND
, DependanciesPageProc
);
408 return (LONG
)(PropertySheet(&psh
) != -1);