- remove all reliance on 'extern' data, using abstraction.

- store pointer to currently selected service in info struct so we don't have to keep calling it
- rewrite create.c making it more modular. Still has some missing features.
- lots of bugfixes and small improvements

svn path=/trunk/; revision=22184
This commit is contained in:
Ged Murphy 2006-06-02 16:47:39 +00:00
parent 01c01fafcd
commit 72af90afdf
12 changed files with 503 additions and 382 deletions

View file

@ -64,7 +64,7 @@ CAPTION "About Service Manager"
FONT 8,"Tahoma",0,0
STYLE WS_BORDER | WS_DLGFRAME | WS_SYSMENU | DS_MODALFRAME
BEGIN
LTEXT "Service Manager v0.5\nCopyright (C) 2005-2006\nby Ged Murphy (gedmurphy@gmail.com)", IDC_STATIC, 48, 7, 130, 26
LTEXT "Service Manager v0.5.1\nCopyright (C) 2005-2006\nby Ged Murphy (gedmurphy@gmail.com)", IDC_STATIC, 48, 7, 130, 26
PUSHBUTTON "Close", IDOK, 75, 162, 44, 15
ICON IDI_SM_ICON, IDC_STATIC, 10, 10, 7, 30
EDITTEXT IDC_LICENSE_EDIT, 8, 44, 174, 107, WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | ES_READONLY | ES_MULTILINE
@ -209,7 +209,7 @@ BEGIN
IDS_PROGRESS_INFO_START "ReactOS is attempting to start the following service"
IDS_PROGRESS_INFO_STOP "ReactOS is attempting to stop the following service"
IDS_CREATE_SUCCESS "Service Created Succesfully"
IDS_CREATE_REQ "* = required fields"
IDS_CREATE_REQ "Fields marked with an\nasterix are mandatory"
IDS_DELETE_STOP "You must manually stop the service before deleting!"
END

View file

