- Start a complete overhaul of servman, using abstraction instead of the old messy way.

- Far to many changes to list, so I'm not even gonna even try ;)

svn path=/trunk/; revision=22148
This commit is contained in:
Ged Murphy 2006-06-01 16:42:08 +00:00
parent 130257e46c
commit 520bbfd043
19 changed files with 2066 additions and 1140 deletions

View file

@ -3,19 +3,12 @@
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/about.c
* PURPOSE: About dialog box message handler
* COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com>
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
//ShellAbout(hwnd, _T("test"), _T("test2"), MAKEINTRESOURCE(IDI_SM_ICON));
#include "precomp.h"
#include "servman.h"
extern HINSTANCE hInstance;
#ifdef _MSC_VER
#pragma warning(disable : 4100)
#endif
BOOL CALLBACK
AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
@ -27,15 +20,28 @@ AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
hIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);
SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
hIcon = LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE_EDIT);
SendMessage(hDlg,
WM_SETICON,
ICON_SMALL,
(LPARAM)hIcon);
LoadString(hInstance, IDS_LICENSE, strLicense,
sizeof(strLicense) / sizeof(TCHAR));
hLicenseEditWnd = GetDlgItem(hDlg,
IDC_LICENSE_EDIT);
SetWindowText(hLicenseEditWnd, strLicense);
LoadString(hInstance,
IDS_LICENSE,
strLicense,
sizeof(strLicense) / sizeof(TCHAR));
SetWindowText(hLicenseEditWnd,
strLicense);
return TRUE;
@ -44,7 +50,8 @@ AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
{
DestroyIcon(hIcon);
EndDialog(hDlg, LOWORD(wParam));
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
}

View file

@ -7,12 +7,11 @@
*
*/
#include "servman.h"
#include "precomp.h"
extern HWND hListView;
BOOL Control(HWND hProgDlg, DWORD Control)
BOOL
Control(PMAIN_WND_INFO Info,
DWORD Control)
{
HWND hProgBar;
SC_HANDLE hSCManager;
@ -25,38 +24,53 @@ BOOL Control(HWND hProgDlg, DWORD Control)
DWORD dwStartTickCount, dwOldCheckPoint;
item.mask = LVIF_PARAM;
item.iItem = GetSelectedItem();
SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);
item.iItem = Info->SelectedItem;
SendMessage(Info->hListView,
LVM_GETITEM,
0,
(LPARAM)&item);
/* copy pointer to selected service */
Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
/* set the progress bar range and step */
hProgBar = GetDlgItem(hProgDlg, IDC_SERVCON_PROGRESS);
SendMessage(hProgBar, PBM_SETRANGE, 0, MAKELPARAM(0, PROGRESSRANGE));
SendMessage(hProgBar, PBM_SETSTEP, (WPARAM)1, 0);
hProgBar = GetDlgItem(Info->hProgDlg,
IDC_SERVCON_PROGRESS);
SendMessage(hProgBar,
PBM_SETRANGE,
0,
MAKELPARAM(0, PROGRESSRANGE));
SendMessage(hProgBar,
PBM_SETSTEP,
(WPARAM)1,
0);
/* 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(0);
GetError();
return FALSE;
}
/* open handle to the service */
hSc = OpenService(hSCManager, Service->lpServiceName,
hSc = OpenService(hSCManager,
Service->lpServiceName,
SC_MANAGER_ALL_ACCESS);
if (hSc == NULL)
{
GetError(0);
GetError();
return FALSE;
}
/* process requested action */
if (! ControlService(hSc, Control, &Status))
if (! ControlService(hSc,
Control,
&Status))
{
GetError(0);
GetError();
CloseServiceHandle(hSc);
return FALSE;
}
@ -68,7 +82,7 @@ BOOL Control(HWND hProgDlg, DWORD Control)
sizeof(SERVICE_STATUS_PROCESS),
&BytesNeeded))
{
GetError(0);
GetError();
return FALSE;
}
@ -84,33 +98,38 @@ BOOL Control(HWND hProgDlg, DWORD Control)
dwWaitTime = ServiceStatus.dwWaitHint / 10;
if( dwWaitTime < 500 )
if (dwWaitTime < 500)
dwWaitTime = 500;
else if ( dwWaitTime > 5000 )
else if (dwWaitTime > 5000)
dwWaitTime = 5000;
/* increment the progress bar */
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
SendMessage(hProgBar,
PBM_STEPIT,
0,
0);
/* wait before checking status */
Sleep(dwWaitTime);
/* 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(0);
GetError();
return FALSE;
}
if (ServiceStatus.dwCheckPoint > dwOldCheckPoint)
{
/* The service is making progress. increment the progress bar */
SendMessage(hProgBar, PBM_STEPIT, 0, 0);
SendMessage(hProgBar,
PBM_STEPIT,
0,
0);
dwStartTickCount = GetTickCount();
dwOldCheckPoint = ServiceStatus.dwCheckPoint;
}
@ -128,7 +147,10 @@ BOOL Control(HWND hProgDlg, DWORD Control)
if (ServiceStatus.dwCurrentState == Control)
{
SendMessage(hProgBar, PBM_DELTAPOS, PROGRESSRANGE, 0);
SendMessage(hProgBar,
PBM_DELTAPOS,
PROGRESSRANGE,
0);
Sleep(1000);
return TRUE;
}

View file

@ -7,7 +7,7 @@
*
*/
#include "servman.h"
#include "precomp.h"
extern HINSTANCE hInstance;
BOOL bHelpOpen = FALSE;
@ -27,7 +27,7 @@ BOOL Create(LPTSTR ServiceName,
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL)
{
GetError(0);
GetError();
return FALSE;
}
@ -47,7 +47,7 @@ BOOL Create(LPTSTR ServiceName,
if (hSc == NULL)
{
GetError(0);
GetError();
return FALSE;
}

View file

@ -7,40 +7,43 @@
*
*/
#include "servman.h"
#include "precomp.h"
extern HINSTANCE hInstance;
extern HWND hListView;
BOOL DoDeleteService(HWND hDlg)
static BOOL
DoDeleteService(PMAIN_WND_INFO Info,
HWND hDlg)
{
SC_HANDLE hSCManager;
SC_HANDLE hSc;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
/* 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(0);
GetError();
return FALSE;
}
/* copy pointer to selected service */
Service = GetSelectedService();
Service = GetSelectedService(Info);
/* get a handle to the service requested for starting */
hSc = OpenService(hSCManager, Service->lpServiceName, DELETE);
hSc = OpenService(hSCManager,
Service->lpServiceName,
DELETE);
if (hSc == NULL)
{
GetError(0);
GetError();
return FALSE;
}
/* start the service opened */
if (! DeleteService(hSc))
{
GetError(0);
GetError();
return FALSE;
}
@ -56,8 +59,12 @@ BOOL DoDeleteService(HWND hDlg)
#pragma warning(disable : 4100)
#endif
BOOL CALLBACK
DeleteDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
DeleteDialogProc(HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
PMAIN_WND_INFO Info = NULL;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
HICON hIcon = NULL;
TCHAR Buf[1000];
@ -66,42 +73,67 @@ DeleteDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
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);
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();
Service = GetSelectedService(Info);
SendDlgItemMessage(hDlg, IDC_DEL_NAME, WM_SETTEXT, 0, (LPARAM)Service->lpDisplayName);
SendDlgItemMessage(hDlg,
IDC_DEL_NAME,
WM_SETTEXT,
0,
(LPARAM)Service->lpDisplayName);
item.mask = LVIF_TEXT;
item.iItem = GetSelectedItem();
item.iItem = Info->SelectedItem;
item.iSubItem = 1;
item.pszText = Buf;
item.cchTextMax = sizeof(Buf);
SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);
SendMessage(Info->hListView,
LVM_GETITEM,
0,
(LPARAM)&item);
SendDlgItemMessage(hDlg, IDC_DEL_DESC, WM_SETTEXT, 0,
(LPARAM)Buf);
SendDlgItemMessage(hDlg,
IDC_DEL_DESC,
WM_SETTEXT,
0,
(LPARAM)Buf);
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
if (DoDeleteService(hDlg))
(void)ListView_DeleteItem(hListView, GetSelectedItem());
if (DoDeleteService(Info, hDlg))
ListView_DeleteItem(Info->hListView,
Info->SelectedItem);
DestroyIcon(hIcon);
EndDialog(hDlg, LOWORD(wParam));
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
case IDCANCEL:
DestroyIcon(hIcon);
EndDialog(hDlg, LOWORD(wParam));
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
}
}

View file

@ -7,12 +7,13 @@
*
*/
#include "servman.h"
#include "precomp.h"
extern HWND hListView;
DWORD GetTextFromListView(TCHAR Text[500], INT row, INT col)
static DWORD
GetTextFromListView(PMAIN_WND_INFO Info,
TCHAR Text[500],
INT row,
INT col)
{
LVITEM item;
DWORD NumChars;
@ -22,19 +23,30 @@ DWORD GetTextFromListView(TCHAR Text[500], INT row, INT col)
item.iSubItem = col;
item.pszText = Text;
item.cchTextMax = 500;
NumChars = (INT)SendMessage(hListView, LVM_GETITEMTEXT, row, (LPARAM)&item);
NumChars = (INT)SendMessage(Info->hListView,
LVM_GETITEMTEXT,
row,
(LPARAM)&item);
return NumChars;
}
BOOL SaveServicesToFile(LPCTSTR pszFileName)
static BOOL
SaveServicesToFile(PMAIN_WND_INFO Info,
LPCTSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hFile = CreateFile(pszFileName,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
TCHAR LVText[500];
@ -44,29 +56,47 @@ BOOL SaveServicesToFile(LPCTSTR pszFileName)
INT NumListedServ = 0;
INT i, k;
NumListedServ = ListView_GetItemCount(hListView);
NumListedServ = ListView_GetItemCount(Info->hListView);
for (i=0; i < NumListedServ; i++)
{
for (k=0; k<5; k++)
{
dwTextLength = GetTextFromListView(LVText, i, k);
dwTextLength = GetTextFromListView(Info,
LVText,
i,
k);
if (LVText != NULL)
{
WriteFile(hFile, LVText, sizeof(TCHAR) * dwTextLength, &dwWritten, NULL);
WriteFile(hFile, &tab, sizeof(TCHAR), &dwWritten, NULL);
WriteFile(hFile,
LVText,
sizeof(TCHAR) * dwTextLength,
&dwWritten,
NULL);
WriteFile(hFile,
&tab,
sizeof(TCHAR),
&dwWritten,
NULL);
}
}
WriteFile(hFile, &newl, sizeof(TCHAR), &dwWritten, NULL);
WriteFile(hFile,
&newl,
sizeof(TCHAR),
&dwWritten,
NULL);
}
CloseHandle(hFile);
bSuccess = TRUE;
}
return bSuccess;
}
VOID ExportFile(HWND hwnd)
VOID ExportFile(PMAIN_WND_INFO Info)
{
OPENFILENAME ofn;
TCHAR szFileName[MAX_PATH] = _T("");
@ -74,7 +104,7 @@ VOID ExportFile(HWND hwnd)
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.hwndOwner = Info->hMainWnd;
ofn.lpstrFilter = _T("Text (Tab Delimited)(*.txt)\0*.txt\0Text (Comma Delimited)(*.csv)\0*.csv\0");
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
@ -83,10 +113,13 @@ VOID ExportFile(HWND hwnd)
if(GetSaveFileName(&ofn))
{
if (SaveServicesToFile(szFileName))
if (SaveServicesToFile(Info, szFileName))
return;
}
if (CommDlgExtendedError() != CDERR_GENERALCODES)
MessageBox(NULL, _T("Export to file failed"), NULL, 0);
}

