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

View file

@ -17,6 +17,12 @@
#define NO_ITEM_SELECTED -1 #define NO_ITEM_SELECTED -1
#define MAX_KEY_LENGTH 256 #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 typedef struct _MAIN_WND_INFO
{ {
HWND hMainWnd; HWND hMainWnd;
@ -54,6 +60,7 @@ typedef struct _MENU_HINT
UINT HintId; UINT HintId;
} MENU_HINT, *PMENU_HINT; } MENU_HINT, *PMENU_HINT;
VOID ChangeListViewText(PMAIN_WND_INFO Info, ENUM_SERVICE_STATUS_PROCESS* pService, UINT Column);
BOOL InitMainWindowImpl(VOID); BOOL InitMainWindowImpl(VOID);
VOID UninitMainWindowImpl(VOID); VOID UninitMainWindowImpl(VOID);
HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow); HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow);

View file

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

View file

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

View file

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