@ -16,7 +16,6 @@ Control(PMAIN_WND_INFO Info,
HWND hProgBar;
SC_HANDLE hSCManager;
SC_HANDLE hSc;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
SERVICE_STATUS_PROCESS ServiceStatus;
SERVICE_STATUS Status;
LVITEM item;
@ -30,9 +29,6 @@ Control(PMAIN_WND_INFO Info,
0,
(LPARAM)&item);
/* copy pointer to selected service */
Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
/* set the progress bar range and step */
hProgBar = GetDlgItem(Info->hProgDlg,
IDC_SERVCON_PROGRESS);
@ -40,6 +36,7 @@ Control(PMAIN_WND_INFO Info,
PBM_SETRANGE,
0,
MAKELPARAM(0, PROGRESSRANGE));
SendMessage(hProgBar,
PBM_SETSTEP,
(WPARAM)1,
@ -57,7 +54,7 @@ Control(PMAIN_WND_INFO Info,
/* open handle to the service */
hSc = OpenService(hSCManager,
Service->lpServiceName,
Info->CurrentService->lpServiceName,
SC_MANAGER_ALL_ACCESS);
if (hSc == NULL)
{

View file

@ -9,22 +9,30 @@
#include "precomp.h"
extern HINSTANCE hInstance;
BOOL bHelpOpen = FALSE;
typedef struct _CREATE_DATA
{
HWND hSelf;
LPTSTR ServiceName;
LPTSTR DisplayName;
LPTSTR BinPath;
LPTSTR Description;
LPTSTR Options;
} CREATE_DATA, *PCREATE_DATA;
BOOL Create(LPTSTR ServiceName,
LPTSTR DisplayName,
LPTSTR BinPath,
LPTSTR Description,
LPTSTR Options)
static BOOL bHelpOpen = FALSE;
static BOOL
DoCreate(PCREATE_DATA Data)
{
SC_HANDLE hSCManager;
SC_HANDLE hSc;
TCHAR Buf[32];
/* open handle to the SCM */
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
hSCManager = OpenSCManager(NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL)
{
GetError();
@ -32,13 +40,13 @@ BOOL Create(LPTSTR ServiceName,
}
hSc = CreateService(hSCManager,
ServiceName,
DisplayName,
Data->ServiceName,
Data->DisplayName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
BinPath,
Data->BinPath,
NULL,
NULL,
NULL,
@ -48,25 +56,204 @@ BOOL Create(LPTSTR ServiceName,
if (hSc == NULL)
{
GetError();
CloseServiceHandle(hSCManager);
return FALSE;
}
SetDescription(ServiceName, Description);
/* Set the service description in the registry
* CreateService does not do this for us */
SetDescription(Data->ServiceName,
Data->Description);
LoadString(hInstance, IDS_CREATE_SUCCESS, Buf,
sizeof(Buf) / sizeof(TCHAR));
/* report success to user */
LoadString(hInstance,
IDS_CREATE_SUCCESS,
Buf,
sizeof(Buf) / sizeof(TCHAR));
DisplayString(Buf);
CloseServiceHandle(hSCManager);
CloseServiceHandle(hSc);
return TRUE;
}
#ifdef _MSC_VER
#pragma warning(disable : 4100)
#endif
static BOOL
GetDataFromDialog(PCREATE_DATA Data)
{
HWND hwnd;
TCHAR Buf[64];
INT iLen = 0;
/* get service name */
hwnd = GetDlgItem(Data->hSelf,
IDC_CREATE_SERVNAME);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
Data->ServiceName = HeapAlloc(ProcessHeap,
0,
(iLen+1) * sizeof(TCHAR));
if (Data->ServiceName != NULL)
{
GetWindowText(hwnd,
Data->ServiceName,
iLen+1);
}
else
return FALSE;
}
else
{
LoadString(hInstance,
IDS_CREATE_REQ,
Buf,
sizeof(Buf));
DisplayString(Buf);
SetFocus(hwnd);
return FALSE;
}
/* get display name */
iLen = 0;
hwnd = GetDlgItem(Data->hSelf,
IDC_CREATE_DISPNAME);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
Data->DisplayName = HeapAlloc(ProcessHeap,
0,
(iLen+1) * sizeof(TCHAR));
if (Data->DisplayName != NULL)
{
GetWindowText(hwnd,
Data->DisplayName,
iLen+1);
}
else
return FALSE;
}
else
{
LoadString(hInstance,
IDS_CREATE_REQ,
Buf,
sizeof(Buf));
DisplayString(Buf);
SetFocus(hwnd);
return FALSE;
}
/* get binary path */
iLen = 0;
hwnd = GetDlgItem(Data->hSelf,
IDC_CREATE_PATH);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
Data->BinPath = HeapAlloc(ProcessHeap,
0,
(iLen+1) * sizeof(TCHAR));
if (Data->BinPath != NULL)
{
GetWindowText(hwnd,
Data->BinPath,
iLen+1);
}
else
return FALSE;
}
else
{
LoadString(hInstance,
IDS_CREATE_REQ,
Buf,
sizeof(Buf));
DisplayString(Buf);
SetFocus(hwnd);
return FALSE;
}
/* get description */
iLen = 0;
hwnd = GetDlgItem(Data->hSelf,
IDC_CREATE_DESC);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
Data->Description = HeapAlloc(ProcessHeap,
0,
(iLen+1) * sizeof(TCHAR));
if (Data->Description != NULL)
{
GetWindowText(hwnd,
Data->Description,
iLen+1);
}
else
return FALSE;
}
/* get options */
iLen = 0;
hwnd = GetDlgItem(Data->hSelf,
IDC_CREATE_PATH);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
Data->Options = HeapAlloc(ProcessHeap,
0,
(iLen+1) * sizeof(TCHAR));
if (Data->Options != NULL)
{
GetWindowText(hwnd,
Data->Options,
iLen+1);
}
else
return FALSE;
}
return TRUE;
}
static VOID
FreeMemory(PCREATE_DATA Data)
{
if (Data->ServiceName != NULL)
HeapFree(ProcessHeap,
0,
Data->ServiceName);
if (Data->DisplayName != NULL)
HeapFree(ProcessHeap,
0,
Data->DisplayName);
if (Data->BinPath != NULL)
HeapFree(ProcessHeap,
0,
Data->BinPath);
if (Data->Description != NULL)
HeapFree(ProcessHeap,
0,
Data->Description);
if (Data->Options != NULL)
HeapFree(ProcessHeap,
0,
Data->Options);
HeapFree(ProcessHeap,
0,
Data);
}
BOOL CALLBACK
CreateHelpDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
CreateHelpDialogProc(HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HWND hHelp;
HICON hIcon = NULL;
@ -74,31 +261,45 @@ CreateHelpDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
switch (message)
{
case WM_INITDIALOG:
hIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);
SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
hHelp = GetDlgItem(hDlg, IDC_CREATE_HELP);
LoadString(hInstance, IDS_HELP_OPTIONS, Buf,
sizeof(Buf) / sizeof(TCHAR));
SetWindowText(hHelp, Buf);
return TRUE;
case WM_COMMAND:
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
case WM_INITDIALOG:
{
DestroyIcon(hIcon);
DestroyWindow(hDlg);
hIcon = LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
SendMessage(hDlg,
WM_SETICON,
ICON_SMALL,
(LPARAM)hIcon);
hHelp = GetDlgItem(hDlg,
IDC_CREATE_HELP);
LoadString(hInstance,
IDS_HELP_OPTIONS,
Buf,
sizeof(Buf) / sizeof(TCHAR));
SetWindowText(hHelp,
Buf);
return TRUE;
}
break;
case WM_DESTROY:
bHelpOpen = FALSE;
break;
case WM_COMMAND:
{
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
{
bHelpOpen = FALSE;
DestroyIcon(hIcon);
DestroyWindow(hDlg);
return TRUE;
}
break;
}
}
return FALSE;
@ -106,160 +307,94 @@ CreateHelpDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL CALLBACK
CreateDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
CreateDialogProc(HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HICON hIcon = NULL;
switch (message)
{
case WM_INITDIALOG:
hIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);
SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
case WM_INITDIALOG:
{
case IDOK:
{
LPTSTR ServiceName = NULL;
LPTSTR DisplayName = NULL;
LPTSTR BinPath = NULL;
LPTSTR Description = NULL;
LPTSTR Options = NULL;
HWND hwnd;
TCHAR Buf[32];
INT iLen = 0;
hIcon = LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
/* get service name */
hwnd = GetDlgItem(hDlg, IDC_CREATE_SERVNAME);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
ServiceName = HeapAlloc(GetProcessHeap(), 0, iLen+1);
if (ServiceName != NULL)
{
GetWindowText(hwnd, ServiceName, iLen+1);
}
}
else
{
LoadString(hInstance, IDS_CREATE_REQ, Buf,
sizeof(Buf) / sizeof(TCHAR));
DisplayString(Buf);
SetFocus(hwnd);
break;
}
/* get display name */
iLen = 0;
hwnd = GetDlgItem(hDlg, IDC_CREATE_DISPNAME);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
DisplayName = HeapAlloc(GetProcessHeap(), 0, iLen+1);
if (DisplayName != NULL)
GetWindowText(hwnd, DisplayName, iLen+1);
}
else
{
LoadString(hInstance, IDS_CREATE_REQ, Buf,
sizeof(Buf) / sizeof(TCHAR));
DisplayString(Buf);
SetFocus(hwnd);
break;
}
/* get binary path */
iLen = 0;
hwnd = GetDlgItem(hDlg, IDC_CREATE_PATH);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
BinPath = HeapAlloc(GetProcessHeap(), 0, iLen+1);
if (BinPath != NULL)
GetWindowText(hwnd, BinPath, iLen+1);
}
else
{
LoadString(hInstance, IDS_CREATE_REQ, Buf,
sizeof(Buf) / sizeof(TCHAR));
DisplayString(Buf);
SetFocus(hwnd);
break;
}
/* get description */
iLen = 0;
hwnd = GetDlgItem(hDlg, IDC_CREATE_DESC);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
Description = HeapAlloc(GetProcessHeap(), 0, iLen+1);
if (Description != NULL)
GetWindowText(hwnd, Description, iLen+1);
}
/* get options */
iLen = 0;
hwnd = GetDlgItem(hDlg, IDC_CREATE_PATH);
iLen = GetWindowTextLength(hwnd);
if (iLen != 0)
{
Options = HeapAlloc(GetProcessHeap(), 0, iLen+1);
if (Options != NULL)
GetWindowText(hwnd, Options, iLen+1);
}
Create(ServiceName, DisplayName, BinPath, Description, Options);
if (ServiceName != NULL)
HeapFree(GetProcessHeap(), 0, ServiceName);
if (DisplayName != NULL)
HeapFree(GetProcessHeap(), 0, DisplayName);
if (BinPath != NULL)
HeapFree(GetProcessHeap(), 0, BinPath);
if (Description != NULL)
HeapFree(GetProcessHeap(), 0, Description);
if (Options != NULL)
HeapFree(GetProcessHeap(), 0, Options);
DestroyIcon(hIcon);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
case IDCANCEL:
DestroyIcon(hIcon);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
case ID_CREATE_HELP:
{
HWND hHelp;
if (! bHelpOpen)
{
hHelp = CreateDialog(hInstance,
MAKEINTRESOURCE(IDD_DLG_HELP_OPTIONS),
hDlg,
(DLGPROC)CreateHelpDialogProc);
if(hHelp != NULL)
{
ShowWindow(hHelp, SW_SHOW);
bHelpOpen = TRUE;
}
}
}
break;
SendMessage(hDlg,
WM_SETICON,
ICON_SMALL,
(LPARAM)hIcon);
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
{
PCREATE_DATA Data;
Data = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(CREATE_DATA));
if (Data != NULL)
{
Data->hSelf = hDlg;
if (GetDataFromDialog(Data))
{
DoCreate(Data);
}
else
{
/* Something went wrong, leave the dialog
* open so they can try again */
FreeMemory(Data);
break;
}
FreeMemory(Data);
}
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
}
case IDCANCEL:
{
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
}
case ID_CREATE_HELP:
{
HWND hHelp;
if (! bHelpOpen)
{
hHelp = CreateDialog(hInstance,
MAKEINTRESOURCE(IDD_DLG_HELP_OPTIONS),
hDlg,
(DLGPROC)CreateHelpDialogProc);
if(hHelp != NULL)
{
bHelpOpen = TRUE;
}
}
}
break;
}
}
}
return FALSE;