View file

@ -1,41 +0,0 @@
/*
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/geterror.c
* PURPOSE: displays error messages
* COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include "servman.h"
VOID GetError(DWORD err)
{
LPVOID lpMsgBuf;
if (err == 0)
err = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox(NULL, lpMsgBuf, _T("Error!"), MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf);
}
VOID DisplayString(PTCHAR Msg)
{
MessageBox(NULL, Msg, _T("Note!"), MB_OK);
}

View file

@ -0,0 +1,940 @@
/*
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/mainwnd.c
* PURPOSE: Main window message handler
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include "precomp.h"
static const TCHAR szMainWndClass[] = TEXT("ServManWndClass");
BOOL bSortAscending = TRUE;
extern HWND hwndGenDlg;
/* Toolbar buttons */
TBBUTTON tbb [NUM_BUTTONS] =
{ /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
{TBICON_PROP, ID_PROP, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0}, /* properties */
{TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh */
{TBICON_EXPORT, ID_EXPORT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* export */
/* Note: First item for a seperator is its width in pixels */
{15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
{TBICON_CREATE, ID_CREATE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* create */
{TBICON_DELETE, ID_DELETE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* delete */
{15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
{TBICON_START, ID_START, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* start */
{TBICON_STOP, ID_STOP, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* stop */
{TBICON_PAUSE, ID_PAUSE, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* pause */
{TBICON_RESTART, ID_RESTART, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* restart */
{15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
{TBICON_HELP, ID_HELP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* help */
{TBICON_EXIT, ID_EXIT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* exit */
};
VOID SetView(HWND hListView, DWORD View)
{
DWORD Style = GetWindowLong(hListView, GWL_STYLE);
if ((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 */
hMainMenu = GetMenu(Info->hMainWnd);
/* set all to greyed */
EnableMenuItem(hMainMenu, ID_START, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_STOP, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_PAUSE, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_RESUME, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_RESTART, MF_GRAYED);
EnableMenuItem(Info->hShortcutMenu, ID_START, MF_GRAYED);
EnableMenuItem(Info->hShortcutMenu, ID_STOP, MF_GRAYED);
EnableMenuItem(Info->hShortcutMenu, ID_PAUSE, MF_GRAYED);
EnableMenuItem(Info->hShortcutMenu, ID_RESUME, MF_GRAYED);
EnableMenuItem(Info->hShortcutMenu, ID_RESTART, MF_GRAYED);
SendMessage(Info->hTool, TB_SETSTATE, ID_START,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
SendMessage(Info->hTool, TB_SETSTATE, ID_STOP,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
SendMessage(Info->hTool, TB_SETSTATE, ID_PAUSE,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
SendMessage(Info->hTool, TB_SETSTATE, ID_RESTART,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
if (Info->SelectedItem != NO_ITEM_SELECTED)
{
/* get pointer to selected service */
Service = GetSelectedService(Info);
Flags = Service->ServiceStatusProcess.dwControlsAccepted;
State = Service->ServiceStatusProcess.dwCurrentState;
if (State == SERVICE_STOPPED)
{
EnableMenuItem(hMainMenu, ID_START, MF_ENABLED);
EnableMenuItem(Info->hShortcutMenu, ID_START, MF_ENABLED);
SendMessage(Info->hTool, TB_SETSTATE, ID_START,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{
EnableMenuItem(hMainMenu, ID_STOP, MF_ENABLED);
EnableMenuItem(Info->hShortcutMenu, ID_STOP, MF_ENABLED);
SendMessage(Info->hTool, TB_SETSTATE, ID_STOP,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
if ( (Flags & SERVICE_ACCEPT_PAUSE_CONTINUE) && (State == SERVICE_RUNNING) )
{
EnableMenuItem(hMainMenu, ID_PAUSE, MF_ENABLED);
EnableMenuItem(Info->hShortcutMenu, ID_PAUSE, MF_ENABLED);
SendMessage(Info->hTool, TB_SETSTATE, ID_PAUSE,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{
EnableMenuItem(hMainMenu, ID_RESTART, MF_ENABLED);
EnableMenuItem(Info->hShortcutMenu, ID_RESTART, MF_ENABLED);
SendMessage(Info->hTool, TB_SETSTATE, ID_RESTART,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
}
else
{
EnableMenuItem(hMainMenu, ID_PROP, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_DELETE, MF_GRAYED);
EnableMenuItem(Info->hShortcutMenu, ID_DELETE, MF_GRAYED);
SendMessage(Info->hTool, TB_SETSTATE, ID_PROP,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
}
}
INT CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
ENUM_SERVICE_STATUS_PROCESS *Param1;
ENUM_SERVICE_STATUS_PROCESS *Param2;
// INT iSubItem = (LPARAM)lParamSort;
if (bSortAscending) {
Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1;
Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2;
}
else
{
Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2;
Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1;
}
return _tcsicmp(Param1->lpDisplayName, Param2->lpDisplayName);
}
/*FIXME: needs rewriting / optimising */
static VOID CALLBACK
MainWndResize(PVOID Context,
WORD cx,
WORD cy)
{
PMAIN_WND_INFO Info = (PMAIN_WND_INFO)Context;
RECT rcClient, rcTool, rcStatus;
int lvHeight, iToolHeight, iStatusHeight;
/* Size toolbar and get height */
Info->hTool = GetDlgItem(Info->hMainWnd, IDC_TOOLBAR);
SendMessage(Info->hTool, TB_AUTOSIZE, 0, 0);
GetWindowRect(Info->hTool, &rcTool);
iToolHeight = rcTool.bottom - rcTool.top;
/* Size status bar and get height */
Info->hStatus = GetDlgItem(Info->hMainWnd, IDC_STATUSBAR);
SendMessage(Info->hStatus, WM_SIZE, 0, 0);
GetWindowRect(Info->hStatus, &rcStatus);
iStatusHeight = rcStatus.bottom - rcStatus.top;
/* Calculate remaining height and size list view */
GetClientRect(Info->hMainWnd, &rcClient);
lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
Info->hListView = GetDlgItem(Info->hMainWnd, IDC_SERVLIST);
SetWindowPos(Info->hListView, NULL, 0, iToolHeight, rcClient.right, lvHeight, SWP_NOZORDER);
}
static VOID
CreateToolbar(PMAIN_WND_INFO Info)
{
TBADDBITMAP tbab;
INT iImageOffset;
INT NumButtons;
Info->hTool = CreateWindowEx(0, //WS_EX_TOOLWINDOW
TOOLBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
0, 0, 0, 0,
Info->hMainWnd,
(HMENU)IDC_TOOLBAR,
hInstance,
NULL);
if(Info->hTool == NULL)
{
MessageBox(Info->hMainWnd,
_T("Could not create tool bar."),
_T("Error"),
MB_OK | MB_ICONERROR);
}
/* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
SendMessage(Info->hTool,
TB_BUTTONSTRUCTSIZE,
sizeof(TBBUTTON),
0);
NumButtons = sizeof(tbb) / sizeof(tbb[0]);
/* Add custom images */
tbab.hInst = hInstance;
tbab.nID = IDB_BUTTONS;
iImageOffset = (INT)SendMessage(Info->hTool,
TB_ADDBITMAP,
NumButtons,
(LPARAM)&tbab);
tbb[0].iBitmap += iImageOffset; /* properties */
tbb[1].iBitmap += iImageOffset; /* refresh */
tbb[2].iBitmap += iImageOffset; /* export */
tbb[4].iBitmap += iImageOffset; /* create */
tbb[5].iBitmap += iImageOffset; /* delete */
tbb[7].iBitmap += iImageOffset; /* start */
tbb[8].iBitmap += iImageOffset; /* stop */
tbb[9].iBitmap += iImageOffset; /* pause */
tbb[10].iBitmap += iImageOffset; /* restart */
tbb[12].iBitmap += iImageOffset; /* help */
tbb[13].iBitmap += iImageOffset; /* exit */
/* Add buttons to toolbar */
SendMessage(Info->hTool,
TB_ADDBUTTONS,
NumButtons,
(LPARAM) &tbb);
/* Show toolbar */
ShowWindow(Info->hTool,
SW_SHOWNORMAL);
}
static BOOL
CreateListView(PMAIN_WND_INFO Info)
{
LVCOLUMN lvc = { 0 };
TCHAR szTemp[256];
Info->hListView = CreateWindowEx(0,
WC_LISTVIEW,
NULL,
WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER |
LBS_NOTIFY | LVS_SORTASCENDING | LBS_NOREDRAW,
0, 0, 0, 0,
Info->hMainWnd,
(HMENU) IDC_SERVLIST,
hInstance,
NULL);
if (Info->hListView == NULL)
{
MessageBox(Info->hMainWnd,
_T("Could not create List View."),
_T("Error"),
MB_OK | MB_ICONERROR);
return FALSE;
}
ListView_SetExtendedListViewStyle(Info->hListView,
LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);/*LVS_EX_GRIDLINES |*/
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
lvc.fmt = LVCFMT_LEFT;
/* Add columns to the list-view */
/* name */
lvc.iSubItem = 0;
lvc.cx = 150;
LoadString(hInstance,
IDS_FIRSTCOLUMN,
szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
ListView_InsertColumn(Info->hListView,
0,
&lvc);
/* description */
lvc.iSubItem = 1;
lvc.cx = 240;
LoadString(hInstance,
IDS_SECONDCOLUMN,
szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
ListView_InsertColumn(Info->hListView,
1,
&lvc);
/* status */
lvc.iSubItem = 2;
lvc.cx = 55;
LoadString(hInstance,
IDS_THIRDCOLUMN,
szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
ListView_InsertColumn(Info->hListView,
2,
&lvc);
/* startup type */
lvc.iSubItem = 3;
lvc.cx = 80;
LoadString(hInstance,
IDS_FOURTHCOLUMN,
szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
ListView_InsertColumn(Info->hListView,
3,
&lvc);
/* logon as */
lvc.iSubItem = 4;
lvc.cx = 100;
LoadString(hInstance,
IDS_FITHCOLUMN,
szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
ListView_InsertColumn(Info->hListView,
4,
&lvc);
return TRUE;
}
static VOID
CreateStatusBar(PMAIN_WND_INFO Info)
{
INT StatWidths[] = {110, -1}; /* widths of status bar */
Info->hStatus = CreateWindowEx(0,
STATUSCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
0, 0, 0, 0,
Info->hMainWnd,
(HMENU)IDC_STATUSBAR,
hInstance,
NULL);
if(Info->hStatus == NULL)
{
MessageBox(Info->hMainWnd,
_T("Could not create status bar."),
_T("Error!"),
MB_OK | MB_ICONERROR);
return;
}
SendMessage(Info->hStatus,
SB_SETPARTS,
sizeof(StatWidths) / sizeof(INT),
(LPARAM)StatWidths);
}
static VOID
InitMainWnd(PMAIN_WND_INFO Info)
{
CreateToolbar(Info);
if (!CreateListView(Info))
return;
CreateStatusBar(Info);
/* Create Popup Menu */
Info->hShortcutMenu = LoadMenu(hInstance,
MAKEINTRESOURCE(IDR_POPUP));
Info->hShortcutMenu = GetSubMenu(Info->hShortcutMenu,
0);
}
static VOID
MainWndCommand(PMAIN_WND_INFO Info,
WORD CmdId,
HWND hControl)
{
UNREFERENCED_PARAMETER(hControl);
switch (CmdId)
{
case ID_PROP:
{
if (Info->SelectedItem != NO_ITEM_SELECTED)
{
PPROP_DLG_INFO PropSheet;
PropSheet = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(PROP_DLG_INFO));
if (PropSheet != NULL)
{
Info->PropSheet = PropSheet;
OpenPropSheet(Info);
}
HeapFree(ProcessHeap,
0,
PropSheet);
}
}
break;
case ID_REFRESH:
{
RefreshServiceList(Info);
Info->SelectedItem = NO_ITEM_SELECTED;
/* disable menus and buttons */
SetMenuAndButtonStates(Info);
/* clear the service in the status bar */
SendMessage(Info->hStatus,
SB_SETTEXT,
1,
_T('\0'));
}
break;
case ID_EXPORT:
{
ExportFile(Info);
SetFocus(Info->hListView);
}
break;
case ID_CREATE:
{
DialogBoxParam(hInstance,
MAKEINTRESOURCE(IDD_DLG_CREATE),
Info->hMainWnd,
(DLGPROC)CreateDialogProc,
(LPARAM)Info);
SetFocus(Info->hListView);
}
break;
case ID_DELETE:
{
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
Service = GetSelectedService(Info);
if (Service->ServiceStatusProcess.dwCurrentState != SERVICE_RUNNING)
{
DialogBoxParam(hInstance,
MAKEINTRESOURCE(IDD_DLG_DELETE),
Info->hMainWnd,
(DLGPROC)DeleteDialogProc,
(LPARAM)Info);
}
else
{
TCHAR Buf[60];
LoadString(hInstance,
IDS_DELETE_STOP,
Buf,
sizeof(Buf) / sizeof(TCHAR));
DisplayString(Buf);
}
SetFocus(Info->hListView);
}
break;
case ID_START:
{
DoStart(Info);
}
break;
case ID_STOP:
{
DoStop(Info);
}
break;
case ID_PAUSE:
{
Control(Info,
SERVICE_CONTROL_PAUSE);
}
break;
case ID_RESUME:
{
Control(Info,
SERVICE_CONTROL_CONTINUE );
}
break;
case ID_RESTART:
{
/* FIXME: remove this hack */
SendMessage(Info->hMainWnd,
WM_COMMAND,
0,
ID_STOP);
SendMessage(Info->hMainWnd,
WM_COMMAND,
0,
ID_START);
}
break;
case ID_HELP:
MessageBox(NULL,
_T("Help is not yet implemented\n"),
_T("Note!"),
MB_OK | MB_ICONINFORMATION);
SetFocus(Info->hListView);
break;
case ID_EXIT:
PostMessage(Info->hMainWnd,
WM_CLOSE,
0,
0);
break;
case ID_VIEW_LARGE:
SetView(Info->hListView,
LVS_ICON);
break;
case ID_VIEW_SMALL:
SetView(Info->hListView,
LVS_SMALLICON);
break;
case ID_VIEW_LIST:
SetView(Info->hListView,
LVS_LIST);
break;
case ID_VIEW_DETAILS:
SetView(Info->hListView,
LVS_REPORT);
break;
case ID_VIEW_CUSTOMIZE:
break;
case ID_ABOUT:
DialogBox(hInstance,
MAKEINTRESOURCE(IDD_ABOUTBOX),
Info->hMainWnd,
(DLGPROC)AboutDialogProc);
SetFocus(Info->hListView);
break;
}
}
static LRESULT CALLBACK
MainWndProc(HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
PMAIN_WND_INFO Info;
LRESULT Ret = 0;
/* Get the window context */
Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd,
GWLP_USERDATA);
if (Info == NULL && msg != WM_CREATE)
{
goto HandleDefaultMessage;
}
switch(msg)
{
case WM_CREATE:
{
Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams);
/* Initialize the main window context */
Info->hMainWnd = hwnd;
SetWindowLongPtr(hwnd,
GWLP_USERDATA,
(LONG_PTR)Info);
InitMainWnd(Info);
/* Show the window */
ShowWindow(hwnd,
Info->nCmdShow);
RefreshServiceList(Info);
}
break;
case WM_SIZE:
{
MainWndResize(Info,
LOWORD(lParam),
HIWORD(lParam));
}
break;
case WM_NOTIFY:
{
LPNMHDR pnmhdr = (LPNMHDR)lParam;
switch (pnmhdr->code)
{
case NM_DBLCLK:
{
POINT pt;
RECT rect;
GetCursorPos(&pt);
GetWindowRect(Info->hListView, &rect);
if (PtInRect(&rect, pt))
{
SendMessage(hwnd,
WM_COMMAND,
//ID_PROP,
MAKEWPARAM((WORD)ID_PROP, (WORD)0),
0);
}
//OpenPropSheet(Info);
}
break;
case LVN_COLUMNCLICK:
{
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
ListView_SortItems(Info->hListView,
CompareFunc,
pnmv->iSubItem);
bSortAscending = !bSortAscending;
}
break;
case LVN_ITEMCHANGED:
{
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
HMENU hMainMenu;
/* get handle to menu */
hMainMenu = GetMenu(Info->hMainWnd);
/* activate properties menu item, if not already */
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,
ID_DELETE,
MF_BYCOMMAND) != MF_ENABLED)
{
EnableMenuItem(hMainMenu,
ID_DELETE,
MF_ENABLED);
EnableMenuItem(Info->hShortcutMenu,
ID_DELETE,
MF_ENABLED);
}
/* globally set selected service */
Info->SelectedItem = pnmv->iItem;
/* 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);
/* show the properties button */
SendMessage(Info->hTool,
TB_SETSTATE,
ID_PROP,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
break;
case TTN_GETDISPINFO:
{
LPTOOLTIPTEXT lpttt;
UINT idButton;
lpttt = (LPTOOLTIPTEXT)lParam;
/* Specify the resource identifier of the descriptive
* text for the given button. */
idButton = (UINT)lpttt->hdr.idFrom;
switch (idButton)
{
case ID_PROP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
break;
case ID_REFRESH:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
break;
case ID_EXPORT:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT);
break;
case ID_CREATE:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_CREATE);
break;
case ID_DELETE:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_DELETE);
break;
case ID_START:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_START);
break;
case ID_STOP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
break;
case ID_PAUSE:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE);
break;
case ID_RESTART:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);
break;
case ID_HELP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP);
break;
case ID_EXIT:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
break;
}
}
break;
default:
break;
}
}
break;
case WM_CONTEXTMENU:
{
POINT pt;
RECT lvRect;
INT xPos = GET_X_LPARAM(lParam);
INT yPos = GET_Y_LPARAM(lParam);
GetCursorPos(&pt);
/* display popup when cursor is in the list view */
GetWindowRect(Info->hListView, &lvRect);
if (PtInRect(&lvRect, pt))
{
TrackPopupMenuEx(Info->hShortcutMenu,
TPM_RIGHTBUTTON,
xPos,
yPos,
Info->hMainWnd,
NULL);
}
}
break;
case WM_COMMAND:
{
MainWndCommand(Info,
LOWORD(wParam),
(HWND)lParam);
goto HandleDefaultMessage;
}
case WM_CLOSE:
{
/* Free service array */
HeapFree(ProcessHeap,
0,
Info->pServiceStatus);
DestroyMenu(Info->hShortcutMenu);
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
{
//DestroyMainWnd(Info);
HeapFree(ProcessHeap,
0,
Info);
SetWindowLongPtr(hwnd,
GWLP_USERDATA,
0);
/* Break the message queue loop */
PostQuitMessage(0);
}
break;
default:
{
HandleDefaultMessage:
Ret = DefWindowProc(hwnd,
msg,
wParam,
lParam);
}
break;
}
return Ret;
}
HWND
CreateMainWindow(LPCTSTR lpCaption,
int nCmdShow)
{
PMAIN_WND_INFO Info;
HWND hMainWnd = NULL;
Info = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(MAIN_WND_INFO));
if (Info != NULL)
{
Info->nCmdShow = nCmdShow;
hMainWnd = CreateWindowEx(WS_EX_WINDOWEDGE,
szMainWndClass,
lpCaption,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
CW_USEDEFAULT,
CW_USEDEFAULT,
650,
450,
NULL,
NULL,
hInstance,
Info);
if (hMainWnd == NULL)
{
int ret;
ret = GetLastError();
GetError();
HeapFree(ProcessHeap,
0,
Info);
}
}
return hMainWnd;
}
BOOL
InitMainWindowImpl(VOID)
{
WNDCLASSEX wc = {0};
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = MainWndProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON));
wc.hCursor = LoadCursor(NULL,
IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wc.lpszClassName = szMainWndClass;
wc.hIconSm = (HICON)LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
LR_SHARED);
return RegisterClassEx(&wc) != (ATOM)0;
}
VOID
UninitMainWindowImpl(VOID)
{
UnregisterClass(szMainWndClass,
hInstance);
}

View file

@ -0,0 +1,248 @@
#include "precomp.h"
static INT
LengthOfStrResource(IN HINSTANCE hInst,
IN UINT uID)
{
HRSRC hrSrc;
HGLOBAL hRes;
LPWSTR lpName, lpStr;
if (hInst == NULL)
{
return -1;
}
/* There are always blocks of 16 strings */
lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
/* Find the string table block */
if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
(hRes = LoadResource(hInst, hrSrc)) &&
(lpStr = LockResource(hRes)))
{
UINT x;
/* Find the string we're looking for */
uID &= 0xF; /* position in the block, same as % 16 */
for (x = 0; x < uID; x++)
{
lpStr += (*lpStr) + 1;
}
/* Found the string */
return (int)(*lpStr);
}
return -1;
}
INT
AllocAndLoadString(OUT LPTSTR *lpTarget,
IN HINSTANCE hInst,
IN UINT uID)
{
INT ln;
ln = LengthOfStrResource(hInst,
uID);
if (ln++ > 0)
{
(*lpTarget) = (LPTSTR)LocalAlloc(LMEM_FIXED,
ln * sizeof(TCHAR));
if ((*lpTarget) != NULL)
{
INT Ret;
if (!(Ret = LoadString(hInst, uID, *lpTarget, ln)))
{
LocalFree((HLOCAL)(*lpTarget));
}
return Ret;
}
}
return 0;
}
DWORD
LoadAndFormatString(IN HINSTANCE hInstance,
IN UINT uID,
OUT LPTSTR *lpTarget,
...)
{
DWORD Ret = 0;
LPTSTR lpFormat;
va_list lArgs;
if (AllocAndLoadString(&lpFormat,
hInstance,
uID) > 0)
{
va_start(lArgs, lpTarget);
/* let's use FormatMessage to format it because it has the ability to allocate
memory automatically */
Ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
lpFormat,
0,
0,
(LPTSTR)lpTarget,
0,
&lArgs);
va_end(lArgs);
LocalFree((HLOCAL)lpFormat);
}
return Ret;
}
BOOL
StatusBarLoadAndFormatString(IN HWND hStatusBar,
IN INT PartId,
IN HINSTANCE hInstance,
IN UINT uID,
...)
{
BOOL Ret = FALSE;
LPTSTR lpFormat, lpStr;
va_list lArgs;
if (AllocAndLoadString(&lpFormat,
hInstance,
uID) > 0)
{
va_start(lArgs, uID);
/* let's use FormatMessage to format it because it has the ability to allocate
memory automatically */
Ret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
lpFormat,
0,
0,
(LPTSTR)&lpStr,
0,
&lArgs);
va_end(lArgs);
if (lpStr != NULL)
{
Ret = (BOOL)SendMessage(hStatusBar,
SB_SETTEXT,
(WPARAM)PartId,
(LPARAM)lpStr);
LocalFree((HLOCAL)lpStr);
}
LocalFree((HLOCAL)lpFormat);
}
return Ret;
}
BOOL
StatusBarLoadString(IN HWND hStatusBar,
IN INT PartId,
IN HINSTANCE hInstance,
IN UINT uID)
{
BOOL Ret = FALSE;
LPTSTR lpStr;
if (AllocAndLoadString(&lpStr,
hInstance,
uID) > 0)
{
Ret = (BOOL)SendMessage(hStatusBar,
SB_SETTEXT,
(WPARAM)PartId,
(LPARAM)lpStr);
LocalFree((HLOCAL)lpStr);
}
return Ret;
}
INT
GetTextFromEdit(OUT LPTSTR lpString,
IN HWND hDlg,
IN UINT Res)
{
INT len = GetWindowTextLength(GetDlgItem(hDlg, Res));
if(len > 0)
{
GetDlgItemText(hDlg,
Res,
lpString,
len + 1);
}
else
lpString = NULL;
return len;
}
VOID GetError(VOID)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox(NULL, lpMsgBuf, _T("Error!"), MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf);
}
VOID DisplayString(PTCHAR Msg)
{
MessageBox(NULL, Msg, _T("Note!"), MB_OK);
}
HIMAGELIST
InitImageList(UINT NumImages,
UINT StartResource,
UINT Width,
UINT Height)
{
HBITMAP hBitmap;
HIMAGELIST hImageList;
INT i, k, Ret;
/* Create the toolbar icon image list */
hImageList = ImageList_Create(Width,
Height,
ILC_MASK | ILC_COLOR24,
NumImages,
0);
if (! hImageList)
return NULL;
/* Add all icons to the image list */
for (i = StartResource, k = 0; k < NumImages; i++, k++)
{
hBitmap = LoadImage(hInstance,
MAKEINTRESOURCE(i),
IMAGE_BITMAP,
Width,
Height,
LR_LOADTRANSPARENT);
Ret = ImageList_AddMasked(hImageList,
hBitmap,
RGB(255, 255, 254));
DeleteObject(hBitmap);
}
return hImageList;
}

View file

@ -0,0 +1,132 @@
#ifndef __SERVMAN_PRECOMP_H
#define __SERVMAN_PRECOMP_H
//#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h> /* GET_X/Y_LPARAM */
#include <stdio.h>
#include <tchar.h>
#include <commctrl.h>
#include "resource.h"
#ifdef _MSC_VER
#pragma warning(disable : 4100)
#endif
#define NO_ITEM_SELECTED -1
#define MAX_KEY_LENGTH 256
#define NUM_BUTTONS 14
#define PROGRESSRANGE 8
typedef struct _PROP_DLG_INFO
{
HWND hwndGenDlg;
HWND hwndDepDlg;
LPTSTR lpServiceName;
LPTSTR lpDisplayName;
LPTSTR lpDescription;
LPTSTR lpPathToExe;
TCHAR szStartupType;
TCHAR szServiceStatus[25];
LPTSTR lpStartParams;
} PROP_DLG_INFO, *PPROP_DLG_INFO;
typedef struct _MAIN_WND_INFO
{
HWND hMainWnd;
HWND hListView;
HWND hStatus;
HWND hTool;
HWND hProgDlg;
HMENU hShortcutMenu;
int nCmdShow;
/* Stores the complete services array */
ENUM_SERVICE_STATUS_PROCESS *pServiceStatus;
/* Stores the current selected service */
ENUM_SERVICE_STATUS_PROCESS *CurrentService;
INT SelectedItem;
struct _PROP_DLG_INFO *PropSheet;
} MAIN_WND_INFO, *PMAIN_WND_INFO;
BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK CreateDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK DeleteDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ProgressDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam);
/* servman.c */
extern HINSTANCE hInstance;
extern HANDLE ProcessHeap;
/* mainwnd.c */
BOOL InitMainWindowImpl(VOID);
VOID UninitMainWindowImpl(VOID);
HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow);
/* start */
BOOL DoStart(PMAIN_WND_INFO Info);
/* stop */
BOOL DoStop(PMAIN_WND_INFO Info);
/* control */
BOOL Control(PMAIN_WND_INFO Info, DWORD Control);
/* query.c */
ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info);
BOOL SetDescription(LPTSTR, LPTSTR);
BOOL GetDescription(LPTSTR, LPTSTR *);
BOOL GetExecutablePath(PMAIN_WND_INFO Info, LPTSTR *);
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
DWORD GetServiceList(PMAIN_WND_INFO Info);
/* propsheet.c */
LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info);
/* export.c */
VOID ExportFile(PMAIN_WND_INFO Info);
/* misc.c */
INT AllocAndLoadString(OUT LPTSTR *lpTarget,
IN HINSTANCE hInst,
IN UINT uID);
DWORD LoadAndFormatString(IN HINSTANCE hInstance,
IN UINT uID,
OUT LPTSTR *lpTarget,
...);
BOOL StatusBarLoadAndFormatString(IN HWND hStatusBar,
IN INT PartId,
IN HINSTANCE hInstance,
IN UINT uID,
...);
BOOL StatusBarLoadString(IN HWND hStatusBar,
IN INT PartId,
IN HINSTANCE hInstance,
IN UINT uID);
INT GetTextFromEdit(OUT LPTSTR lpString,
IN HWND hDlg,
IN UINT Res);
VOID GetError(VOID);
VOID DisplayString(PTCHAR);
HIMAGELIST InitImageList(UINT NumButtons,
UINT StartResource,
UINT Width,
UINT Height);
#endif /* __SERVMAN_PRECOMP_H */

View file

@ -7,11 +7,7 @@
*
*/
#include "servman.h"
extern HINSTANCE hInstance;
//extern HWND hMainWnd;
#include "precomp.h"
BOOL CALLBACK ProgressDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{

View file

@ -7,36 +7,19 @@
*
*/
#include "servman.h"
#include "precomp.h"
HWND hwndGenDlg;
extern ENUM_SERVICE_STATUS_PROCESS *pServiceStatus;
extern HINSTANCE hInstance;
extern HWND hListView;
extern HWND hMainWnd;
typedef struct _PROP_DLG_INFO
{
LPTSTR lpServiceName;
LPTSTR lpDisplayName;
LPTSTR lpDescription;
LPTSTR lpPathToExe;
TCHAR szStartupType;
TCHAR szServiceStatus[25];
LPTSTR lpStartParams;
} PROP_DLG_INFO, *PPROP_DLG_INFO;
VOID SetButtonStates()
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();
Service = GetSelectedService(Info);
Flags = Service->ServiceStatusProcess.dwControlsAccepted;
State = Service->ServiceStatusProcess.dwCurrentState;
@ -70,7 +53,8 @@ VOID SetButtonStates()
* Fills the 'startup type' combo box with possible
* values and sets it to value of the selected item
*/
VOID SetStartupType(LPTSTR lpServiceName)
static VOID
SetStartupType(LPTSTR lpServiceName)
{
HWND hList;
HKEY hKey;
@ -123,82 +107,120 @@ VOID SetStartupType(LPTSTR lpServiceName)
* Populates the General Properties dialog with
* the relevant service information
*/
VOID GetDlgInfo()
static VOID
GetDlgInfo(PMAIN_WND_INFO Info)
{
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
PROP_DLG_INFO DlgInfo;
/* get pointer to selected service */
Service = GetSelectedService();
Service = GetSelectedService(Info);
/* set the service name */
DlgInfo.lpServiceName = Service->lpServiceName;
SendDlgItemMessage(hwndGenDlg, IDC_SERV_NAME, WM_SETTEXT, 0, (
LPARAM)DlgInfo.lpServiceName);
Info->PropSheet->lpServiceName = Service->lpServiceName;
SendDlgItemMessage(hwndGenDlg,
IDC_SERV_NAME,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpServiceName);
/* set the display name */
DlgInfo.lpDisplayName = Service->lpDisplayName;
SendDlgItemMessage(hwndGenDlg, IDC_DISP_NAME, WM_SETTEXT, 0,
(LPARAM)DlgInfo.lpDisplayName);
Info->PropSheet->lpDisplayName = Service->lpDisplayName;
SendDlgItemMessage(hwndGenDlg,
IDC_DISP_NAME,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpDisplayName);
/* set the description */
if (GetDescription(Service->lpServiceName, &DlgInfo.lpDescription))
SendDlgItemMessage(hwndGenDlg, IDC_DESCRIPTION, WM_SETTEXT, 0,
(LPARAM)DlgInfo.lpDescription);
if (GetDescription(Service->lpServiceName, &Info->PropSheet->lpDescription))
SendDlgItemMessage(hwndGenDlg,
IDC_DESCRIPTION,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpDescription);
/* set the executable path */
if (GetExecutablePath(&DlgInfo.lpPathToExe))
SendDlgItemMessage(hwndGenDlg, IDC_EXEPATH, WM_SETTEXT, 0, (LPARAM)DlgInfo.lpPathToExe);
if (GetExecutablePath(Info, &Info->PropSheet->lpPathToExe))
SendDlgItemMessage(hwndGenDlg,
IDC_EXEPATH,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->lpPathToExe);
/* set startup type */
SetStartupType(Service->lpServiceName);
/* set service status */
if (Service->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
{
LoadString(hInstance, IDS_SERVICES_STARTED, DlgInfo.szServiceStatus,
sizeof(DlgInfo.szServiceStatus) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT, 0, (LPARAM)DlgInfo.szServiceStatus);
LoadString(hInstance,
IDS_SERVICES_STARTED,
Info->PropSheet->szServiceStatus,
sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
SendDlgItemMessage(hwndGenDlg,
IDC_SERV_STATUS,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->szServiceStatus);
}
else
{
LoadString(hInstance, IDS_SERVICES_STOPPED, DlgInfo.szServiceStatus,
sizeof(DlgInfo.szServiceStatus) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT, 0, (LPARAM)DlgInfo.szServiceStatus);
LoadString(hInstance,
IDS_SERVICES_STOPPED,
Info->PropSheet->szServiceStatus,
sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
SendDlgItemMessage(hwndGenDlg,
IDC_SERV_STATUS,
WM_SETTEXT,
0,
(LPARAM)Info->PropSheet->szServiceStatus);
}
}
#ifdef _MSC_VER
#pragma warning(disable : 4100)
#endif
/*
* General Property dialog callback.
* Controls messages to the General dialog
*/
INT_PTR CALLBACK
static INT_PTR CALLBACK
GeneralPageProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
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);
if (Info == NULL && uMsg != WM_INITDIALOG)
{
return FALSE;
}
switch (uMsg)
{
case WM_INITDIALOG:
GetDlgInfo();
SetButtonStates();
{
Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
if (Info != NULL)
{
SetWindowLongPtr(hwndDlg,
GWLP_USERDATA,
(LONG_PTR)Info);
GetDlgInfo(Info);
SetButtonStates(Info);
}
}
break;
case WM_COMMAND:
@ -210,19 +232,19 @@ GeneralPageProc(HWND hwndDlg,
break;
case IDC_START:
SendMessage(hMainWnd, WM_COMMAND, ID_START, 0);
SendMessage(Info->hMainWnd, WM_COMMAND, ID_START, 0);
break;
case IDC_STOP:
SendMessage(hMainWnd, WM_COMMAND, ID_STOP, 0);
SendMessage(Info->hMainWnd, WM_COMMAND, ID_STOP, 0);
break;
case IDC_PAUSE:
SendMessage(hMainWnd, WM_COMMAND, ID_PAUSE, 0);
SendMessage(Info->hMainWnd, WM_COMMAND, ID_PAUSE, 0);
break;
case IDC_RESUME:
SendMessage(hMainWnd, WM_COMMAND, ID_RESUME, 0);
SendMessage(Info->hMainWnd, WM_COMMAND, ID_RESUME, 0);
break;
case IDC_START_PARAM:
@ -263,18 +285,39 @@ GeneralPageProc(HWND hwndDlg,
* Dependancies Property dialog callback.
* Controls messages to the Dependancies dialog
*/
INT_PTR CALLBACK
static INT_PTR CALLBACK
DependanciesPageProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
PMAIN_WND_INFO Info;
/* FIXME get rid of this */
hwndGenDlg = hwndDlg;
/* 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:
break;
{
Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
if (Info != NULL)
{
SetWindowLongPtr(hwndDlg,
GWLP_USERDATA,
(LONG_PTR)Info);
}
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
@ -307,7 +350,8 @@ DependanciesPageProc(HWND hwndDlg,
}
INT CALLBACK AddEditButton(HWND hwnd, UINT message, LPARAM lParam)
static INT CALLBACK
AddEditButton(HWND hwnd, UINT message, LPARAM lParam)
{
HWND hEditButton;
@ -339,7 +383,10 @@ INT CALLBACK AddEditButton(HWND hwnd, UINT message, LPARAM lParam)
static VOID
InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
InitPropSheetPage(PROPSHEETPAGE *psp,
PMAIN_WND_INFO Info,
WORD idDlg,
DLGPROC DlgProc)
{
ZeroMemory(psp, sizeof(PROPSHEETPAGE));
psp->dwSize = sizeof(PROPSHEETPAGE);
@ -347,22 +394,23 @@ InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
psp->hInstance = hInstance;
psp->pszTemplate = MAKEINTRESOURCE(idDlg);
psp->pfnDlgProc = DlgProc;
psp->lParam = (LPARAM)Info;
}
LONG APIENTRY
OpenPropSheet(HWND hwnd)
OpenPropSheet(PMAIN_WND_INFO Info)
{
PROPSHEETHEADER psh;
PROPSHEETPAGE psp[2];
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
Service = GetSelectedService();
Service = GetSelectedService(Info);
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_USECALLBACK;
psh.hwndParent = hwnd;
psh.hwndParent = Info->hMainWnd;
psh.hInstance = hInstance;
psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
psh.pszCaption = Service->lpDisplayName;
@ -372,10 +420,10 @@ OpenPropSheet(HWND hwnd)
psh.ppsp = psp;
InitPropSheetPage(&psp[0], IDD_DLG_GENERAL, GeneralPageProc);
//InitPropSheetPage(&psp[1], IDD_DLG_GENERAL, LogonPageProc);
//InitPropSheetPage(&psp[2], IDD_DLG_GENERAL, RecoveryPageProc);
InitPropSheetPage(&psp[1], IDD_DLG_DEPEND, DependanciesPageProc);
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);
}

View file

@ -7,36 +7,25 @@
*
*/
#include "servman.h"
extern HINSTANCE hInstance;
extern HWND hListView;
extern HWND hStatus;
/* Stores the complete services array */
ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;
/* Free service array */
VOID FreeMemory(VOID)
{
HeapFree(GetProcessHeap(), 0, pServiceStatus);
}
#include "precomp.h"
ENUM_SERVICE_STATUS_PROCESS*
GetSelectedService(VOID)
GetSelectedService(PMAIN_WND_INFO Info)
{
ENUM_SERVICE_STATUS_PROCESS *pSelectedService = NULL;
LVITEM item;
LVITEM lvItem;
item.mask = LVIF_PARAM;
item.iItem = GetSelectedItem();
SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);
lvItem.mask = LVIF_PARAM;
lvItem.iItem = Info->SelectedItem;
SendMessage(Info->hListView,
LVM_GETITEM,
0,
(LPARAM)&lvItem);
/* copy pointer to selected service */
pSelectedService = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
pSelectedService = (ENUM_SERVICE_STATUS_PROCESS *)lvItem.lParam;
return pSelectedService;
}
@ -68,7 +57,7 @@ BOOL SetDescription(LPTSTR ServiceName, LPTSTR Description)
(LPBYTE)Description,
(DWORD)lstrlen(szBuf)+1)) != ERROR_SUCCESS)
{
GetError(val);
//GetError(val);
return FALSE;
}
@ -139,7 +128,9 @@ BOOL GetDescription(LPTSTR lpServiceName, LPTSTR *retDescription)
/* get vendor of service binary */
BOOL GetExecutablePath(LPTSTR *ExePath)
BOOL
GetExecutablePath(PMAIN_WND_INFO Info,
LPTSTR *ExePath)
{
SC_HANDLE hSCManager = NULL;
SC_HANDLE hSc = NULL;
@ -148,31 +139,40 @@ BOOL GetExecutablePath(LPTSTR *ExePath)
DWORD BytesNeeded = 0;
/* copy pointer to selected service */
Service = GetSelectedService();
Service = GetSelectedService(Info);
/* open handle to the SCM */
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
hSCManager = OpenSCManager(NULL,
NULL,
SC_MANAGER_ENUMERATE_SERVICE);
if (hSCManager == NULL)
{
GetError(0);
GetError();
return FALSE;
}
/* get a handle to the service requested for starting */
hSc = OpenService(hSCManager, Service->lpServiceName, SERVICE_QUERY_CONFIG);
hSc = OpenService(hSCManager,
Service->lpServiceName,
SERVICE_QUERY_CONFIG);
if (hSc == NULL)
{
GetError(0);
GetError();
goto cleanup;
}
if (!QueryServiceConfig(hSc, pServiceConfig, 0, &BytesNeeded))
if (!QueryServiceConfig(hSc,
pServiceConfig,
0,
&BytesNeeded))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
pServiceConfig = (LPQUERY_SERVICE_CONFIG)
HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
HeapAlloc(GetProcessHeap(),
0,
BytesNeeded);
if (pServiceConfig == NULL)
goto cleanup;
@ -181,7 +181,9 @@ BOOL GetExecutablePath(LPTSTR *ExePath)
BytesNeeded,
&BytesNeeded))
{
HeapFree(GetProcessHeap(), 0, pServiceConfig);
HeapFree(ProcessHeap,
0,
pServiceConfig);
goto cleanup;
}
}
@ -207,7 +209,8 @@ cleanup:
}
VOID InitListViewImage(VOID)
static VOID
InitListViewImage(PMAIN_WND_INFO Info)
{
HICON hSmIconItem, hLgIconItem; /* icon for list-view items */
HIMAGELIST hSmall, hLarge; /* image list for other views */
@ -215,43 +218,65 @@ VOID InitListViewImage(VOID)
/* Create the icon image lists */
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR32, 1, 1);
GetSystemMetrics(SM_CYSMICON),
ILC_MASK | ILC_COLOR32,
1,
1);
hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
GetSystemMetrics(SM_CYICON), ILC_MASK | ILC_COLOR32, 1, 1);
GetSystemMetrics(SM_CYICON),
ILC_MASK | ILC_COLOR32,
1,
1);
/* Add an icon to each image list */
hSmIconItem = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON, 16, 16, 0);
ImageList_AddIcon(hSmall, hSmIconItem);
hSmIconItem = LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
hLgIconItem = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON, 32, 32, 0);
ImageList_AddIcon(hLarge, hLgIconItem);
ImageList_AddIcon(hSmall,
hSmIconItem);
hLgIconItem = LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
32,
32,
0);
ImageList_AddIcon(hLarge,
hLgIconItem);
/* assign the image to the list view */
(void)ListView_SetImageList(hListView, hSmall, LVSIL_SMALL);
(void)ListView_SetImageList(hListView, hLarge, LVSIL_NORMAL);
ListView_SetImageList(Info->hListView,
hSmall,
LVSIL_SMALL);
ListView_SetImageList(Info->hListView,
hLarge,
LVSIL_NORMAL);
}
BOOL
RefreshServiceList(VOID)
RefreshServiceList(PMAIN_WND_INFO Info)
{
LVITEM item;
LVITEM lvItem;
TCHAR szNumServices[32];
TCHAR szStatus[64];
DWORD NumServices = 0;
DWORD Index;
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
(void)ListView_DeleteAllItems(hListView);
ListView_DeleteAllItems(Info->hListView);
InitListViewImage();
InitListViewImage(Info);
NumServices = GetServiceList();
NumServices = GetServiceList(Info);
if (NumServices)
{
@ -267,8 +292,10 @@ RefreshServiceList(VOID)
DWORD dwValueSize;
/* open the registry key for the service */
_sntprintf(buf, 300, Path,
pServiceStatus[Index].lpServiceName);
_sntprintf(buf,
300,
Path,
Info->pServiceStatus[Index].lpServiceName);
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
buf,
@ -278,49 +305,54 @@ RefreshServiceList(VOID)
/* set the display name */
ZeroMemory(&item, sizeof(LVITEM));
item.mask = LVIF_TEXT | LVIF_PARAM;
item.pszText = pServiceStatus[Index].lpDisplayName;
ZeroMemory(&lvItem, sizeof(LVITEM));
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.pszText = Info->pServiceStatus[Index].lpDisplayName;
/* Set a pointer for each service so we can query it later.
* Not all services are added to the list, so we can't query
* the item number as they become out of sync with the array */
item.lParam = (LPARAM)&pServiceStatus[Index];
lvItem.lParam = (LPARAM)&Info->pServiceStatus[Index];
item.iItem = ListView_GetItemCount(hListView);
item.iItem = ListView_InsertItem(hListView, &item);
lvItem.iItem = ListView_GetItemCount(Info->hListView);
lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
/* set the description */
if (GetDescription(pServiceStatus[Index].lpServiceName, &Description))
if (GetDescription(Info->pServiceStatus[Index].lpServiceName, &Description))
{
item.pszText = Description;
item.iSubItem = 1;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
lvItem.pszText = Description;
lvItem.iSubItem = 1;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM)&lvItem);
HeapFree(GetProcessHeap(), 0, Description);
HeapFree(ProcessHeap,
0,
Description);
}
/* set the status */
if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState
== SERVICE_RUNNING)
if (Info->pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
{
LoadString(hInstance, IDS_SERVICES_STARTED, szStatus,
sizeof(szStatus) / sizeof(TCHAR));
item.pszText = szStatus;
item.iSubItem = 2;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
LoadString(hInstance,
IDS_SERVICES_STARTED,
szStatus,
sizeof(szStatus) / sizeof(TCHAR));
lvItem.pszText = szStatus;
lvItem.iSubItem = 2;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM)&lvItem);
}
/* set the startup type */
dwValueSize = sizeof(DWORD);
if (RegQueryValueEx(hKey,
_T("Start"),
@ -335,33 +367,47 @@ RefreshServiceList(VOID)
if (StartUp == 0x02)
{
LoadString(hInstance, IDS_SERVICES_AUTO, szStatus,
sizeof(szStatus) / sizeof(TCHAR));
item.pszText = szStatus;
item.iSubItem = 3;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
LoadString(hInstance,
IDS_SERVICES_AUTO,
szStatus,
sizeof(szStatus) / sizeof(TCHAR));
lvItem.pszText = szStatus;
lvItem.iSubItem = 3;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM)&lvItem);
}
else if (StartUp == 0x03)
{
LoadString(hInstance, IDS_SERVICES_MAN, szStatus,
sizeof(szStatus) / sizeof(TCHAR));
item.pszText = szStatus;
item.iSubItem = 3;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
LoadString(hInstance,
IDS_SERVICES_MAN,
szStatus,
sizeof(szStatus) / sizeof(TCHAR));
lvItem.pszText = szStatus;
lvItem.iSubItem = 3;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM)&lvItem);
}
else if (StartUp == 0x04)
{
LoadString(hInstance, IDS_SERVICES_DIS, szStatus,
sizeof(szStatus) / sizeof(TCHAR));
item.pszText = szStatus;
item.iSubItem = 3;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
LoadString(hInstance,
IDS_SERVICES_DIS,
szStatus,
sizeof(szStatus) / sizeof(TCHAR));
lvItem.pszText = szStatus;
lvItem.iSubItem = 3;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM)&lvItem);
}
/* set Log On As */
dwValueSize = 0;
if (RegQueryValueEx(hKey,
_T("ObjectName"),
@ -374,7 +420,9 @@ RefreshServiceList(VOID)
continue;
}
LogOnAs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);
LogOnAs = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
dwValueSize);
if (LogOnAs == NULL)
{
RegCloseKey(hKey);
@ -387,32 +435,52 @@ RefreshServiceList(VOID)
(LPBYTE)LogOnAs,
&dwValueSize))
{
HeapFree(GetProcessHeap(), 0, LogOnAs);
HeapFree(ProcessHeap,
0,
LogOnAs);
RegCloseKey(hKey);
continue;
}
item.pszText = LogOnAs;
item.iSubItem = 4;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
lvItem.pszText = LogOnAs;
lvItem.iSubItem = 4;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM)&lvItem);
HeapFree(GetProcessHeap(), 0, LogOnAs);
HeapFree(ProcessHeap,
0,
LogOnAs);
RegCloseKey(hKey);
}
NumListedServ = ListView_GetItemCount(hListView);
NumListedServ = ListView_GetItemCount(Info->hListView);
/* set the number of listed services in the status bar */
LoadString(hInstance, IDS_NUM_SERVICES, szNumServices,
sizeof(szNumServices) / sizeof(TCHAR));
_sntprintf(buf, 300, szNumServices, NumListedServ);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);
LoadString(hInstance,
IDS_NUM_SERVICES,
szNumServices,
sizeof(szNumServices) / sizeof(TCHAR));
_sntprintf(buf,
300,
szNumServices,
NumListedServ);
SendMessage(Info->hStatus,
SB_SETTEXT,
0,
(LPARAM)buf);
}
/* turn redraw flag on. It's turned off initially via the LBS_NOREDRAW flag */
SendMessage (hListView, WM_SETREDRAW, TRUE, 0) ;
SendMessage (Info->hListView,
WM_SETREDRAW,
TRUE,
0) ;
return TRUE;
}
@ -421,7 +489,7 @@ RefreshServiceList(VOID)
DWORD
GetServiceList(VOID)
GetServiceList(PMAIN_WND_INFO Info)
{
SC_HANDLE ScHandle;
@ -436,7 +504,7 @@ GetServiceList(VOID)
SC_ENUM_PROCESS_INFO,
SERVICE_WIN32,
SERVICE_STATE_ALL,
(LPBYTE)pServiceStatus,
(LPBYTE)Info->pServiceStatus,
0, &BytesNeeded,
&NumServices,
&ResumeHandle,
@ -446,9 +514,11 @@ GetServiceList(VOID)
if (GetLastError() == ERROR_MORE_DATA)
{
/* reserve memory for service info array */
pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *)
HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
if (pServiceStatus == NULL)
Info->pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *)
HeapAlloc(ProcessHeap,
0,
BytesNeeded);
if (Info->pServiceStatus == NULL)
return FALSE;
/* fill array with service info */
@ -456,14 +526,16 @@ GetServiceList(VOID)
SC_ENUM_PROCESS_INFO,
SERVICE_WIN32,
SERVICE_STATE_ALL,
(LPBYTE)pServiceStatus,
(LPBYTE)Info->pServiceStatus,
BytesNeeded,
&BytesNeeded,
&NumServices,
&ResumeHandle,
0) == 0)
{
HeapFree(GetProcessHeap(), 0, pServiceStatus);
HeapFree(ProcessHeap,
0,
Info->pServiceStatus);
return FALSE;
}
}

View file

@ -3,7 +3,8 @@
/* about box info */
#define IDD_ABOUTBOX 200
#define IDC_LICENSE_EDIT 201
#define IDS_LICENSE 202
#define IDS_APPNAME 202
#define IDS_LICENSE 203
#define IDC_SERVLIST 1000
#define IDC_TOOLBAR 1001
@ -45,13 +46,14 @@
#define IDS_TOOLTIP_PROP 6000
#define IDS_TOOLTIP_REFRESH 6001
#define IDS_TOOLTIP_EXPORT 6002
#define IDS_TOOLTIP_START 6003
#define IDS_TOOLTIP_STOP 6004
#define IDS_TOOLTIP_PAUSE 6005
#define IDS_TOOLTIP_RESTART 6006
#define IDS_TOOLTIP_NEW 6007
#define IDS_TOOLTIP_HELP 6008
#define IDS_TOOLTIP_EXIT 6009
#define IDS_TOOLTIP_CREATE 6003
#define IDS_TOOLTIP_DELETE 6004
#define IDS_TOOLTIP_START 6005
#define IDS_TOOLTIP_STOP 6006
#define IDS_TOOLTIP_PAUSE 6007
#define IDS_TOOLTIP_RESTART 6008
#define IDS_TOOLTIP_HELP 6009
#define IDS_TOOLTIP_EXIT 6010
#define IDS_SERVICES_STARTED 5000
#define IDS_SERVICES_STOPPED 5001
@ -68,12 +70,13 @@
#define TBICON_REFRESH 1
#define TBICON_EXPORT 2
#define TBICON_CREATE 3
#define TBICON_START 4
#define TBICON_STOP 5
#define TBICON_PAUSE 6
#define TBICON_RESTART 7
#define TBICON_HELP 8
#define TBICON_EXIT 9
#define TBICON_DELETE 4
#define TBICON_START 5
#define TBICON_STOP 6
#define TBICON_PAUSE 7
#define TBICON_RESTART 8
#define TBICON_HELP 9
#define TBICON_EXIT 10
/* properties dialog */
#define IDD_DLG_GENERAL 10001

View file

@ -2,772 +2,65 @@
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/servman.c
* PURPOSE: Main window message handler
* PURPOSE: HQ
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include "servman.h"
const TCHAR ClassName[] = _T("ServiceManager");
#include "precomp.h"
HINSTANCE hInstance;
HWND hMainWnd;
HWND hListView;
HWND hStatus;
HWND hTool;
HWND hProgDlg;
HMENU hShortcutMenu;
INT SelectedItem = -1;
HANDLE ProcessHeap;
TBBUTTON *ptbb;
extern HWND hwndGenDlg;
INT GetSelectedItem(VOID)
int WINAPI
WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
return SelectedItem;
}
VOID SetView(DWORD View)
{
DWORD Style = GetWindowLong(hListView, GWL_STYLE);
if ((Style & LVS_TYPEMASK) != View)
SetWindowLong(hListView, GWL_STYLE, (Style & ~LVS_TYPEMASK) | View);
}
VOID SetMenuAndButtonStates()
{
HMENU hMainMenu;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
DWORD Flags, State;
/* get handle to menu */
hMainMenu = GetMenu(hMainWnd);
/* set all to greyed */
EnableMenuItem(hMainMenu, ID_START, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_STOP, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_PAUSE, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_RESUME, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_RESTART, MF_GRAYED);
EnableMenuItem(hShortcutMenu, ID_START, MF_GRAYED);
EnableMenuItem(hShortcutMenu, ID_STOP, MF_GRAYED);
EnableMenuItem(hShortcutMenu, ID_PAUSE, MF_GRAYED);
EnableMenuItem(hShortcutMenu, ID_RESUME, MF_GRAYED);
EnableMenuItem(hShortcutMenu, ID_RESTART, MF_GRAYED);
SendMessage(hTool, TB_SETSTATE, ID_START,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
SendMessage(hTool, TB_SETSTATE, ID_STOP,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
SendMessage(hTool, TB_SETSTATE, ID_PAUSE,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
SendMessage(hTool, TB_SETSTATE, ID_RESTART,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
if (GetSelectedItem() != -1)
{
/* get pointer to selected service */
Service = GetSelectedService();
Flags = Service->ServiceStatusProcess.dwControlsAccepted;
State = Service->ServiceStatusProcess.dwCurrentState;
if (State == SERVICE_STOPPED)
{
EnableMenuItem(hMainMenu, ID_START, MF_ENABLED);
EnableMenuItem(hShortcutMenu, ID_START, MF_ENABLED);
SendMessage(hTool, TB_SETSTATE, ID_START,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{
EnableMenuItem(hMainMenu, ID_STOP, MF_ENABLED);
EnableMenuItem(hShortcutMenu, ID_STOP, MF_ENABLED);
SendMessage(hTool, TB_SETSTATE, ID_STOP,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
if ( (Flags & SERVICE_ACCEPT_PAUSE_CONTINUE) && (State == SERVICE_RUNNING) )
{
EnableMenuItem(hMainMenu, ID_PAUSE, MF_ENABLED);
EnableMenuItem(hShortcutMenu, ID_PAUSE, MF_ENABLED);
SendMessage(hTool, TB_SETSTATE, ID_PAUSE,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{
EnableMenuItem(hMainMenu, ID_RESTART, MF_ENABLED);
EnableMenuItem(hShortcutMenu, ID_RESTART, MF_ENABLED);
SendMessage(hTool, TB_SETSTATE, ID_RESTART,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
}
else
{
EnableMenuItem(hMainMenu, ID_PROP, MF_GRAYED);
EnableMenuItem(hMainMenu, ID_DELETE, MF_GRAYED);
EnableMenuItem(hShortcutMenu, ID_DELETE, MF_GRAYED);
SendMessage(hTool, TB_SETSTATE, ID_PROP,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
TBADDBITMAP tbab;
INT iImageOffset;
INT statwidths[] = {110, -1}; /* widths of status bar */
TCHAR szTemp[256];
LVCOLUMN lvc = { 0 };
/* Toolbar buttons */
TBBUTTON tbb [NUM_BUTTONS] =
{ /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
{TBICON_PROP, ID_PROP, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0}, /* properties */
{TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh */
{TBICON_EXPORT, ID_EXPORT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* export */
/* Note: First item for a seperator is its width in pixels */
{15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
{TBICON_CREATE, ID_CREATE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* create */
{15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
{TBICON_START, ID_START, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* start */
{TBICON_STOP, ID_STOP, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* stop */
{TBICON_PAUSE, ID_PAUSE, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* pause */
{TBICON_RESTART, ID_RESTART, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* restart */
{15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
{TBICON_HELP, ID_HELP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* help */
{TBICON_EXIT, ID_EXIT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* exit */
};
ptbb = tbb;
/* ======================== Create Toolbar ============================== */
/* Create Toolbar */
hTool = CreateWindowEx(0,
TOOLBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
0, 0, 0, 0,
hwnd,
(HMENU)IDC_TOOLBAR,
hInstance,
NULL);
if(hTool == NULL)
MessageBox(hwnd, _T("Could not create tool bar."), _T("Error"), MB_OK | MB_ICONERROR);
/* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
SendMessage(hTool, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
/* Add custom images */
tbab.hInst = hInstance;
tbab.nID = IDB_BUTTONS;
iImageOffset = (INT)SendMessage(hTool, TB_ADDBITMAP, NUM_BUTTONS, (LPARAM)&tbab);
tbb[0].iBitmap += iImageOffset; /* properties */
tbb[1].iBitmap += iImageOffset; /* refresh */
tbb[2].iBitmap += iImageOffset; /* export */
tbb[4].iBitmap += iImageOffset; /* create */
tbb[6].iBitmap += iImageOffset; /* start */
tbb[7].iBitmap += iImageOffset; /* stop */
tbb[8].iBitmap += iImageOffset; /* pause */
tbb[9].iBitmap += iImageOffset; /* restart */
tbb[11].iBitmap += iImageOffset; /* help */
tbb[12].iBitmap += iImageOffset; /* exit */
/* Add buttons to toolbar */
SendMessage(hTool, TB_ADDBUTTONS, NUM_BUTTONS, (LPARAM) &tbb);
/* Show toolbar */
ShowWindow(hTool, SW_SHOWNORMAL);
/* ======================== Create List View ============================== */
hListView = CreateWindowEx(0,
WC_LISTVIEW,
NULL,
WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER |
LBS_NOTIFY | LVS_SORTASCENDING | LBS_NOREDRAW,
0, 0, 0, 0, /* sized via WM_SIZE */
hwnd,
(HMENU) IDC_SERVLIST,
hInstance,
NULL);
if (hListView == NULL)
MessageBox(hwnd, _T("Could not create List View."), _T("Error"), MB_OK | MB_ICONERROR);
(void)ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT |
/*LVS_EX_GRIDLINES |*/ LVS_EX_HEADERDRAGDROP);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
lvc.fmt = LVCFMT_LEFT;
/* Add columns to the list-view */
/* name */
lvc.iSubItem = 0;
lvc.cx = 150;
LoadString(hInstance, IDS_FIRSTCOLUMN, szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
(void)ListView_InsertColumn(hListView, 0, &lvc);
/* description */
lvc.iSubItem = 1;
lvc.cx = 240;
LoadString(hInstance, IDS_SECONDCOLUMN, szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
(void)ListView_InsertColumn(hListView, 1, &lvc);
/* status */
lvc.iSubItem = 2;
lvc.cx = 55;
LoadString(hInstance, IDS_THIRDCOLUMN, szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
(void)ListView_InsertColumn(hListView, 2, &lvc);
/* startup type */
lvc.iSubItem = 3;
lvc.cx = 80;
LoadString(hInstance, IDS_FOURTHCOLUMN, szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
(void)ListView_InsertColumn(hListView, 3, &lvc);
/* logon as */
lvc.iSubItem = 4;
lvc.cx = 100;
LoadString(hInstance, IDS_FITHCOLUMN, szTemp,
sizeof(szTemp) / sizeof(TCHAR));
lvc.pszText = szTemp;
(void)ListView_InsertColumn(hListView, 4, &lvc);
/* ======================== Create Status Bar ============================== */
hStatus = CreateWindowEx(0,
STATUSCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
0, 0, 0, 0,
hwnd,
(HMENU)IDC_STATUSBAR,
hInstance,
NULL);
if(hStatus == NULL)
MessageBox(hwnd, _T("Could not create status bar."),
_T("Error!"), MB_OK | MB_ICONERROR);
SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
/* ======================== Create Popup Menu ============================== */
hShortcutMenu = LoadMenu(hInstance, MAKEINTRESOURCE (IDR_POPUP));
hShortcutMenu = GetSubMenu(hShortcutMenu, 0);
/* ================= populate the list view with all services =================== */
RefreshServiceList();
}
break;
case WM_SIZE:
{
RECT rcTool;
int iToolHeight;
RECT rcStatus;
int iStatusHeight;
int lvHeight;
RECT rcClient;
/* Size toolbar and get height */
hTool = GetDlgItem(hwnd, IDC_TOOLBAR);
SendMessage(hTool, TB_AUTOSIZE, 0, 0);
GetWindowRect(hTool, &rcTool);
iToolHeight = rcTool.bottom - rcTool.top;
/* Size status bar and get height */
hStatus = GetDlgItem(hwnd, IDC_STATUSBAR);
SendMessage(hStatus, WM_SIZE, 0, 0);
GetWindowRect(hStatus, &rcStatus);
iStatusHeight = rcStatus.bottom - rcStatus.top;
/* Calculate remaining height and size list view */
GetClientRect(hwnd, &rcClient);
lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
hListView = GetDlgItem(hwnd, IDC_SERVLIST);
SetWindowPos(hListView, NULL, 0, iToolHeight, rcClient.right, lvHeight, SWP_NOZORDER);
}
break;
case WM_NOTIFY:
{
NMHDR* nm = (NMHDR*) lParam;
switch (nm->code)
{
case NM_DBLCLK:
OpenPropSheet(hwnd);
break;
case LVN_COLUMNCLICK:
break;
case LVN_ITEMCHANGED:
{
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
HMENU hMainMenu;
/* get handle to menu */
hMainMenu = GetMenu(hMainWnd);
/* activate properties menu item, if not already */
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, ID_DELETE, MF_BYCOMMAND) != MF_ENABLED)
{
EnableMenuItem(hMainMenu, ID_DELETE, MF_ENABLED);
EnableMenuItem(hShortcutMenu, ID_DELETE, MF_ENABLED);
}
/* globally set selected service */
SelectedItem = pnmv->iItem;
/* alter options for the service */
SetMenuAndButtonStates();
/* get pointer to selected service */
Service = GetSelectedService();
/* set current selected service in the status bar */
SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)Service->lpDisplayName);
/* show the properties button */
SendMessage(hTool, TB_SETSTATE, ID_PROP,
(LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
}
break;
case TTN_GETDISPINFO:
{
LPTOOLTIPTEXT lpttt;
UINT idButton;
lpttt = (LPTOOLTIPTEXT) lParam;
/* Specify the resource identifier of the descriptive
* text for the given button. */
idButton = (UINT)lpttt->hdr.idFrom;
switch (idButton)
{
case ID_PROP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
break;
case ID_REFRESH:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
break;
case ID_EXPORT:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT);
break;
case ID_CREATE:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_NEW);
break;
case ID_START:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_START);
break;
case ID_STOP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
break;
case ID_PAUSE:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE);
break;
case ID_RESTART:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);
break;
case ID_HELP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP);
break;
case ID_EXIT:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
break;
}
}
break;
default:
break;
}
}
break;
case WM_CONTEXTMENU:
{
int xPos, yPos;
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
TrackPopupMenuEx(hShortcutMenu, TPM_RIGHTBUTTON,
xPos, yPos, hwnd, NULL);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_PROP:
if (GetSelectedItem() != -1)
OpenPropSheet(hwnd);
break;
case ID_REFRESH:
RefreshServiceList();
SelectedItem = -1;
/* disable menus and buttons */
SetMenuAndButtonStates();
/* clear the service in the status bar */
SendMessage(hStatus, SB_SETTEXT, 1, _T('\0'));
break;
case ID_EXPORT:
ExportFile(hListView);
SetFocus(hListView);
break;
case ID_CREATE:
DialogBox(hInstance,
MAKEINTRESOURCE(IDD_DLG_CREATE),
hMainWnd,
(DLGPROC)CreateDialogProc);
SetFocus(hListView);
break;
case ID_DELETE:
{
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
Service = GetSelectedService();
if (Service->ServiceStatusProcess.dwCurrentState !=
SERVICE_RUNNING)
{
DialogBox(hInstance,
MAKEINTRESOURCE(IDD_DLG_DELETE),
hMainWnd,
(DLGPROC)DeleteDialogProc);
}
else
{
TCHAR Buf[60];
LoadString(hInstance, IDS_DELETE_STOP, Buf,
sizeof(Buf) / sizeof(TCHAR));
DisplayString(Buf);
}
SetFocus(hListView);
}
break;
case ID_START:
{
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
TCHAR ProgDlgBuf[100];
/* open the progress dialog */
hProgDlg = CreateDialog(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DLG_PROGRESS),
hMainWnd,
(DLGPROC)ProgressDialogProc);
if (hProgDlg != NULL)
{
ShowWindow(hProgDlg, SW_SHOW);
/* write the info to the progress dialog */
LoadString(hInstance, IDS_PROGRESS_INFO_START, ProgDlgBuf,
sizeof(ProgDlgBuf) / sizeof(TCHAR));
SendDlgItemMessage(hProgDlg, IDC_SERVCON_INFO, WM_SETTEXT,
0, (LPARAM)ProgDlgBuf);
/* get pointer to selected service */
Service = GetSelectedService();
/* write the service name to the progress dialog */
SendDlgItemMessage(hProgDlg, IDC_SERVCON_NAME, WM_SETTEXT, 0,
(LPARAM)Service->lpServiceName);
}
if ( DoStartService(hProgDlg) )
{
LVITEM item;
TCHAR szStatus[64];
TCHAR buf[25];
LoadString(hInstance, IDS_SERVICES_STARTED, szStatus,
sizeof(szStatus) / sizeof(TCHAR));
item.pszText = szStatus;
item.iItem = GetSelectedItem();
item.iSubItem = 2;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
/* change dialog status */
if (hwndGenDlg)
{
LoadString(hInstance, IDS_SERVICES_STARTED, buf,
sizeof(buf) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT,
0, (LPARAM)buf);
}
}
SendMessage(hProgDlg, WM_DESTROY, 0, 0);
}
break;
case ID_STOP:
{
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
TCHAR ProgDlgBuf[100];
/* open the progress dialog */
hProgDlg = CreateDialog(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DLG_PROGRESS),
hMainWnd,
(DLGPROC)ProgressDialogProc);
if (hProgDlg != NULL)
{
ShowWindow(hProgDlg, SW_SHOW);
/* write the info to the progress dialog */
LoadString(hInstance, 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();
/* write the service name to the progress dialog */
SendDlgItemMessage(hProgDlg, IDC_SERVCON_NAME, WM_SETTEXT, 0,
(LPARAM)Service->lpServiceName);
}
if( Control(hProgDlg, SERVICE_CONTROL_STOP) )
{
LVITEM item;
TCHAR buf[25];
item.pszText = _T('\0');
item.iItem = GetSelectedItem();
item.iSubItem = 2;
SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
/* change dialog status */
if (hwndGenDlg)
{
LoadString(hInstance, IDS_SERVICES_STOPPED, buf,
sizeof(buf) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT,
0, (LPARAM)buf);
}
}
SendMessage(hProgDlg, WM_DESTROY, 0, 0);
}
break;
case ID_PAUSE:
Control(hProgDlg, SERVICE_CONTROL_PAUSE);
break;
case ID_RESUME:
Control(hProgDlg, SERVICE_CONTROL_CONTINUE );
break;
case ID_RESTART:
SendMessage(hMainWnd, WM_COMMAND, 0, ID_STOP);
SendMessage(hMainWnd, WM_COMMAND, 0, ID_START);
break;
case ID_HELP:
MessageBox(NULL, _T("Help is not yet implemented\n"),
_T("Note!"), MB_OK | MB_ICONINFORMATION);
SetFocus(hListView);
break;
case ID_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_VIEW_LARGE:
SetView(LVS_ICON);
break;
case ID_VIEW_SMALL:
SetView(LVS_SMALLICON);
break;
case ID_VIEW_LIST:
SetView(LVS_LIST);
break;
case ID_VIEW_DETAILS:
SetView(LVS_REPORT);
break;
case ID_VIEW_CUSTOMIZE:
break;
case ID_ABOUT:
DialogBox(hInstance,
MAKEINTRESOURCE(IDD_ABOUTBOX),
hMainWnd,
(DLGPROC)AboutDialogProc);
SetFocus(hListView);
break;
}
break;
case WM_CLOSE:
FreeMemory(); /* free the service array */
DestroyMenu(hShortcutMenu);
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
#ifdef _MSC_VER
#pragma warning(disable : 4100)
#endif
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
LPTSTR lpAppName;
HWND hMainWnd;
MSG Msg;
int Ret = 1;
INITCOMMONCONTROLSEX icex;
hInstance = hThisInstance;
ProcessHeap = GetProcessHeap();
InitCommonControls();
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
InitCommonControlsEx(&icex);
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wc.lpszClassName = ClassName;
wc.hIconSm = (HICON)LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
if (!AllocAndLoadString(&lpAppName, hInstance, IDS_APPNAME))
{
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),
MB_ICONEXCLAMATION | MB_OK);
return 0;
return 1;
}
hMainWnd = CreateWindowEx(
0,
ClassName,
_T("ReactOS Service Manager"),
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, 650, 450,
NULL, NULL, hInstance, NULL);
if(hMainWnd == NULL)
if (InitMainWindowImpl())
{
MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hMainWnd, nCmdShow);
UpdateWindow(hMainWnd);
while( GetMessage( &Msg, NULL, 0, 0 ) )
{
if(! IsDialogMessage(hProgDlg, &Msg) )
hMainWnd = CreateMainWindow(lpAppName,
nCmdShow);
if (hMainWnd != NULL)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
/* pump the message queue */
while( GetMessage( &Msg, NULL, 0, 0 ) )
{
//if(! IsDialogMessage(hProgDlg, &Msg) )
//{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
//}
}
Ret = 0;
}
UninitMainWindowImpl();
}
return (int)Msg.wParam;
LocalFree((HLOCAL)lpAppName);
return Ret;
}

View file

@ -1,44 +0,0 @@
#ifndef __SERVMAN_H
#define __SERVMAN_H
//#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h> /* GET_X/Y_LPARAM */
#include <stdio.h>
#include <tchar.h>
#include <commctrl.h>
#include "resource.h"
#define MAX_KEY_LENGTH 256
#define NUM_BUTTONS 13
#define PROGRESSRANGE 8
BOOL RefreshServiceList(VOID);
BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK CreateDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK DeleteDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ProgressDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL DoStartService(HWND hProgDlg);
BOOL Control(HWND hProgBar, DWORD Control);
INT GetSelectedItem(VOID);
ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(VOID);
VOID GetError(DWORD);
VOID FreeMemory(VOID);
VOID DisplayString(PTCHAR);
BOOL SetDescription(LPTSTR, LPTSTR);
BOOL GetDescription(LPTSTR, LPTSTR *);
BOOL GetExecutablePath(LPTSTR *);
LONG APIENTRY OpenPropSheet(HWND);
DWORD GetServiceList(VOID);
VOID ExportFile(HWND);
#endif /* __SERVMAN_H */

View file

@ -10,6 +10,7 @@
<define name="_WIN32_WINNT">0x501</define>
<library>kernel32</library>
<library>user32</library>
<library>gdi32</library>
<library>advapi32</library>
<library>version</library>
<library>comctl32</library>
@ -21,14 +22,16 @@
<file>create.c</file>
<file>delete.c</file>
<file>export.c</file>
<file>geterror.c</file>
<file>mainwnd.c</file>
<file>misc.c</file>
<file>progress.c</file>
<file>propsheet.c</file>
<file>query.c</file>
<file>servman.c</file>
<file>start.c</file>
<file>start.c</file>
<file>stop.c</file>
</compilationunit>
<file>servman.rc</file>
<pch>servman.h</pch>
<pch>precomp.h</pch>
</module>
</rbuild>

View file

@ -3,16 +3,21 @@
#include "resource.h"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Service Manager\0"
#define REACTOS_STR_INTERNAL_NAME "services\0"
#define REACTOS_STR_ORIGINAL_FILENAME "services.exe\0"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Service Manager\0"
#define REACTOS_STR_INTERNAL_NAME "services\0"
#define REACTOS_STR_ORIGINAL_FILENAME "services.exe\0"
//#include <reactos/version.rc>
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//1 24 DISCARDABLE "manifest.xml"
STRINGTABLE DISCARDABLE
BEGIN
IDS_APPNAME "ReactOS Service Manager"
END
IDI_SM_ICON ICON "res/system.ico"
IDB_BUTTONS BITMAP DISCARDABLE "res/toolbar.bmp"
#include "En.rc"
//#include "De.rc" /* I don't want to have to keep altering 2 files whilst developing */
#include "Ru.rc" /* You have to alter 3 of them now ;-) */

View file

@ -7,35 +7,46 @@
*
*/
#include "servman.h"
#include "precomp.h"
extern HWND hListView;
extern HWND hMainWnd;
extern HWND hwndGenDlg;
BOOL DoStartService(HWND hProgDlg)
static BOOL
DoStartService(PMAIN_WND_INFO Info)
{
HWND hProgBar;
SC_HANDLE hSCManager;
SC_HANDLE hSc;
SERVICE_STATUS_PROCESS ServiceStatus;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
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();
Service = GetSelectedService(Info);
/* set the progress bar range and step */
hProgBar = GetDlgItem(hProgDlg, IDC_SERVCON_PROGRESS);
SendMessage(hProgBar, PBM_SETRANGE, 0, MAKELPARAM(0, PROGRESSRANGE));
SendMessage(hProgBar, PBM_SETSTEP, (WPARAM)1, 0);
hProgBar = GetDlgItem(Info->hProgDlg,
IDC_SERVCON_PROGRESS);
SendMessage(hProgBar,
PBM_SETRANGE,
0,
MAKELPARAM(0, PROGRESSRANGE));
SendMessage(hProgBar,
PBM_SETSTEP,
(WPARAM)1,
0);
/* 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(0);
GetError();
return FALSE;
}
@ -43,14 +54,14 @@ BOOL DoStartService(HWND hProgDlg)
hSc = OpenService(hSCManager, Service->lpServiceName, SERVICE_ALL_ACCESS);
if (hSc == NULL)
{
GetError(0);
GetError();
return FALSE;
}
/* start the service opened */
if (! StartService(hSc, ArgCount, NULL))
{
GetError(0);
GetError();
return FALSE;
}
@ -61,7 +72,7 @@ BOOL DoStartService(HWND hProgDlg)
sizeof(SERVICE_STATUS_PROCESS),
&BytesNeeded))
{
GetError(0);
GetError();
return FALSE;
}
@ -96,7 +107,7 @@ BOOL DoStartService(HWND hProgDlg)
sizeof(SERVICE_STATUS_PROCESS),
&BytesNeeded))
{
GetError(0);
GetError();
return FALSE;
}
@ -130,3 +141,87 @@ BOOL DoStartService(HWND hProgDlg)
}
BOOL
DoStart(PMAIN_WND_INFO Info)
{
HWND hProgDlg;
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
TCHAR ProgDlgBuf[100];
/* open the progress dialog */
hProgDlg = CreateDialog(hInstance,
MAKEINTRESOURCE(IDD_DLG_PROGRESS),
Info->hMainWnd,
(DLGPROC)ProgressDialogProc);
if (hProgDlg != NULL)
{
ShowWindow(hProgDlg,
SW_SHOW);
/* write the info to the progress dialog */
LoadString(hInstance,
IDS_PROGRESS_INFO_START,
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);
}
/* start the service */
if ( DoStartService(Info) )
{
LVITEM item;
TCHAR szStatus[64];
TCHAR buf[25];
LoadString(hInstance,
IDS_SERVICES_STARTED,
szStatus,
sizeof(szStatus) / sizeof(TCHAR));
item.pszText = szStatus;
item.iItem = Info->SelectedItem;
item.iSubItem = 2;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
item.iItem,
(LPARAM) &item);
/* change dialog status */
if (hwndGenDlg)
{
LoadString(hInstance,
IDS_SERVICES_STARTED,
buf,
sizeof(buf) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg,
IDC_SERV_STATUS,
WM_SETTEXT,
0,
(LPARAM)buf);
}
}
SendMessage(hProgDlg,
WM_DESTROY,
0,
0);
return TRUE;
}

View file

@ -0,0 +1,82 @@
/*
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/start.c
* PURPOSE: Stops a service
* COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#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 */
hProgDlg = CreateDialog(hInstance,
MAKEINTRESOURCE(IDD_DLG_PROGRESS),
Info->hMainWnd,
(DLGPROC)ProgressDialogProc);
if (hProgDlg != NULL)
{
ShowWindow(hProgDlg,
SW_SHOW);
/* write the info to the progress dialog */
LoadString(hInstance,
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);
}
if( Control(Info, SERVICE_CONTROL_STOP) )
{
LVITEM item;
TCHAR buf[25];
item.pszText = _T('\0');
item.iItem = Info->SelectedItem;
item.iSubItem = 2;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
item.iItem,
(LPARAM) &item);
/* change dialog status */
if (hwndGenDlg)
{
LoadString(hInstance,
IDS_SERVICES_STOPPED,
buf,
sizeof(buf) / sizeof(TCHAR));
SendDlgItemMessageW(hwndGenDlg,
IDC_SERV_STATUS, WM_SETTEXT,
0,
(LPARAM)buf);
}
}
SendMessage(hProgDlg, WM_DESTROY, 0, 0);
return TRUE;
}