Author: gedmurphy Date: Sat Aug 25 17:41:44 2007 New Revision: 28541
URL: http://svn.reactos.org/svn/reactos?rev=28541&view=rev Log: code improvements and various bug fixes
Modified: trunk/reactos/base/applications/mscutils/servman/mainwnd.c trunk/reactos/base/applications/mscutils/servman/precomp.h trunk/reactos/base/applications/mscutils/servman/progress.c trunk/reactos/base/applications/mscutils/servman/query.c
Modified: trunk/reactos/base/applications/mscutils/servman/mainwnd.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/... ============================================================================== --- trunk/reactos/base/applications/mscutils/servman/mainwnd.c (original) +++ trunk/reactos/base/applications/mscutils/servman/mainwnd.c Sat Aug 25 17:41:44 2007 @@ -15,7 +15,7 @@
/* Toolbar buttons */ -TBBUTTON Buttons [NUM_BUTTONS] = +static const TBBUTTON 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 */ @@ -141,31 +141,19 @@ { HMENU hMainMenu; DWORD Flags, State; + UINT i;
/* 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)); + for (i = ID_START; i <= ID_RESTART; i++) + { + EnableMenuItem(hMainMenu, i, MF_GRAYED); + EnableMenuItem(Info->hShortcutMenu, ID_START, MF_GRAYED); + SendMessage(Info->hTool, TB_SETSTATE, i, + (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0)); + }
if (Info->SelectedItem != NO_ITEM_SELECTED) { @@ -249,7 +237,7 @@ static BOOL pCreateToolbar(PMAIN_WND_INFO Info) { - INT NumButtons = sizeof(Buttons) / sizeof(Buttons[0]); + INT numButtons = sizeof(Buttons) / sizeof(Buttons[0]);
Info->hTool = CreateWindowEx(0, TOOLBARCLASSNAME, @@ -288,7 +276,7 @@
SendMessage(Info->hTool, TB_ADDBUTTONS, - NumButtons, + numButtons, (LPARAM)Buttons);
return TRUE; @@ -346,7 +334,6 @@ (void)ListView_SetImageList(Info->hListView, hLarge, LVSIL_NORMAL); - }
@@ -472,7 +459,6 @@ if(Info->hStatus == NULL) return FALSE;
- SendMessage(Info->hStatus, SB_SETPARTS, sizeof(StatWidths) / sizeof(INT), @@ -485,7 +471,6 @@ ListViewSelectionChanged(PMAIN_WND_INFO Info, LPNMLISTVIEW pnmv) { - HMENU hMainMenu;
/* get handle to menu */ @@ -543,16 +528,19 @@ }
-static VOID +static BOOL InitMainWnd(PMAIN_WND_INFO Info) { if (!pCreateToolbar(Info)) + { DisplayString(_T("error creating toolbar")); + return FALSE; + }
if (!CreateListView(Info)) { DisplayString(_T("error creating list view")); - return; + return FALSE; }
if (!CreateStatusBar(Info)) @@ -563,6 +551,8 @@ MAKEINTRESOURCE(IDR_POPUP)); Info->hShortcutMenu = GetSubMenu(Info->hShortcutMenu, 0); + + return TRUE; }
@@ -820,7 +810,8 @@ GWLP_USERDATA, (LONG_PTR)Info);
- InitMainWnd(Info); + if (!InitMainWnd(Info)) + return -1;
/* Show the window */ ShowWindow(hwnd, @@ -1007,10 +998,9 @@
case WM_CLOSE: { - /* Free service array */ HeapFree(ProcessHeap, 0, - Info->pServiceStatus); + Info->pAllServices);
DestroyMenu(Info->hShortcutMenu); DestroyWindow(hwnd); @@ -1019,8 +1009,6 @@
case WM_DESTROY: { - //DestroyMainWnd(Info); - HeapFree(ProcessHeap, 0, Info); @@ -1028,7 +1016,6 @@ GWLP_USERDATA, 0);
- /* Break the message queue loop */ PostQuitMessage(0); } break; @@ -1044,6 +1031,7 @@ } break; } + return Ret; }
@@ -1122,4 +1110,3 @@ UnregisterClass(szMainWndClass, hInstance); } -
Modified: trunk/reactos/base/applications/mscutils/servman/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/... ============================================================================== --- trunk/reactos/base/applications/mscutils/servman/precomp.h (original) +++ trunk/reactos/base/applications/mscutils/servman/precomp.h Sat Aug 25 17:41:44 2007 @@ -15,9 +15,6 @@
#define NO_ITEM_SELECTED -1 #define MAX_KEY_LENGTH 256 -#define NUM_BUTTONS 11 -#define PROGRESSRANGE 8 -
typedef struct _MAIN_WND_INFO { @@ -28,7 +25,7 @@ HMENU hShortcutMenu; int nCmdShow;
- ENUM_SERVICE_STATUS_PROCESS *pServiceStatus; /* Stores the complete services array */ + ENUM_SERVICE_STATUS_PROCESS *pAllServices; ENUM_SERVICE_STATUS_PROCESS *CurrentService; /* Stores the current selected service */
INT SelectedItem;/* selection number in the list view */ @@ -79,7 +76,7 @@ LPTSTR GetDescription(LPTSTR); LPTSTR GetExecutablePath(PMAIN_WND_INFO Info); BOOL RefreshServiceList(PMAIN_WND_INFO Info); -DWORD GetServiceList(PMAIN_WND_INFO Info); +//DWORD GetServiceList(PMAIN_WND_INFO Info);
/* propsheet.c */ LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info); @@ -91,35 +88,27 @@ 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 */
Modified: trunk/reactos/base/applications/mscutils/servman/progress.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/... ============================================================================== --- trunk/reactos/base/applications/mscutils/servman/progress.c (original) +++ trunk/reactos/base/applications/mscutils/servman/progress.c Sat Aug 25 17:41:44 2007 @@ -8,6 +8,8 @@ */
#include "precomp.h" + +#define PROGRESSRANGE 8
VOID CompleteProgressBar(HWND hProgDlg)
Modified: trunk/reactos/base/applications/mscutils/servman/query.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils/... ============================================================================== --- trunk/reactos/base/applications/mscutils/servman/query.c (original) +++ trunk/reactos/base/applications/mscutils/servman/query.c Sat Aug 25 17:41:44 2007 @@ -25,7 +25,6 @@ /* return pointer to selected service */ return (ENUM_SERVICE_STATUS_PROCESS *)lvItem.lParam; } -
/* get vendor of service binary */ @@ -99,21 +98,90 @@ }
+static BOOL +GetServiceList(PMAIN_WND_INFO Info, + DWORD *NumServices) +{ + SC_HANDLE ScHandle; + BOOL bRet = FALSE; + + DWORD BytesNeeded = 0; + DWORD ResumeHandle = 0; + + *NumServices = 0; + + ScHandle = OpenSCManager(NULL, + NULL, + SC_MANAGER_ENUMERATE_SERVICE); + if (ScHandle != INVALID_HANDLE_VALUE) + { + if (!EnumServicesStatusEx(ScHandle, + SC_ENUM_PROCESS_INFO, + SERVICE_WIN32, + SERVICE_STATE_ALL, + NULL, + 0, + &BytesNeeded, + NumServices, + &ResumeHandle, + 0)) + { + /* Call function again if required size was returned */ + if (GetLastError() == ERROR_MORE_DATA) + { + /* reserve memory for service info array */ + Info->pAllServices = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(ProcessHeap, + 0, + BytesNeeded); + if (Info->pAllServices) + { + /* fill array with service info */ + if (EnumServicesStatusEx(ScHandle, + SC_ENUM_PROCESS_INFO, + SERVICE_WIN32, + SERVICE_STATE_ALL, + (LPBYTE)Info->pAllServices, + BytesNeeded, + &BytesNeeded, + NumServices, + &ResumeHandle, + 0)) + { + bRet = TRUE; + } + } + } + } + } + + if (ScHandle) + CloseServiceHandle(ScHandle); + + if (!bRet) + { + HeapFree(ProcessHeap, + 0, + Info->pAllServices); + } + + return bRet; +} + + BOOL RefreshServiceList(PMAIN_WND_INFO Info) { + ENUM_SERVICE_STATUS_PROCESS *pService; LVITEM lvItem; TCHAR szNumServices[32]; TCHAR szStatus[64]; - DWORD NumServices = 0; + DWORD NumServices; DWORD Index; LPCTSTR Path = _T("System\CurrentControlSet\Services\%s");
(void)ListView_DeleteAllItems(Info->hListView);
- NumServices = GetServiceList(Info); - - if (NumServices) + if (GetServiceList(Info, &NumServices)) { TCHAR buf[300]; /* buffer to hold key path */ INT NumListedServ = 0; /* how many services were listed */ @@ -122,38 +190,43 @@ { HKEY hKey = NULL; LPTSTR lpDescription = NULL; - LPTSTR LogOnAs = NULL; + LPTSTR lpLogOnAs = NULL; DWORD StartUp = 0; DWORD dwValueSize; + + /* copy the service info over */ + pService = &Info->pAllServices[Index];
/* open the registry key for the service */ _sntprintf(buf, 300, Path, - Info->pServiceStatus[Index].lpServiceName); - - RegOpenKeyEx(HKEY_LOCAL_MACHINE, - buf, + pService->lpServiceName); + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, + buf, + 0, + KEY_READ, + &hKey) != ERROR_SUCCESS) + { + HeapFree(ProcessHeap, 0, - KEY_READ, - &hKey); - + pService); + continue; + }
/* set the display name */ 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 */ - lvItem.lParam = (LPARAM)&Info->pServiceStatus[Index]; - - lvItem.iItem = ListView_GetItemCount(Info->hListView); + lvItem.pszText = pService->lpDisplayName; + + /* Add the service pointer */ + lvItem.lParam = (LPARAM)pService; + + /* add it to the listview */ lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
/* set the description */ - if ((lpDescription = GetDescription(Info->pServiceStatus[Index].lpServiceName))) + if ((lpDescription = GetDescription(pService->lpServiceName))) { lvItem.pszText = lpDescription; lvItem.iSubItem = 1; @@ -168,7 +241,7 @@ }
/* set the status */ - if (Info->pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING) + if (pService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING) { LoadString(hInstance, IDS_SERVICES_STARTED, @@ -189,18 +262,34 @@ NULL, NULL, (LPBYTE)&StartUp, - &dwValueSize)) - { - RegCloseKey(hKey); - continue; - } - - if (StartUp == 0x02) - { - LoadString(hInstance, - IDS_SERVICES_AUTO, - szStatus, - sizeof(szStatus) / sizeof(TCHAR)); + &dwValueSize) == ERROR_SUCCESS) + { + switch (StartUp) + { + case 2: + LoadStringW(hInstance, + IDS_SERVICES_AUTO, + szStatus, + sizeof(szStatus) / sizeof(TCHAR)); + break; + case 3: + LoadStringW(hInstance, + IDS_SERVICES_MAN, + szStatus, + sizeof(szStatus) / sizeof(TCHAR)); + break; + + case 4: + LoadStringW(hInstance, + IDS_SERVICES_DIS, + szStatus, + sizeof(szStatus) / sizeof(TCHAR)); + break; + default: + szStatus[0] = 0; + break; + } + lvItem.pszText = szStatus; lvItem.iSubItem = 3; SendMessage(Info->hListView, @@ -208,32 +297,6 @@ lvItem.iItem, (LPARAM)&lvItem); } - else if (StartUp == 0x03) - { - 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)); - lvItem.pszText = szStatus; - lvItem.iSubItem = 3; - SendMessage(Info->hListView, - LVM_SETITEMTEXT, - lvItem.iItem, - (LPARAM)&lvItem); - }
/* set Log On As */ dwValueSize = 0; @@ -242,52 +305,39 @@ NULL, NULL, NULL, - &dwValueSize)) - { + &dwValueSize) == ERROR_SUCCESS) + { + lpLogOnAs = HeapAlloc(ProcessHeap, + 0, + dwValueSize); + if (lpLogOnAs != NULL) + { + if(RegQueryValueEx(hKey, + _T("ObjectName"), + NULL, + NULL, + (LPBYTE)lpLogOnAs, + &dwValueSize) == ERROR_SUCCESS) + { + lvItem.pszText = lpLogOnAs; + lvItem.iSubItem = 4; + SendMessage(Info->hListView, + LVM_SETITEMTEXT, + lvItem.iItem, + (LPARAM)&lvItem); + } + + HeapFree(ProcessHeap, + 0, + lpLogOnAs); + } + RegCloseKey(hKey); - continue; - } - - LogOnAs = HeapAlloc(ProcessHeap, - HEAP_ZERO_MEMORY, - dwValueSize); - if (LogOnAs == NULL) - { - RegCloseKey(hKey); - return FALSE; - } - if(RegQueryValueEx(hKey, - _T("ObjectName"), - NULL, - NULL, - (LPBYTE)LogOnAs, - &dwValueSize)) - { - HeapFree(ProcessHeap, - 0, - LogOnAs); - RegCloseKey(hKey); - continue; - } - - lvItem.pszText = LogOnAs; - lvItem.iSubItem = 4; - SendMessage(Info->hListView, - LVM_SETITEMTEXT, - lvItem.iItem, - (LPARAM)&lvItem); - - HeapFree(ProcessHeap, - 0, - LogOnAs); - - RegCloseKey(hKey); - + } }
+ /* set the number of listed services in the status bar */ NumListedServ = ListView_GetItemCount(Info->hListView); - - /* set the number of listed services in the status bar */ LoadString(hInstance, IDS_NUM_SERVICES, szNumServices, @@ -308,78 +358,7 @@ SendMessage (Info->hListView, WM_SETREDRAW, TRUE, - 0) ; + 0);
return TRUE; } - - - - -DWORD -GetServiceList(PMAIN_WND_INFO Info) -{ - SC_HANDLE ScHandle; - BOOL bGotServices = FALSE; - - DWORD BytesNeeded = 0; - DWORD ResumeHandle = 0; - DWORD NumServices = 0; - - ScHandle = OpenSCManager(NULL, - NULL, - SC_MANAGER_ENUMERATE_SERVICE); - if (ScHandle != INVALID_HANDLE_VALUE) - { - if (!EnumServicesStatusEx(ScHandle, - SC_ENUM_PROCESS_INFO, - SERVICE_WIN32, - SERVICE_STATE_ALL, - (LPBYTE)Info->pServiceStatus, - 0, - &BytesNeeded, - &NumServices, - &ResumeHandle, - 0)) - { - /* Call function again if required size was returned */ - if (GetLastError() == ERROR_MORE_DATA) - { - /* reserve memory for service info array */ - Info->pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *) - HeapAlloc(ProcessHeap, - 0, - BytesNeeded); - if (Info->pServiceStatus == NULL) - return FALSE; - - /* fill array with service info */ - if (EnumServicesStatusEx(ScHandle, - SC_ENUM_PROCESS_INFO, - SERVICE_WIN32, - SERVICE_STATE_ALL, - (LPBYTE)Info->pServiceStatus, - BytesNeeded, - &BytesNeeded, - &NumServices, - &ResumeHandle, - 0)) - { - bGotServices = TRUE; - } - } - } - } - - if (ScHandle) - CloseServiceHandle(ScHandle); - - if (!bGotServices) - { - HeapFree(ProcessHeap, - 0, - Info->pServiceStatus); - } - - return NumServices; -}