View file

@ -15,7 +15,6 @@ DoDeleteService(PMAIN_WND_INFO Info,
{
SC_HANDLE hSCManager;
SC_HANDLE hSc;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
/* open handle to the SCM */
hSCManager = OpenSCManager(NULL,
@ -27,23 +26,23 @@ DoDeleteService(PMAIN_WND_INFO Info,
return FALSE;
}
/* copy pointer to selected service */
Service = GetSelectedService(Info);
/* get a handle to the service requested for starting */
/* get a handle to the service requested for deleting */
hSc = OpenService(hSCManager,
Service->lpServiceName,
Info->CurrentService->lpServiceName,
DELETE);
if (hSc == NULL)
{
GetError();
CloseServiceHandle(hSCManager);
return FALSE;
}
/* start the service opened */
/* delete the service opened */
if (! DeleteService(hSc))
{
GetError();
CloseServiceHandle(hSCManager);
CloseServiceHandle(hSc);
return FALSE;
}
@ -55,9 +54,6 @@ DoDeleteService(PMAIN_WND_INFO Info,
}
#ifdef _MSC_VER
#pragma warning(disable : 4100)
#endif
BOOL CALLBACK
DeleteDialogProc(HWND hDlg,
UINT message,
@ -65,76 +61,80 @@ DeleteDialogProc(HWND hDlg,
LPARAM lParam)
{
PMAIN_WND_INFO Info = NULL;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
HICON hIcon = NULL;
TCHAR Buf[1000];
LVITEM item;
switch (message)
{
case WM_INITDIALOG:
{
Info = (PMAIN_WND_INFO)lParam;
hIcon = LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
SendMessage(hDlg,
WM_SETICON,
ICON_SMALL,
(LPARAM)hIcon);
/* get pointer to selected service */
Service = GetSelectedService(Info);
SendDlgItemMessage(hDlg,
IDC_DEL_NAME,
WM_SETTEXT,
0,
(LPARAM)Service->lpDisplayName);
item.mask = LVIF_TEXT;
item.iItem = Info->SelectedItem;
item.iSubItem = 1;
item.pszText = Buf;
item.cchTextMax = sizeof(Buf);
SendMessage(Info->hListView,
LVM_GETITEM,
0,
(LPARAM)&item);
SendDlgItemMessage(hDlg,
IDC_DEL_DESC,
WM_SETTEXT,
0,
(LPARAM)Buf);
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
case WM_INITDIALOG:
{
case IDOK:
if (DoDeleteService(Info, hDlg))
(void)ListView_DeleteItem(Info->hListView,
Info->SelectedItem);
Info = (PMAIN_WND_INFO)lParam;
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
hIcon = LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
case IDCANCEL:
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
SendMessage(hDlg,
WM_SETICON,
ICON_SMALL,
(LPARAM)hIcon);
SendDlgItemMessage(hDlg,
IDC_DEL_NAME,
WM_SETTEXT,
0,
(LPARAM)Info->CurrentService->lpDisplayName);
item.mask = LVIF_TEXT;
item.iItem = Info->SelectedItem;
item.iSubItem = 1;
item.pszText = Buf;
item.cchTextMax = sizeof(Buf);
SendMessage(Info->hListView,
LVM_GETITEM,
0,
(LPARAM)&item);
SendDlgItemMessage(hDlg,
IDC_DEL_DESC,
WM_SETTEXT,
0,
(LPARAM)Buf);
SetFocus(GetDlgItem(hDlg, IDCANCEL));
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
{
if (DoDeleteService(Info, hDlg))
(void)ListView_DeleteItem(Info->hListView,
Info->SelectedItem);
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
}
case IDCANCEL:
{
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
}
}
}
}

View file

@ -13,7 +13,6 @@ static const TCHAR szMainWndClass[] = TEXT("ServManWndClass");
BOOL bSortAscending = TRUE;
extern HWND hwndGenDlg;
/* Toolbar buttons */
TBBUTTON tbb [NUM_BUTTONS] =
@ -43,19 +42,24 @@ TBBUTTON tbb [NUM_BUTTONS] =
};
VOID SetView(HWND hListView, DWORD View)
static VOID
SetListViewStyle(HWND hListView,
DWORD View)
{
DWORD Style = GetWindowLong(hListView, GWL_STYLE);
if ((Style & LVS_TYPEMASK) != View)
SetWindowLong(hListView, GWL_STYLE, (Style & ~LVS_TYPEMASK) | View);
{
SetWindowLong(hListView,
GWL_STYLE,
(Style & ~LVS_TYPEMASK) | View);
}
}
VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
{
HMENU hMainMenu;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
DWORD Flags, State;
/* get handle to menu */
@ -85,11 +89,8 @@ VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
if (Info->SelectedItem != NO_ITEM_SELECTED)
{
/* get pointer to selected service */
Service = GetSelectedService(Info);
Flags = Service->ServiceStatusProcess.dwControlsAccepted;
State = Service->ServiceStatusProcess.dwCurrentState;
Flags = Info->CurrentService->ServiceStatusProcess.dwControlsAccepted;
State = Info->CurrentService->ServiceStatusProcess.dwCurrentState;
if (State == SERVICE_STOPPED)
{
@ -135,7 +136,8 @@ VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
}
INT CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
static INT CALLBACK
CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
ENUM_SERVICE_STATUS_PROCESS *Param1;
ENUM_SERVICE_STATUS_PROCESS *Param2;
@ -464,11 +466,7 @@ MainWndCommand(PMAIN_WND_INFO Info,
case ID_DELETE:
{
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
Service = GetSelectedService(Info);
if (Service->ServiceStatusProcess.dwCurrentState != SERVICE_RUNNING)
if (Info->CurrentService->ServiceStatusProcess.dwCurrentState != SERVICE_RUNNING)
{
DialogBoxParam(hInstance,
MAKEINTRESOURCE(IDD_DLG_DELETE),
@ -547,23 +545,23 @@ MainWndCommand(PMAIN_WND_INFO Info,
break;
case ID_VIEW_LARGE:
SetView(Info->hListView,
LVS_ICON);
SetListViewStyle(Info->hListView,
LVS_ICON);
break;
case ID_VIEW_SMALL:
SetView(Info->hListView,
LVS_SMALLICON);
SetListViewStyle(Info->hListView,
LVS_SMALLICON);
break;
case ID_VIEW_LIST:
SetView(Info->hListView,
LVS_LIST);
SetListViewStyle(Info->hListView,
LVS_LIST);
break;
case ID_VIEW_DETAILS:
SetView(Info->hListView,
LVS_REPORT);
SetListViewStyle(Info->hListView,
LVS_REPORT);
break;
case ID_VIEW_CUSTOMIZE:
@ -606,6 +604,7 @@ MainWndProc(HWND hwnd,
/* Initialize the main window context */
Info->hMainWnd = hwnd;
Info->SelectedItem = NO_ITEM_SELECTED;
SetWindowLongPtr(hwnd,
GWLP_USERDATA,
@ -670,7 +669,6 @@ MainWndProc(HWND hwnd,
case LVN_ITEMCHANGED:
{
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
HMENU hMainMenu;
/* get handle to menu */
@ -680,9 +678,11 @@ MainWndProc(HWND hwnd,
if (GetMenuState(hMainMenu,
ID_PROP,
MF_BYCOMMAND) != MF_ENABLED)
{
EnableMenuItem(hMainMenu,
ID_PROP,
MF_ENABLED);
}
/* activate delete menu item, if not already */
if (GetMenuState(hMainMenu,
@ -698,20 +698,20 @@ MainWndProc(HWND hwnd,
}
/* globally set selected service */
/* set selected service */
Info->SelectedItem = pnmv->iItem;
/* get pointer to selected service */
Info->CurrentService = GetSelectedService(Info);
/* alter options for the service */
SetMenuAndButtonStates(Info);
/* get pointer to selected service */
Service = GetSelectedService(Info);
/* set current selected service in the status bar */
SendMessage(Info->hStatus,
SB_SETTEXT,
1,
(LPARAM)Service->lpDisplayName);
(LPARAM)Info->CurrentService->lpDisplayName);
/* show the properties button */
SendMessage(Info->hTool,

View file

@ -1,3 +1,12 @@
/*
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/misc.c
* PURPOSE: miscallanous functions
* COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include "precomp.h"
static INT
@ -201,7 +210,7 @@ VOID GetError(VOID)
VOID DisplayString(PTCHAR Msg)
{
MessageBox(NULL, Msg, _T("Note!"), MB_OK);
MessageBox(NULL, Msg, _T("Note!"), MB_ICONEXCLAMATION|MB_OK);
}

View file

@ -49,6 +49,7 @@ typedef struct _MAIN_WND_INFO
/* Stores the current selected service */
ENUM_SERVICE_STATUS_PROCESS *CurrentService;
/* selection number in the list view */
INT SelectedItem;
struct _PROP_DLG_INFO *PropSheet;

View file

@ -9,42 +9,36 @@
#include "precomp.h"
HWND hwndGenDlg;
static VOID
SetButtonStates(PMAIN_WND_INFO Info)
{
HWND hButton;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
DWORD Flags, State;
/* get pointer to selected service */
Service = GetSelectedService(Info);
Flags = Service->ServiceStatusProcess.dwControlsAccepted;
State = Service->ServiceStatusProcess.dwCurrentState;
Flags = Info->CurrentService->ServiceStatusProcess.dwControlsAccepted;
State = Info->CurrentService->ServiceStatusProcess.dwCurrentState;
if (State == SERVICE_STOPPED)
{
hButton = GetDlgItem(hwndGenDlg, IDC_START);
hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_START);
EnableWindow (hButton, TRUE);
}
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{
hButton = GetDlgItem(hwndGenDlg, IDC_STOP);
hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_STOP);
EnableWindow (hButton, TRUE);
}
if ( (Flags & SERVICE_ACCEPT_PAUSE_CONTINUE) && (State == SERVICE_RUNNING) )
{
hButton = GetDlgItem(hwndGenDlg, IDC_PAUSE);
hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_PAUSE);
EnableWindow (hButton, TRUE);
}
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{
hButton = GetDlgItem(hwndGenDlg, IDC_PAUSE);
hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_PAUSE);
EnableWindow (hButton, TRUE);
}
}
@ -54,7 +48,7 @@ SetButtonStates(PMAIN_WND_INFO Info)
* values and sets it to value of the selected item
*/
static VOID
SetStartupType(LPTSTR lpServiceName)
SetStartupType(PMAIN_WND_INFO Info)
{
HWND hList;
HKEY hKey;
@ -65,14 +59,18 @@ SetStartupType(LPTSTR lpServiceName)
TCHAR KeyBuf[300];
/* open the registry key for the service */
_sntprintf(KeyBuf, sizeof(KeyBuf) / sizeof(TCHAR), Path, lpServiceName);
_sntprintf(KeyBuf,
sizeof(KeyBuf) / sizeof(TCHAR),
Path,
Info->CurrentService->lpServiceName);
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
KeyBuf,
0,
KEY_READ,
&hKey);
hList = GetDlgItem(hwndGenDlg, IDC_START_TYPE);
hList = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_START_TYPE);
LoadString(hInstance, IDS_SERVICES_AUTO, buf, sizeof(buf) / sizeof(TCHAR));
SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
@ -110,30 +108,25 @@ SetStartupType(LPTSTR lpServiceName)
static VOID
GetDlgInfo(PMAIN_WND_INFO Info)
{
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
/* get pointer to selected service */
Service = GetSelectedService(Info);
/* set the service name */
Info->PropSheet->lpServiceName = Service->lpServiceName;
SendDlgItemMessage(hwndGenDlg,
Info->PropSheet->lpServiceName = Info->CurrentService->lpServiceName;
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_SERV_NAME,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpServiceName);
/* set the display name */
Info->PropSheet->lpDisplayName = Service->lpDisplayName;
SendDlgItemMessage(hwndGenDlg,
Info->PropSheet->lpDisplayName = Info->CurrentService->lpDisplayName;
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_DISP_NAME,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpDisplayName);
/* set the description */
if (GetDescription(Service->lpServiceName, &Info->PropSheet->lpDescription))
SendDlgItemMessage(hwndGenDlg,
if (GetDescription(Info->CurrentService->lpServiceName, &Info->PropSheet->lpDescription))
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_DESCRIPTION,
WM_SETTEXT,
0,
@ -141,24 +134,24 @@ GetDlgInfo(PMAIN_WND_INFO Info)
/* set the executable path */
if (GetExecutablePath(Info, &Info->PropSheet->lpPathToExe))
SendDlgItemMessage(hwndGenDlg,
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_EXEPATH,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpPathToExe);
/* set startup type */
SetStartupType(Service->lpServiceName);
SetStartupType(Info);
/* set service status */
if (Service->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
if (Info->CurrentService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
{
LoadString(hInstance,
IDS_SERVICES_STARTED,
Info->PropSheet->szServiceStatus,
sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
SendDlgItemMessage(hwndGenDlg,
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_SERV_STATUS,
WM_SETTEXT,
0,
@ -171,7 +164,7 @@ GetDlgInfo(PMAIN_WND_INFO Info)
Info->PropSheet->szServiceStatus,
sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
SendDlgItemMessage(hwndGenDlg,
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
IDC_SERV_STATUS,
WM_SETTEXT,
0,
@ -194,11 +187,7 @@ GeneralPageProc(HWND hwndDlg,
{
PMAIN_WND_INFO Info;
/* FIXME get rid of this */
hwndGenDlg = hwndDlg;
/* Get the window context */
/* FIXME: does this get called in time for WM_INITDIALOG */
Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg,
GWLP_USERDATA);
@ -214,6 +203,8 @@ GeneralPageProc(HWND hwndDlg,
Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
if (Info != NULL)
{
Info->PropSheet->hwndGenDlg = hwndDlg;
SetWindowLongPtr(hwndDlg,
GWLP_USERDATA,
(LONG_PTR)Info);
@ -293,9 +284,6 @@ DependanciesPageProc(HWND hwndDlg,
{
PMAIN_WND_INFO Info;
/* FIXME get rid of this */
hwndGenDlg = hwndDlg;
/* Get the window context */
Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg,
GWLP_USERDATA);
@ -312,6 +300,8 @@ DependanciesPageProc(HWND hwndDlg,
Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
if (Info != NULL)
{
Info->PropSheet->hwndDepDlg = hwndDlg;
SetWindowLongPtr(hwndDlg,
GWLP_USERDATA,
(LONG_PTR)Info);
@ -403,9 +393,6 @@ OpenPropSheet(PMAIN_WND_INFO Info)
{
PROPSHEETHEADER psh;
PROPSHEETPAGE psp[2];
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
Service = GetSelectedService(Info);
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
@ -413,7 +400,7 @@ OpenPropSheet(PMAIN_WND_INFO Info)
psh.hwndParent = Info->hMainWnd;
psh.hInstance = hInstance;
psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
psh.pszCaption = Service->lpDisplayName;
psh.pszCaption = Info->CurrentService->lpDisplayName;
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
psh.nStartPage = 0;
psh.pfnCallback = AddEditButton;

View file

@ -10,11 +10,9 @@
#include "precomp.h"
ENUM_SERVICE_STATUS_PROCESS*
GetSelectedService(PMAIN_WND_INFO Info)
{
ENUM_SERVICE_STATUS_PROCESS *pSelectedService = NULL;
LVITEM lvItem;
lvItem.mask = LVIF_PARAM;
@ -24,10 +22,8 @@ GetSelectedService(PMAIN_WND_INFO Info)
0,
(LPARAM)&lvItem);
/* copy pointer to selected service */
pSelectedService = (ENUM_SERVICE_STATUS_PROCESS *)lvItem.lParam;
return pSelectedService;
/* return pointer to selected service */
return (ENUM_SERVICE_STATUS_PROCESS *)lvItem.lParam;
}
@ -100,7 +96,9 @@ BOOL GetDescription(LPTSTR lpServiceName, LPTSTR *retDescription)
if (ret != ERROR_FILE_NOT_FOUND)
{
Description = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);
Description = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
dwValueSize);
if (Description == NULL)
{
RegCloseKey(hKey);
@ -114,7 +112,9 @@ BOOL GetDescription(LPTSTR lpServiceName, LPTSTR *retDescription)
(LPBYTE)Description,
&dwValueSize))
{
HeapFree(GetProcessHeap(), 0, Description);
HeapFree(ProcessHeap,
0,
Description);
RegCloseKey(hKey);
return FALSE;
}
@ -135,12 +135,8 @@ GetExecutablePath(PMAIN_WND_INFO Info,
SC_HANDLE hSCManager = NULL;
SC_HANDLE hSc = NULL;
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
DWORD BytesNeeded = 0;
/* copy pointer to selected service */
Service = GetSelectedService(Info);
/* open handle to the SCM */
hSCManager = OpenSCManager(NULL,
NULL,
@ -153,7 +149,7 @@ GetExecutablePath(PMAIN_WND_INFO Info,
/* get a handle to the service requested for starting */
hSc = OpenService(hSCManager,
Service->lpServiceName,
Info->CurrentService->lpServiceName,
SERVICE_QUERY_CONFIG);
if (hSc == NULL)
{
@ -170,7 +166,7 @@ GetExecutablePath(PMAIN_WND_INFO Info,
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
pServiceConfig = (LPQUERY_SERVICE_CONFIG)
HeapAlloc(GetProcessHeap(),
HeapAlloc(ProcessHeap,
0,
BytesNeeded);
if (pServiceConfig == NULL)

View file

@ -2,7 +2,7 @@
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/servman.c
* PURPOSE: HQ
* PURPOSE: Program HQ
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
@ -31,7 +31,9 @@ WinMain(HINSTANCE hThisInstance,
icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
InitCommonControlsEx(&icex);
if (!AllocAndLoadString(&lpAppName, hInstance, IDS_APPNAME))
if (!AllocAndLoadString(&lpAppName,
hInstance,
IDS_APPNAME))
{
return 1;
}

View file

@ -9,8 +9,6 @@
#include "precomp.h"
extern HWND hwndGenDlg;
static BOOL
DoStartService(PMAIN_WND_INFO Info)
{
@ -18,13 +16,10 @@ DoStartService(PMAIN_WND_INFO Info)
SC_HANDLE hSCManager;
SC_HANDLE hSc;
SERVICE_STATUS_PROCESS ServiceStatus;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL; /* FIXME: get rid of this */
DWORD BytesNeeded = 0;
INT ArgCount = 0;
DWORD dwStartTickCount, dwOldCheckPoint;
/* copy pointer to selected service */
Service = GetSelectedService(Info);
/* set the progress bar range and step */
hProgBar = GetDlgItem(Info->hProgDlg,
@ -51,7 +46,9 @@ DoStartService(PMAIN_WND_INFO Info)
}
/* get a handle to the service requested for starting */
hSc = OpenService(hSCManager, Service->lpServiceName, SERVICE_ALL_ACCESS);
hSc = OpenService(hSCManager,
Info->CurrentService->lpServiceName,
SERVICE_ALL_ACCESS);
if (hSc == NULL)
{
GetError();
@ -59,7 +56,9 @@ DoStartService(PMAIN_WND_INFO Info)
}
/* start the service opened */
if (! StartService(hSc, ArgCount, NULL))
if (! StartService(hSc,
ArgCount,
NULL))
{
GetError();
return FALSE;
@ -100,12 +99,11 @@ DoStartService(PMAIN_WND_INFO Info)
Sleep(ServiceStatus.dwWaitHint / 8);
/* check status again */
if (! QueryServiceStatusEx(
hSc,
SC_STATUS_PROCESS_INFO,
(LPBYTE)&ServiceStatus,
sizeof(SERVICE_STATUS_PROCESS),
&BytesNeeded))
if (! QueryServiceStatusEx(hSc,
SC_STATUS_PROCESS_INFO,
(LPBYTE)&ServiceStatus,
sizeof(SERVICE_STATUS_PROCESS),
&BytesNeeded))
{
GetError();
return FALSE;
@ -132,7 +130,10 @@ DoStartService(PMAIN_WND_INFO Info)
if (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
{
SendMessage(hProgBar, PBM_DELTAPOS, PROGRESSRANGE, 0);
SendMessage(hProgBar,
PBM_DELTAPOS,
PROGRESSRANGE,
0);
Sleep(1000);
return TRUE;
}
@ -148,7 +149,6 @@ BOOL
DoStart(PMAIN_WND_INFO Info)
{
HWND hProgDlg;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
TCHAR ProgDlgBuf[100];
/* open the progress dialog */
@ -173,15 +173,12 @@ DoStart(PMAIN_WND_INFO Info)
0,
(LPARAM)ProgDlgBuf);
/* get pointer to selected service */
Service = GetSelectedService(Info);
/* write the service name to the progress dialog */
SendDlgItemMessage(hProgDlg,
IDC_SERVCON_NAME,
WM_SETTEXT,
0,
(LPARAM)Service->lpServiceName);
(LPARAM)Info->CurrentService->lpServiceName);
}
/* start the service */
@ -204,13 +201,14 @@ DoStart(PMAIN_WND_INFO Info)
(LPARAM) &item);
/* change dialog status */
if (hwndGenDlg)
if (Info->PropSheet->hwndGenDlg)
{
LoadString(hInstance,
IDS_SERVICES_STARTED,
buf,
sizeof(buf) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg,
SendDlgItemMessageW(Info->PropSheet->hwndGenDlg,
IDC_SERV_STATUS,
WM_SETTEXT,
0,

View file

@ -1,7 +1,7 @@
/*
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/start.c
* FILE: base/system/servman/stop.c
* PURPOSE: Stops a service
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
@ -9,12 +9,9 @@
#include "precomp.h"
extern HWND hwndGenDlg;
BOOL DoStop(PMAIN_WND_INFO Info)
{
HWND hProgDlg;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
TCHAR ProgDlgBuf[100];
/* open the progress dialog */
@ -32,24 +29,22 @@ BOOL DoStop(PMAIN_WND_INFO Info)
IDS_PROGRESS_INFO_STOP,
ProgDlgBuf,
sizeof(ProgDlgBuf) / sizeof(TCHAR));
SendDlgItemMessage(hProgDlg,
IDC_SERVCON_INFO,
WM_SETTEXT,
0,
(LPARAM)ProgDlgBuf);
/* get pointer to selected service */
Service = GetSelectedService(Info);
/* write the service name to the progress dialog */
SendDlgItemMessage(hProgDlg,
IDC_SERVCON_NAME,
WM_SETTEXT,
0,
(LPARAM)Service->lpServiceName);
(LPARAM)Info->CurrentService->lpServiceName);
}
if( Control(Info, SERVICE_CONTROL_STOP) )
if ( Control(Info, SERVICE_CONTROL_STOP) )
{
LVITEM item;
TCHAR buf[25];
@ -63,13 +58,14 @@ BOOL DoStop(PMAIN_WND_INFO Info)
(LPARAM) &item);
/* change dialog status */
if (hwndGenDlg)
if (Info->PropSheet->hwndGenDlg)
{
LoadString(hInstance,
IDS_SERVICES_STOPPED,
buf,
sizeof(buf) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg,
SendDlgItemMessageW(Info->PropSheet->hwndGenDlg,
IDC_SERV_STATUS, WM_SETTEXT,
0,
(LPARAM)buf);