mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 18:22:35 +00:00
simplify some code
svn path=/trunk/; revision=28472
This commit is contained in:
parent
520d244fe2
commit
0c529df2e0
5 changed files with 207 additions and 201 deletions
|
@ -304,6 +304,58 @@ pCreateToolbar(PMAIN_WND_INFO Info)
|
|||
}
|
||||
|
||||
|
||||
static VOID
|
||||
InitListViewImage(PMAIN_WND_INFO Info)
|
||||
{
|
||||
HICON hSmIconItem, hLgIconItem; /* icon for list-view items */
|
||||
HIMAGELIST hSmall, hLarge; /* image list for other views */
|
||||
|
||||
|
||||
/* Create the icon image lists */
|
||||
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
|
||||
GetSystemMetrics(SM_CYSMICON),
|
||||
ILC_MASK | ILC_COLOR32,
|
||||
1,
|
||||
1);
|
||||
|
||||
hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
|
||||
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);
|
||||
|
||||
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(Info->hListView,
|
||||
hSmall,
|
||||
LVSIL_SMALL);
|
||||
(void)ListView_SetImageList(Info->hListView,
|
||||
hLarge,
|
||||
LVSIL_NORMAL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static BOOL
|
||||
CreateListView(PMAIN_WND_INFO Info)
|
||||
{
|
||||
|
@ -397,6 +449,8 @@ CreateListView(PMAIN_WND_INFO Info)
|
|||
4,
|
||||
&lvc);
|
||||
|
||||
InitListViewImage(Info);
|
||||
|
||||
/* check the details view menu item */
|
||||
CheckMenuRadioItem(GetMenu(Info->hMainWnd),
|
||||
ID_VIEW_LARGE,
|
||||
|
|
|
@ -59,7 +59,7 @@ typedef struct _MAIN_WND_INFO
|
|||
struct _PROP_DLG_INFO *PropSheet;
|
||||
|
||||
/* status flags */
|
||||
BOOL InMenuLoop : 1;
|
||||
BOOL InMenuLoop;
|
||||
|
||||
} MAIN_WND_INFO, *PMAIN_WND_INFO;
|
||||
|
||||
|
@ -97,8 +97,8 @@ 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 *);
|
||||
LPTSTR GetDescription(LPTSTR);
|
||||
LPTSTR GetExecutablePath(PMAIN_WND_INFO Info);
|
||||
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
|
||||
DWORD GetServiceList(PMAIN_WND_INFO Info);
|
||||
|
||||
|
|
|
@ -125,20 +125,24 @@ GetDlgInfo(PMAIN_WND_INFO Info)
|
|||
(LPARAM)Info->PropSheet->lpDisplayName);
|
||||
|
||||
/* set the description */
|
||||
if (GetDescription(Info->CurrentService->lpServiceName, &Info->PropSheet->lpDescription))
|
||||
if (Info->PropSheet->lpDescription = GetDescription(Info->CurrentService->lpServiceName))
|
||||
{
|
||||
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
|
||||
IDC_DESCRIPTION,
|
||||
WM_SETTEXT,
|
||||
0,
|
||||
(LPARAM)Info->PropSheet->lpDescription);
|
||||
}
|
||||
|
||||
/* set the executable path */
|
||||
if (GetExecutablePath(Info, &Info->PropSheet->lpPathToExe))
|
||||
if (Info->PropSheet->lpPathToExe = GetExecutablePath(Info))
|
||||
{
|
||||
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
|
||||
IDC_EXEPATH,
|
||||
WM_SETTEXT,
|
||||
0,
|
||||
(LPARAM)Info->PropSheet->lpPathToExe);
|
||||
}
|
||||
|
||||
/* set startup type */
|
||||
SetStartupType(Info);
|
||||
|
@ -182,8 +186,8 @@ GetDlgInfo(PMAIN_WND_INFO Info)
|
|||
static INT_PTR CALLBACK
|
||||
GeneralPageProc(HWND hwndDlg,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
PMAIN_WND_INFO Info;
|
||||
|
||||
|
@ -247,6 +251,16 @@ GeneralPageProc(HWND hwndDlg,
|
|||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
if (Info->PropSheet->lpDescription)
|
||||
HeapFree(ProcessHeap,
|
||||
0,
|
||||
Info->PropSheet->lpDescription);
|
||||
|
||||
if (Info->PropSheet->lpPathToExe)
|
||||
HeapFree(ProcessHeap,
|
||||
0,
|
||||
Info->PropSheet->lpPathToExe);
|
||||
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
|
|
|
@ -27,115 +27,16 @@ GetSelectedService(PMAIN_WND_INFO Info)
|
|||
}
|
||||
|
||||
|
||||
/* Sets the service description in the registry */
|
||||
BOOL SetDescription(LPTSTR ServiceName, LPTSTR Description)
|
||||
{
|
||||
HKEY hKey;
|
||||
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
||||
TCHAR buf[300];
|
||||
TCHAR szBuf[MAX_PATH];
|
||||
LONG val;
|
||||
|
||||
|
||||
/* open the registry key for the service */
|
||||
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, ServiceName);
|
||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
buf,
|
||||
0,
|
||||
KEY_WRITE,
|
||||
&hKey);
|
||||
|
||||
|
||||
if ((val = RegSetValueEx(hKey,
|
||||
_T("Description"),
|
||||
0,
|
||||
REG_SZ,
|
||||
(LPBYTE)Description,
|
||||
(DWORD)lstrlen(szBuf)+1)) != ERROR_SUCCESS)
|
||||
{
|
||||
//GetError(val);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
RegCloseKey(hKey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Retrives the service description from the registry */
|
||||
BOOL GetDescription(LPTSTR lpServiceName, LPTSTR *retDescription)
|
||||
{
|
||||
HKEY hKey;
|
||||
LPTSTR Description = NULL;
|
||||
DWORD dwValueSize = 0;
|
||||
LONG ret;
|
||||
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
||||
TCHAR buf[300];
|
||||
|
||||
/* open the registry key for the service */
|
||||
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, lpServiceName);
|
||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
buf,
|
||||
0,
|
||||
KEY_READ,
|
||||
&hKey);
|
||||
|
||||
ret = RegQueryValueEx(hKey,
|
||||
_T("Description"),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&dwValueSize);
|
||||
if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret != ERROR_INVALID_HANDLE)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (ret != ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
Description = HeapAlloc(ProcessHeap,
|
||||
HEAP_ZERO_MEMORY,
|
||||
dwValueSize);
|
||||
if (Description == NULL)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(RegQueryValueEx(hKey,
|
||||
_T("Description"),
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)Description,
|
||||
&dwValueSize))
|
||||
{
|
||||
HeapFree(ProcessHeap,
|
||||
0,
|
||||
Description);
|
||||
RegCloseKey(hKey);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy pointer over */
|
||||
*retDescription = Description;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* get vendor of service binary */
|
||||
BOOL
|
||||
GetExecutablePath(PMAIN_WND_INFO Info,
|
||||
LPTSTR *ExePath)
|
||||
LPTSTR
|
||||
GetExecutablePath(PMAIN_WND_INFO Info)
|
||||
{
|
||||
SC_HANDLE hSCManager = NULL;
|
||||
SC_HANDLE hSc = NULL;
|
||||
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
|
||||
DWORD BytesNeeded = 0;
|
||||
LPTSTR lpExePath = NULL;
|
||||
|
||||
/* open handle to the SCM */
|
||||
hSCManager = OpenSCManager(NULL,
|
||||
|
@ -157,7 +58,6 @@ GetExecutablePath(PMAIN_WND_INFO Info,
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
|
||||
if (!QueryServiceConfig(hSc,
|
||||
pServiceConfig,
|
||||
0,
|
||||
|
@ -165,99 +65,40 @@ GetExecutablePath(PMAIN_WND_INFO Info,
|
|||
{
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
pServiceConfig = (LPQUERY_SERVICE_CONFIG)
|
||||
HeapAlloc(ProcessHeap,
|
||||
0,
|
||||
BytesNeeded);
|
||||
pServiceConfig = (LPQUERY_SERVICE_CONFIG) HeapAlloc(ProcessHeap,
|
||||
0,
|
||||
BytesNeeded);
|
||||
if (pServiceConfig == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if (!QueryServiceConfig(hSc,
|
||||
pServiceConfig,
|
||||
BytesNeeded,
|
||||
&BytesNeeded))
|
||||
if (QueryServiceConfig(hSc,
|
||||
pServiceConfig,
|
||||
BytesNeeded,
|
||||
&BytesNeeded))
|
||||
{
|
||||
HeapFree(ProcessHeap,
|
||||
0,
|
||||
pServiceConfig);
|
||||
goto cleanup;
|
||||
lpExePath = HeapAlloc(ProcessHeap,
|
||||
0,
|
||||
(_tcslen(pServiceConfig->lpBinaryPathName) +1 ) * sizeof(TCHAR));
|
||||
|
||||
_tcscpy(lpExePath, pServiceConfig->lpBinaryPathName);
|
||||
}
|
||||
}
|
||||
else /* exit on failure */
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
*ExePath = pServiceConfig->lpBinaryPathName;
|
||||
|
||||
CloseServiceHandle(hSCManager);
|
||||
CloseServiceHandle(hSc);
|
||||
|
||||
return TRUE;
|
||||
|
||||
cleanup:
|
||||
if (pServiceConfig)
|
||||
HeapFree(ProcessHeap,
|
||||
0,
|
||||
pServiceConfig);
|
||||
if (hSCManager != NULL)
|
||||
CloseServiceHandle(hSCManager);
|
||||
if (hSc != NULL)
|
||||
CloseServiceHandle(hSc);
|
||||
return FALSE;
|
||||
|
||||
return lpExePath;
|
||||
}
|
||||
|
||||
|
||||
static VOID
|
||||
InitListViewImage(PMAIN_WND_INFO Info)
|
||||
{
|
||||
HICON hSmIconItem, hLgIconItem; /* icon for list-view items */
|
||||
HIMAGELIST hSmall, hLarge; /* image list for other views */
|
||||
|
||||
|
||||
/* Create the icon image lists */
|
||||
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
|
||||
GetSystemMetrics(SM_CYSMICON),
|
||||
ILC_MASK | ILC_COLOR32,
|
||||
1,
|
||||
1);
|
||||
|
||||
hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
|
||||
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);
|
||||
|
||||
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(Info->hListView,
|
||||
hSmall,
|
||||
LVSIL_SMALL);
|
||||
(void)ListView_SetImageList(Info->hListView,
|
||||
hLarge,
|
||||
LVSIL_NORMAL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOL
|
||||
RefreshServiceList(PMAIN_WND_INFO Info)
|
||||
{
|
||||
|
@ -270,8 +111,6 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
|||
|
||||
(void)ListView_DeleteAllItems(Info->hListView);
|
||||
|
||||
InitListViewImage(Info);
|
||||
|
||||
NumServices = GetServiceList(Info);
|
||||
|
||||
if (NumServices)
|
||||
|
@ -282,7 +121,7 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
|||
for (Index = 0; Index < NumServices; Index++)
|
||||
{
|
||||
HKEY hKey = NULL;
|
||||
LPTSTR Description = NULL;
|
||||
LPTSTR lpDescription = NULL;
|
||||
LPTSTR LogOnAs = NULL;
|
||||
DWORD StartUp = 0;
|
||||
DWORD dwValueSize;
|
||||
|
@ -313,12 +152,10 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
|||
lvItem.iItem = ListView_GetItemCount(Info->hListView);
|
||||
lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
|
||||
|
||||
|
||||
|
||||
/* set the description */
|
||||
if (GetDescription(Info->pServiceStatus[Index].lpServiceName, &Description))
|
||||
if (lpDescription = GetDescription(Info->pServiceStatus[Index].lpServiceName))
|
||||
{
|
||||
lvItem.pszText = Description;
|
||||
lvItem.pszText = lpDescription;
|
||||
lvItem.iSubItem = 1;
|
||||
SendMessage(Info->hListView,
|
||||
LVM_SETITEMTEXT,
|
||||
|
@ -327,10 +164,9 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
|||
|
||||
HeapFree(ProcessHeap,
|
||||
0,
|
||||
Description);
|
||||
lpDescription);
|
||||
}
|
||||
|
||||
|
||||
/* set the status */
|
||||
if (Info->pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
|
||||
{
|
||||
|
@ -346,8 +182,6 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
|||
(LPARAM)&lvItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* set the startup type */
|
||||
dwValueSize = sizeof(DWORD);
|
||||
if (RegQueryValueEx(hKey,
|
||||
|
@ -401,8 +235,6 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
|||
(LPARAM)&lvItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* set Log On As */
|
||||
dwValueSize = 0;
|
||||
if (RegQueryValueEx(hKey,
|
||||
|
@ -515,7 +347,7 @@ GetServiceList(PMAIN_WND_INFO Info)
|
|||
0,
|
||||
BytesNeeded);
|
||||
if (Info->pServiceStatus == NULL)
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
|
||||
/* fill array with service info */
|
||||
if (EnumServicesStatusEx(ScHandle,
|
||||
|
|
106
reactos/base/applications/mscutils/servman/reg.c
Normal file
106
reactos/base/applications/mscutils/servman/reg.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Services
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/system/servman/reg.c
|
||||
* PURPOSE: Query service information
|
||||
* COPYRIGHT: Copyright 2005 - 2007 Ged Murphy <gedmurphy@gmail.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
/* Sets the service description in the registry */
|
||||
BOOL SetDescription(LPTSTR ServiceName, LPTSTR Description)
|
||||
{
|
||||
HKEY hKey;
|
||||
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
||||
TCHAR buf[300];
|
||||
TCHAR szBuf[MAX_PATH];
|
||||
LONG val;
|
||||
|
||||
|
||||
/* open the registry key for the service */
|
||||
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, ServiceName);
|
||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
buf,
|
||||
0,
|
||||
KEY_WRITE,
|
||||
&hKey);
|
||||
|
||||
|
||||
if ((val = RegSetValueEx(hKey,
|
||||
_T("Description"),
|
||||
0,
|
||||
REG_SZ,
|
||||
(LPBYTE)Description,
|
||||
(DWORD)lstrlen(szBuf)+1)) != ERROR_SUCCESS)
|
||||
{
|
||||
//GetError(val);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
RegCloseKey(hKey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Retrives the service description from the registry */
|
||||
LPTSTR
|
||||
GetDescription(LPTSTR lpServiceName)
|
||||
{
|
||||
HKEY hKey;
|
||||
LPTSTR lpDescription = NULL;
|
||||
DWORD dwValueSize = 0;
|
||||
LONG ret;
|
||||
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
||||
TCHAR buf[300];
|
||||
|
||||
/* open the registry key for the service */
|
||||
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, lpServiceName);
|
||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
buf,
|
||||
0,
|
||||
KEY_READ,
|
||||
&hKey);
|
||||
|
||||
ret = RegQueryValueEx(hKey,
|
||||
_T("Description"),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&dwValueSize);
|
||||
if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret != ERROR_INVALID_HANDLE)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (ret != ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
lpDescription = HeapAlloc(ProcessHeap,
|
||||
HEAP_ZERO_MEMORY,
|
||||
dwValueSize);
|
||||
if (lpDescription == NULL)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(RegQueryValueEx(hKey,
|
||||
_T("Description"),
|
||||
NULL,
|
||||
NULL,
|
||||
(LPBYTE)lpDescription,
|
||||
&dwValueSize))
|
||||
{
|
||||
HeapFree(ProcessHeap,
|
||||
0,
|
||||
lpDescription);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
return lpDescription;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue