- implement changing of the startup type from the properties dialog

- add functionality for changing the startup type listview text
- fix a couple of bugs

svn path=/trunk/; revision=28651
This commit is contained in:
Ged Murphy 2007-08-29 15:46:52 +00:00
parent dc17eb77d0
commit 4ab28a9dcf
5 changed files with 137 additions and 74 deletions

View file

@ -9,12 +9,6 @@
#include "precomp.h"
#define LVNAME 0
#define LVDESC 1
#define LVSTATUS 2
#define LVSTARTUP 3
#define LVLOGONAS 4
static const TCHAR szMainWndClass[] = TEXT("ServManWndClass");
BOOL bSortAscending = TRUE;
@ -142,70 +136,112 @@ SetListViewStyle(HWND hListView,
}
}
static VOID
VOID
ChangeListViewText(PMAIN_WND_INFO Info,
ENUM_SERVICE_STATUS_PROCESS* pService,
UINT Column)
{
LVITEM item;
LVFINDINFO lvfi;
LVITEM lvItem;
INT index;
item.iItem = Info->SelectedItem;
item.iSubItem = Column;
switch (Column)
lvfi.flags = LVFI_PARAM;
lvfi.lParam = (LPARAM)pService;
index = ListView_FindItem(Info->hListView,
-1,
&lvfi);
if (index != -1)
{
case LVNAME:
lvItem.iItem = index;
lvItem.iSubItem = Column;
break;
case LVDESC:
switch (Column)
{
LPTSTR lpDescription;
case LVNAME:
lpDescription = GetServiceDescription(Info->pCurrentService->lpServiceName);
break;
item.pszText = lpDescription;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
item.iItem,
(LPARAM) &item);
HeapFree(ProcessHeap,
0,
lpDescription);
}
break;
case LVSTATUS:
{
TCHAR szStatus[64];
if (Info->pCurrentService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
case LVDESC:
{
LoadString(hInstance,
IDS_SERVICES_STARTED,
szStatus,
sizeof(szStatus) / sizeof(TCHAR));
LPTSTR lpDescription;
lpDescription = GetServiceDescription(pService->lpServiceName);
lvItem.pszText = lpDescription;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM) &lvItem);
HeapFree(ProcessHeap,
0,
lpDescription);
}
else
break;
case LVSTATUS:
{
szStatus[0] = 0;
TCHAR szStatus[64];
if (pService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
{
LoadString(hInstance,
IDS_SERVICES_STARTED,
szStatus,
sizeof(szStatus) / sizeof(TCHAR));
}
else
{
szStatus[0] = 0;
}
lvItem.pszText = szStatus;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM) &lvItem);
}
break;
item.pszText = szStatus;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
item.iItem,
(LPARAM) &item);
case LVSTARTUP:
{
LPQUERY_SERVICE_CONFIG lpServiceConfig;
LPTSTR lpStartup = NULL;
DWORD StringId = 0;
lpServiceConfig = GetServiceConfig(pService->lpServiceName);
switch (lpServiceConfig->dwStartType)
{
case 2: StringId = IDS_SERVICES_AUTO; break;
case 3: StringId = IDS_SERVICES_MAN; break;
case 4: StringId = IDS_SERVICES_DIS; break;
}
if (StringId)
AllocAndLoadString(&lpStartup,
hInstance,
StringId);
lvItem.pszText = lpStartup;
SendMessage(Info->hListView,
LVM_SETITEMTEXT,
lvItem.iItem,
(LPARAM)&lvItem);
HeapFree(ProcessHeap,
0,
lpStartup);
HeapFree(ProcessHeap,
0,
lpServiceConfig);
}
break;
case LVLOGONAS:
break;
}
break;
case LVSTARTUP:
break;
case LVLOGONAS:
break;
}
}
@ -715,7 +751,7 @@ MainWndCommand(PMAIN_WND_INFO Info,
if (DoStart(Info))
{
UpdateServiceStatus(Info->pCurrentService);
ChangeListViewText(Info, LVSTATUS);
ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
SetMenuAndButtonStates(Info);
SetFocus(Info->hListView);
}
@ -726,7 +762,7 @@ MainWndCommand(PMAIN_WND_INFO Info,
if (DoStop(Info))
{
UpdateServiceStatus(Info->pCurrentService);
ChangeListViewText(Info, LVSTATUS);
ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
SetMenuAndButtonStates(Info);
SetFocus(Info->hListView);
}
@ -745,7 +781,7 @@ MainWndCommand(PMAIN_WND_INFO Info,
{
DoStart(Info);
UpdateServiceStatus(Info->pCurrentService);
ChangeListViewText(Info, LVSTATUS);
ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
SetMenuAndButtonStates(Info);
SetFocus(Info->hListView);
}

View file

@ -17,6 +17,12 @@
#define NO_ITEM_SELECTED -1
#define MAX_KEY_LENGTH 256
#define LVNAME 0
#define LVDESC 1
#define LVSTATUS 2
#define LVSTARTUP 3
#define LVLOGONAS 4
typedef struct _MAIN_WND_INFO
{
HWND hMainWnd;
@ -54,6 +60,7 @@ typedef struct _MENU_HINT
UINT HintId;
} MENU_HINT, *PMENU_HINT;
VOID ChangeListViewText(PMAIN_WND_INFO Info, ENUM_SERVICE_STATUS_PROCESS* pService, UINT Column);
BOOL InitMainWindowImpl(VOID);
VOID UninitMainWindowImpl(VOID);
HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow);

View file

@ -200,6 +200,7 @@ GetDlgInfo(PSERVICEPROPSHEET dlgInfo,
}
}
VOID
SaveDlgInfo(PSERVICEPROPSHEET dlgInfo,
HWND hwndDlg)
@ -208,23 +209,42 @@ SaveDlgInfo(PSERVICEPROPSHEET dlgInfo,
HWND hList;
DWORD StartUp;
hList = GetDlgItem(hwndDlg, IDC_START_TYPE);
StartUp = SendMessage(hList,
CB_GETCURSEL,
0,
0);
switch (StartUp)
pServiceConfig = HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(*pServiceConfig));
if (pServiceConfig)
{
case 0: pServiceConfig->dwStartType = SERVICE_AUTO_START; break;
case 1: pServiceConfig->dwStartType = SERVICE_DEMAND_START; break;
case 2: pServiceConfig->dwStartType = SERVICE_DISABLED; break;
pServiceConfig->dwServiceType = SERVICE_NO_CHANGE;
pServiceConfig->dwErrorControl = SERVICE_NO_CHANGE;
hList = GetDlgItem(hwndDlg, IDC_START_TYPE);
StartUp = SendMessage(hList,
CB_GETCURSEL,
0,
0);
switch (StartUp)
{
case 0: pServiceConfig->dwStartType = SERVICE_AUTO_START; break;
case 1: pServiceConfig->dwStartType = SERVICE_DEMAND_START; break;
case 2: pServiceConfig->dwStartType = SERVICE_DISABLED; break;
}
if (SetServiceConfig(pServiceConfig,
dlgInfo->pService->lpServiceName,
NULL))
{
ChangeListViewText(dlgInfo->Info,
dlgInfo->pService,
LVSTARTUP);
}
HeapFree(ProcessHeap,
0,
pServiceConfig);
}
}
/*
* General Property dialog callback.
* Controls messages to the General dialog
@ -317,7 +337,7 @@ GeneralPageProc(HWND hwndDlg,
switch (lpnm->code)
{
case PSN_APPLY:
MessageBox(NULL, _T("apply"), NULL, 0);
SaveDlgInfo(dlgInfo, hwndDlg);
break;
}
}

View file

@ -110,7 +110,7 @@ SetServiceConfig(LPQUERY_SERVICE_CONFIG pServiceConfig,
{
hSc = OpenService(hSCManager,
lpServiceName,
SERVICE_QUERY_CONFIG);
SERVICE_CHANGE_CONFIG);
if (hSc)
{
if (ChangeServiceConfig(hSc,
@ -119,7 +119,7 @@ SetServiceConfig(LPQUERY_SERVICE_CONFIG pServiceConfig,
pServiceConfig->dwErrorControl,
pServiceConfig->lpBinaryPathName,
pServiceConfig->lpLoadOrderGroup,
&pServiceConfig->dwTagId,
pServiceConfig->dwTagId ? &pServiceConfig->dwTagId : NULL,
pServiceConfig->lpDependencies,
pServiceConfig->lpServiceStartName,
lpPassword,

View file

@ -24,7 +24,7 @@ DoStartService(PMAIN_WND_INFO Info,
hSCManager = OpenSCManager(NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL)
if (hSCManager != NULL)
{
hSc = OpenService(hSCManager,
Info->pCurrentService->lpServiceName,