2006-11-08 11:47:44 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Services
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2007-08-24 18:27:12 +00:00
|
|
|
* FILE: base/applications/mscutils/servman/propsheet.c
|
2006-11-08 11:47:44 +00:00
|
|
|
* PURPOSE: Property dialog box message handler
|
2007-08-24 18:27:12 +00:00
|
|
|
* COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
|
2006-11-08 11:47:44 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
static VOID
|
2007-08-24 18:27:12 +00:00
|
|
|
SetButtonStates(PMAIN_WND_INFO Info,
|
|
|
|
HWND hwndDlg)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
HWND hButton;
|
|
|
|
DWORD Flags, State;
|
|
|
|
|
|
|
|
Flags = Info->CurrentService->ServiceStatusProcess.dwControlsAccepted;
|
|
|
|
State = Info->CurrentService->ServiceStatusProcess.dwCurrentState;
|
|
|
|
|
|
|
|
if (State == SERVICE_STOPPED)
|
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
hButton = GetDlgItem(hwndDlg, IDC_START);
|
2006-11-08 11:47:44 +00:00
|
|
|
EnableWindow (hButton, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
|
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
hButton = GetDlgItem(hwndDlg, IDC_STOP);
|
2006-11-08 11:47:44 +00:00
|
|
|
EnableWindow (hButton, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (Flags & SERVICE_ACCEPT_PAUSE_CONTINUE) && (State == SERVICE_RUNNING) )
|
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
hButton = GetDlgItem(hwndDlg, IDC_PAUSE);
|
2006-11-08 11:47:44 +00:00
|
|
|
EnableWindow (hButton, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
|
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
hButton = GetDlgItem(hwndDlg, IDC_PAUSE);
|
2006-11-08 11:47:44 +00:00
|
|
|
EnableWindow (hButton, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fills the 'startup type' combo box with possible
|
|
|
|
* values and sets it to value of the selected item
|
|
|
|
*/
|
|
|
|
static VOID
|
2007-08-24 18:27:12 +00:00
|
|
|
SetStartupType(PMAIN_WND_INFO Info,
|
|
|
|
HWND hwndDlg)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
HWND hList;
|
|
|
|
HKEY hKey;
|
|
|
|
TCHAR buf[25];
|
|
|
|
DWORD dwValueSize = 0;
|
|
|
|
DWORD StartUp = 0;
|
|
|
|
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
|
|
|
TCHAR KeyBuf[300];
|
|
|
|
|
|
|
|
/* open the registry key for the service */
|
|
|
|
_sntprintf(KeyBuf,
|
|
|
|
sizeof(KeyBuf) / sizeof(TCHAR),
|
|
|
|
Path,
|
|
|
|
Info->CurrentService->lpServiceName);
|
|
|
|
|
|
|
|
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
|
|
|
KeyBuf,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hKey);
|
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
hList = GetDlgItem(hwndDlg, IDC_START_TYPE);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
LoadString(hInstance, IDS_SERVICES_AUTO, buf, sizeof(buf) / sizeof(TCHAR));
|
|
|
|
SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
|
|
|
|
LoadString(hInstance, IDS_SERVICES_MAN, buf, sizeof(buf) / sizeof(TCHAR));
|
|
|
|
SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
|
|
|
|
LoadString(hInstance, IDS_SERVICES_DIS, buf, sizeof(buf) / sizeof(TCHAR));
|
|
|
|
SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
|
|
|
|
|
|
|
|
dwValueSize = sizeof(DWORD);
|
|
|
|
if (RegQueryValueEx(hKey,
|
|
|
|
_T("Start"),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)&StartUp,
|
|
|
|
&dwValueSize))
|
|
|
|
{
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StartUp == 0x02)
|
|
|
|
SendMessage(hList, CB_SETCURSEL, 0, 0);
|
|
|
|
else if (StartUp == 0x03)
|
|
|
|
SendMessage(hList, CB_SETCURSEL, 1, 0);
|
|
|
|
else if (StartUp == 0x04)
|
|
|
|
SendMessage(hList, CB_SETCURSEL, 2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Populates the General Properties dialog with
|
|
|
|
* the relevant service information
|
|
|
|
*/
|
|
|
|
static VOID
|
2007-08-24 18:27:12 +00:00
|
|
|
GetDlgInfo(PMAIN_WND_INFO Info,
|
|
|
|
HWND hwndDlg)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
LPTSTR lpDescription;
|
|
|
|
LPTSTR lpPathToExe;
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
/* set the service name */
|
2007-08-24 18:27:12 +00:00
|
|
|
SendDlgItemMessage(hwndDlg,
|
2006-11-08 11:47:44 +00:00
|
|
|
IDC_SERV_NAME,
|
|
|
|
WM_SETTEXT,
|
|
|
|
0,
|
2007-08-24 18:27:12 +00:00
|
|
|
(LPARAM)Info->CurrentService->lpServiceName);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* set the display name */
|
2007-08-24 18:27:12 +00:00
|
|
|
SendDlgItemMessage(hwndDlg,
|
2006-11-08 11:47:44 +00:00
|
|
|
IDC_DISP_NAME,
|
|
|
|
WM_SETTEXT,
|
|
|
|
0,
|
2007-08-24 18:27:12 +00:00
|
|
|
(LPARAM)Info->CurrentService->lpDisplayName);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* set the description */
|
2007-08-24 18:27:12 +00:00
|
|
|
if ((lpDescription = GetDescription(Info->CurrentService->lpServiceName)))
|
2007-08-23 14:57:44 +00:00
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
SendDlgItemMessage(hwndDlg,
|
2006-11-08 11:47:44 +00:00
|
|
|
IDC_DESCRIPTION,
|
|
|
|
WM_SETTEXT,
|
|
|
|
0,
|
2007-08-24 18:27:12 +00:00
|
|
|
(LPARAM)lpDescription);
|
|
|
|
|
|
|
|
HeapFree(ProcessHeap,
|
|
|
|
0,
|
|
|
|
lpDescription);
|
|
|
|
|
|
|
|
|
2007-08-23 14:57:44 +00:00
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* set the executable path */
|
2007-08-24 18:27:12 +00:00
|
|
|
if ((lpPathToExe = GetExecutablePath(Info)))
|
2007-08-23 14:57:44 +00:00
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
SendDlgItemMessage(hwndDlg,
|
2006-11-08 11:47:44 +00:00
|
|
|
IDC_EXEPATH,
|
|
|
|
WM_SETTEXT,
|
|
|
|
0,
|
2007-08-24 18:27:12 +00:00
|
|
|
(LPARAM)lpPathToExe);
|
|
|
|
|
|
|
|
HeapFree(ProcessHeap,
|
|
|
|
0,
|
|
|
|
lpPathToExe);
|
2007-08-23 14:57:44 +00:00
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* set startup type */
|
2007-08-24 18:27:12 +00:00
|
|
|
SetStartupType(Info, hwndDlg);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* set service status */
|
|
|
|
if (Info->CurrentService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
|
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
TCHAR szServiceStatus[32];
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
LoadString(hInstance,
|
|
|
|
IDS_SERVICES_STARTED,
|
2007-08-24 18:27:12 +00:00
|
|
|
szServiceStatus,
|
|
|
|
_tcslen(szServiceStatus) + 1);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
SendDlgItemMessage(hwndDlg,
|
2006-11-08 11:47:44 +00:00
|
|
|
IDC_SERV_STATUS,
|
|
|
|
WM_SETTEXT,
|
|
|
|
0,
|
2007-08-24 18:27:12 +00:00
|
|
|
(LPARAM)szServiceStatus);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
TCHAR szServiceStatus[32];
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
LoadString(hInstance,
|
|
|
|
IDS_SERVICES_STOPPED,
|
2007-08-24 18:27:12 +00:00
|
|
|
szServiceStatus,
|
|
|
|
_tcslen(szServiceStatus) + 1);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
SendDlgItemMessage(hwndDlg,
|
2006-11-08 11:47:44 +00:00
|
|
|
IDC_SERV_STATUS,
|
|
|
|
WM_SETTEXT,
|
|
|
|
0,
|
2007-08-24 18:27:12 +00:00
|
|
|
(LPARAM)szServiceStatus);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General Property dialog callback.
|
|
|
|
* Controls messages to the General dialog
|
|
|
|
*/
|
|
|
|
static INT_PTR CALLBACK
|
|
|
|
GeneralPageProc(HWND hwndDlg,
|
|
|
|
UINT uMsg,
|
2007-08-23 14:57:44 +00:00
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
PMAIN_WND_INFO Info;
|
|
|
|
|
|
|
|
/* Get the window context */
|
|
|
|
Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg,
|
|
|
|
GWLP_USERDATA);
|
|
|
|
|
|
|
|
if (Info == NULL && uMsg != WM_INITDIALOG)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
|
|
|
|
if (Info != NULL)
|
|
|
|
{
|
|
|
|
SetWindowLongPtr(hwndDlg,
|
|
|
|
GWLP_USERDATA,
|
|
|
|
(LONG_PTR)Info);
|
2007-08-24 18:27:12 +00:00
|
|
|
GetDlgInfo(Info, hwndDlg);
|
|
|
|
SetButtonStates(Info, hwndDlg);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDC_START_TYPE:
|
|
|
|
/* Enable the 'Apply' button */
|
|
|
|
//PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_START:
|
|
|
|
SendMessage(Info->hMainWnd, WM_COMMAND, ID_START, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_STOP:
|
|
|
|
SendMessage(Info->hMainWnd, WM_COMMAND, ID_STOP, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_PAUSE:
|
|
|
|
SendMessage(Info->hMainWnd, WM_COMMAND, ID_PAUSE, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_RESUME:
|
|
|
|
SendMessage(Info->hMainWnd, WM_COMMAND, ID_RESUME, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_START_PARAM:
|
|
|
|
/* Enable the 'Apply' button */
|
|
|
|
//PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
|
|
|
LPNMHDR lpnm = (LPNMHDR)lParam;
|
|
|
|
|
|
|
|
switch (lpnm->code)
|
|
|
|
{
|
|
|
|
case MCN_SELECT:
|
|
|
|
/* Enable the 'Apply' button */
|
|
|
|
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dependancies Property dialog callback.
|
|
|
|
* Controls messages to the Dependancies dialog
|
|
|
|
*/
|
|
|
|
static INT_PTR CALLBACK
|
|
|
|
DependanciesPageProc(HWND hwndDlg,
|
|
|
|
UINT uMsg,
|
2007-08-24 18:27:12 +00:00
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
PMAIN_WND_INFO Info;
|
|
|
|
|
|
|
|
/* Get the window context */
|
|
|
|
Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg,
|
|
|
|
GWLP_USERDATA);
|
|
|
|
|
|
|
|
if (Info == NULL && uMsg != WM_INITDIALOG)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
|
|
|
|
if (Info != NULL)
|
|
|
|
{
|
|
|
|
SetWindowLongPtr(hwndDlg,
|
|
|
|
GWLP_USERDATA,
|
|
|
|
(LONG_PTR)Info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
|
|
|
LPNMHDR lpnm = (LPNMHDR)lParam;
|
|
|
|
|
|
|
|
switch (lpnm->code)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static INT CALLBACK
|
|
|
|
AddEditButton(HWND hwnd, UINT message, LPARAM lParam)
|
|
|
|
{
|
|
|
|
HWND hEditButton;
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case PSCB_PRECREATE:
|
|
|
|
/*hEditButton = CreateWindowEx(0,
|
|
|
|
WC_BUTTON,
|
|
|
|
NULL,
|
|
|
|
WS_CHILD | WS_VISIBLE,
|
|
|
|
20, 300, 30, 15,
|
|
|
|
hwnd,
|
|
|
|
NULL,
|
|
|
|
hInstance,
|
|
|
|
NULL);
|
|
|
|
if (hEditButton == NULL)
|
|
|
|
GetError(0);*/
|
|
|
|
|
|
|
|
hEditButton = GetDlgItem(hwnd, PSBTN_OK);
|
|
|
|
DestroyWindow(hEditButton);
|
|
|
|
//SetWindowText(hEditButton, _T("test"));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
InitPropSheetPage(PROPSHEETPAGE *psp,
|
|
|
|
PMAIN_WND_INFO Info,
|
|
|
|
WORD idDlg,
|
|
|
|
DLGPROC DlgProc)
|
|
|
|
{
|
|
|
|
ZeroMemory(psp, sizeof(PROPSHEETPAGE));
|
|
|
|
psp->dwSize = sizeof(PROPSHEETPAGE);
|
|
|
|
psp->dwFlags = PSP_DEFAULT;
|
|
|
|
psp->hInstance = hInstance;
|
|
|
|
psp->pszTemplate = MAKEINTRESOURCE(idDlg);
|
|
|
|
psp->pfnDlgProc = DlgProc;
|
|
|
|
psp->lParam = (LPARAM)Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LONG APIENTRY
|
|
|
|
OpenPropSheet(PMAIN_WND_INFO Info)
|
|
|
|
{
|
|
|
|
PROPSHEETHEADER psh;
|
|
|
|
PROPSHEETPAGE psp[2];
|
|
|
|
|
|
|
|
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
|
|
|
|
psh.dwSize = sizeof(PROPSHEETHEADER);
|
|
|
|
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_USECALLBACK;
|
|
|
|
psh.hwndParent = Info->hMainWnd;
|
|
|
|
psh.hInstance = hInstance;
|
|
|
|
psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
|
|
|
|
psh.pszCaption = Info->CurrentService->lpDisplayName;
|
|
|
|
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
|
|
|
|
psh.nStartPage = 0;
|
|
|
|
psh.pfnCallback = AddEditButton;
|
|
|
|
psh.ppsp = psp;
|
|
|
|
|
|
|
|
|
|
|
|
InitPropSheetPage(&psp[0], Info, IDD_DLG_GENERAL, GeneralPageProc);
|
|
|
|
//InitPropSheetPage(&psp[1], Info, IDD_DLG_GENERAL, LogonPageProc);
|
|
|
|
//InitPropSheetPage(&psp[2], Info, IDD_DLG_GENERAL, RecoveryPageProc);
|
|
|
|
InitPropSheetPage(&psp[1], Info, IDD_DLG_DEPEND, DependanciesPageProc);
|
|
|
|
|
|
|
|
return (LONG)(PropertySheet(&psh) != -1);
|
|
|
|
}
|
|
|
|
|