From 4ab28a9dcfa6828da3666426e83e61f40d1cb40a Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Wed, 29 Aug 2007 15:46:52 +0000 Subject: [PATCH] - 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 --- .../applications/mscutils/servman/mainwnd.c | 152 +++++++++++------- .../applications/mscutils/servman/precomp.h | 7 + .../applications/mscutils/servman/propsheet.c | 46 ++++-- .../applications/mscutils/servman/query.c | 4 +- .../applications/mscutils/servman/start.c | 2 +- 5 files changed, 137 insertions(+), 74 deletions(-) diff --git a/reactos/base/applications/mscutils/servman/mainwnd.c b/reactos/base/applications/mscutils/servman/mainwnd.c index 78149a4b74b..796d3ed5581 100644 --- a/reactos/base/applications/mscutils/servman/mainwnd.c +++ b/reactos/base/applications/mscutils/servman/mainwnd.c @@ -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); } diff --git a/reactos/base/applications/mscutils/servman/precomp.h b/reactos/base/applications/mscutils/servman/precomp.h index d6a996a53b0..db823cfcbf3 100644 --- a/reactos/base/applications/mscutils/servman/precomp.h +++ b/reactos/base/applications/mscutils/servman/precomp.h @@ -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); diff --git a/reactos/base/applications/mscutils/servman/propsheet.c b/reactos/base/applications/mscutils/servman/propsheet.c index 2f8312a1be8..8c0f952e179 100644 --- a/reactos/base/applications/mscutils/servman/propsheet.c +++ b/reactos/base/applications/mscutils/servman/propsheet.c @@ -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; } } diff --git a/reactos/base/applications/mscutils/servman/query.c b/reactos/base/applications/mscutils/servman/query.c index 357898c0cae..2068b4f3ab9 100644 --- a/reactos/base/applications/mscutils/servman/query.c +++ b/reactos/base/applications/mscutils/servman/query.c @@ -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, diff --git a/reactos/base/applications/mscutils/servman/start.c b/reactos/base/applications/mscutils/servman/start.c index 19fd099c921..4926e0c617c 100644 --- a/reactos/base/applications/mscutils/servman/start.c +++ b/reactos/base/applications/mscutils/servman/start.c @@ -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,