- Added a progress bar showing the status of the action on the service
- Better control over stopping, pausing and resuming
- Get pointer to services via separate function
Modified: trunk/reactos/subsys/system/servman/En.rc
Modified: trunk/reactos/subsys/system/servman/about.c
Modified: trunk/reactos/subsys/system/servman/control.c
Added: trunk/reactos/subsys/system/servman/progress.c
Modified: trunk/reactos/subsys/system/servman/propsheet.c
Modified: trunk/reactos/subsys/system/servman/query.c
Modified: trunk/reactos/subsys/system/servman/res/system.ico
Modified: trunk/reactos/subsys/system/servman/servman.c
Modified: trunk/reactos/subsys/system/servman/servman.h
Modified: trunk/reactos/subsys/system/servman/servman.xml
Modified: trunk/reactos/subsys/system/servman/start.c

Modified: trunk/reactos/subsys/system/servman/En.rc
--- trunk/reactos/subsys/system/servman/En.rc	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/En.rc	2006-01-22 22:33:22 UTC (rev 20985)
@@ -60,7 +60,7 @@
 BEGIN
   LTEXT "Service Manager v0.1\nCopyright (C) 2006\nby Ged Murphy (gedmurphy@gmail.com)", IDC_STATIC, 48, 7, 130, 26
   PUSHBUTTON "Close", IDOK, 75, 162, 44, 15
-  CONTROL "",IDI_SM_ICON,"Static",0x50000203,0,12,7,30
+  ICON IDI_SM_ICON, IDC_STATIC, 10, 10, 7, 30
   EDITTEXT IDC_LICENSE_EDIT, 8, 44, 174, 107, WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | ES_READONLY | ES_MULTILINE
 END
 
@@ -125,7 +125,8 @@
 IDD_DLG_PROGRESS DIALOGEX 6,6,255,89
 CAPTION "Service Control"
 FONT 8,"MS Sans Serif",0,0
-STYLE WS_BORDER | WS_VISIBLE | WS_DLGFRAME | WS_SYSMENU | WS_THICKFRAME | WS_GROUP | WS_TABSTOP
+STYLE WS_BORDER | WS_DLGFRAME | WS_SYSMENU | DS_MODALFRAME
+EXSTYLE WS_EX_TOOLWINDOW
 BEGIN
   CONTROL "",IDC_SERVCON_PROGRESS,"msctls_progress32",0x50000000,8,46,238,13
   CONTROL "",IDC_SERVCON_INFO,"Static",0x50000000,8,5,236,11
@@ -177,5 +178,5 @@
 
 STRINGTABLE DISCARDABLE
 BEGIN
-  IDS_PROGRESS_INFO "ReactOS is attempting to %s the following service on %s"
+  IDS_PROGRESS_INFO "ReactOS is attempting to %s the following service"
 END

Modified: trunk/reactos/subsys/system/servman/about.c
--- trunk/reactos/subsys/system/servman/about.c	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/about.c	2006-01-22 22:33:22 UTC (rev 20985)
@@ -50,5 +50,5 @@
         break;
     }
 
-    return 0;
+    return FALSE;
 }

Modified: trunk/reactos/subsys/system/servman/control.c
--- trunk/reactos/subsys/system/servman/control.c	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/control.c	2006-01-22 22:33:22 UTC (rev 20985)
@@ -12,13 +12,17 @@
 extern HWND hListView;
 
 
-BOOL Control(DWORD Control)
+BOOL Control(HWND hProgDlg, DWORD Control)
 {
+    HWND hProgBar;
     SC_HANDLE hSCManager;
     SC_HANDLE hSc;
     ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
+    SERVICE_STATUS_PROCESS ServiceStatus;
     SERVICE_STATUS Status;
     LVITEM item;
+    DWORD BytesNeeded = 0;
+    DWORD Loop = 5; //FIXME: testing value. needs better control
 
     item.mask = LVIF_PARAM;
     item.iItem = GetSelectedItem();
@@ -27,6 +31,11 @@
     /* copy pointer to selected service */
     Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
 
+    /* set the progress bar range and step */
+    hProgBar = GetDlgItem(hProgDlg, IDC_SERVCON_PROGRESS);
+    SendMessage(hProgBar, PBM_SETRANGE, 0, MAKELPARAM(0, Loop));
+    SendMessage(hProgBar, PBM_SETSTEP, (WPARAM)1, 0);
+
     /* open handle to the SCM */
     hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
     if (hSCManager == NULL)
@@ -37,7 +46,7 @@
 
     /* open handle to the service */
     hSc = OpenService(hSCManager, Service->lpServiceName,
-                      SERVICE_PAUSE_CONTINUE | SERVICE_STOP);
+                      SC_MANAGER_ALL_ACCESS);
     if (hSc == NULL)
     {
         GetError(0);
@@ -52,8 +61,50 @@
         return FALSE;
     }
 
+    /* query the state of the service */
+    if (! QueryServiceStatusEx(hSc,
+                               SC_STATUS_PROCESS_INFO,
+                               (LPBYTE)&ServiceStatus,
+                               sizeof(SERVICE_STATUS_PROCESS),
+                               &BytesNeeded))
+    {
+        GetError(0);
+        return FALSE;
+    }
+
+    /* loop whilst service is not running */
+    /* FIXME: needs more control adding. 'Loop' is temparary */
+    while (ServiceStatus.dwCurrentState != Control || !Loop)
+    {
+        /* increment the progress bar */
+        SendMessage(hProgBar, PBM_STEPIT, 0, 0);
+
+        /* wait before checking status */
+        Sleep(ServiceStatus.dwWaitHint / 8);
+
+        /* check status again */
+        if (! QueryServiceStatusEx(
+                hSc,
+                SC_STATUS_PROCESS_INFO,
+                (LPBYTE)&ServiceStatus,
+                sizeof(SERVICE_STATUS_PROCESS),
+                &BytesNeeded))
+        {
+            GetError(0);
+            return FALSE;
+        }
+        Loop--;
+    }
+
     CloseServiceHandle(hSc);
 
-    return TRUE;
+    if (ServiceStatus.dwCurrentState == Control)
+    {
+        SendMessage(hProgBar, PBM_DELTAPOS, Loop, 0);
+        Sleep(1000);
+        return TRUE;
+    }
+    else
+        return FALSE;
 
 }

Added: trunk/reactos/subsys/system/servman/progress.c
--- trunk/reactos/subsys/system/servman/progress.c	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/progress.c	2006-01-22 22:33:22 UTC (rev 20985)
@@ -0,0 +1,45 @@
+/*
+ * PROJECT:     ReactOS Services
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        subsys/system/servman/progress.c
+ * PURPOSE:     Progress dialog box message handler
+ * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
+ *
+ */
+
+#include "servman.h"
+
+extern HINSTANCE hInstance;
+//extern HWND hMainWnd;
+
+
+BOOL CALLBACK ProgressDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
+{
+    switch(Message)
+    {
+        case WM_INITDIALOG:
+
+        break;
+
+        case WM_COMMAND:
+            switch(LOWORD(wParam))
+            {
+                case IDOK:
+                    DestroyWindow(hDlg);
+                break;
+
+            }
+        break;
+
+        case WM_DESTROY:
+            DestroyWindow(hDlg);
+        break;
+
+        default:
+            return FALSE;
+    }
+
+    return TRUE;
+
+}
+

Modified: trunk/reactos/subsys/system/servman/propsheet.c
--- trunk/reactos/subsys/system/servman/propsheet.c	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/propsheet.c	2006-01-22 22:33:22 UTC (rev 20985)
@@ -77,18 +77,13 @@
 {
     HKEY hKey;
     ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
-    LVITEM item;
     PROP_DLG_INFO DlgInfo;
     LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
     TCHAR buf[300];
 
-    item.mask = LVIF_PARAM;
-    item.iItem = GetSelectedItem();
-    SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);
+    /* get pointer to selected service */
+    Service = GetSelectedService();
 
-    /* copy pointer to selected service */
-    Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
-
     /* open the registry key for the service */
     _sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, Service->lpServiceName);
     RegOpenKeyEx(HKEY_LOCAL_MACHINE,

Modified: trunk/reactos/subsys/system/servman/query.c
--- trunk/reactos/subsys/system/servman/query.c	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/query.c	2006-01-22 22:33:22 UTC (rev 20985)
@@ -24,6 +24,24 @@
 }
 
 
+
+ENUM_SERVICE_STATUS_PROCESS* 
+GetSelectedService(VOID)
+{
+    ENUM_SERVICE_STATUS_PROCESS *pSelectedService = NULL;
+    LVITEM item;
+
+    item.mask = LVIF_PARAM;
+    item.iItem = GetSelectedItem();
+    SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);
+
+    /* copy pointer to selected service */
+    pSelectedService = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
+
+    return pSelectedService;
+}
+
+
 /* Retrives the service description from the registry */
 BOOL GetDescription(HKEY hKey, LPTSTR *retDescription)
 {

Modified: trunk/reactos/subsys/system/servman/res/system.ico
(Binary files differ)

Modified: trunk/reactos/subsys/system/servman/servman.c
--- trunk/reactos/subsys/system/servman/servman.c	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/servman.c	2006-01-22 22:33:22 UTC (rev 20985)
@@ -16,6 +16,7 @@
 HWND hListView;
 HWND hStatus;
 HWND hTool;
+HWND hProgDlg;
 HMENU hShortcutMenu;
 INT SelectedItem;
 
@@ -343,8 +344,35 @@
                 break;
 
                 case ID_START:
-                    if ( DoStartService() )
+                {
+                    ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
+                    TCHAR buf1[100];
+                    TCHAR buf2[100];
+                    /* open the progress dialog */
+                    hProgDlg = CreateDialog(GetModuleHandle(NULL), 
+                                            MAKEINTRESOURCE(IDD_DLG_PROGRESS),
+                                            hMainWnd, 
+                                            (DLGPROC)ProgressDialogProc);
+                    if (hProgDlg != NULL)
                     {
+                        ShowWindow(hProgDlg, SW_SHOW);
+
+                        /* write the  info to the progress dialog */
+                        LoadString(hInstance, IDS_PROGRESS_INFO, buf1,
+                            sizeof(buf1) / sizeof(TCHAR));
+                        _sntprintf(buf2, 100, buf1, _T("start"));
+                        SendDlgItemMessage(hProgDlg, IDC_SERVCON_INFO, WM_SETTEXT, 0, (LPARAM)buf2);
+
+                        /* get pointer to selected service */
+                        Service = GetSelectedService();
+
+                        /* write the service name to the progress dialog */
+                        SendDlgItemMessage(hProgDlg, IDC_SERVCON_NAME, WM_SETTEXT, 0, 
+                            (LPARAM)Service->lpServiceName);
+                    }
+
+                    if ( DoStartService(hProgDlg) )
+                    {
                         LVITEM item;
                         TCHAR szStatus[64];
 
@@ -355,11 +383,41 @@
                         item.iSubItem = 2;
                         SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
                     }
+
+                    SendMessage(hProgDlg, WM_DESTROY, 0, 0);
+                }
 			    break;
 
                 case ID_STOP:
-                    if( Control(SERVICE_CONTROL_STOP) )
+                {
+                    ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
+                    TCHAR buf1[100];
+                    TCHAR buf2[100];
+                    /* open the progress dialog */
+                    hProgDlg = CreateDialog(GetModuleHandle(NULL), 
+                                            MAKEINTRESOURCE(IDD_DLG_PROGRESS),
+                                            hMainWnd, 
+                                            (DLGPROC)ProgressDialogProc);
+                    if (hProgDlg != NULL)
                     {
+                        ShowWindow(hProgDlg, SW_SHOW);
+
+                        /* write the  info to the progress dialog */
+                        LoadString(hInstance, IDS_PROGRESS_INFO, buf1,
+                            sizeof(buf1) / sizeof(TCHAR));
+                        _sntprintf(buf2, 100, buf1, _T("stop"));
+                        SendDlgItemMessage(hProgDlg, IDC_SERVCON_INFO, WM_SETTEXT, 0, (LPARAM)buf2);
+
+                        /* get pointer to selected service */
+                        Service = GetSelectedService();
+
+                        /* write the service name to the progress dialog */
+                        SendDlgItemMessage(hProgDlg, IDC_SERVCON_NAME, WM_SETTEXT, 0, 
+                            (LPARAM)Service->lpServiceName);
+                    }
+
+                    if( Control(hProgDlg, SERVICE_CONTROL_STOP) )
+                    {
                         LVITEM item;
 
                         item.pszText = '\0';
@@ -367,39 +425,22 @@
                         item.iSubItem = 2;
                         SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
                     }
+
+                    SendMessage(hProgDlg, WM_DESTROY, 0, 0);
+                }
                 break;
 
                 case ID_PAUSE:
-                    Control(SERVICE_CONTROL_PAUSE);
+                    Control(hProgDlg, SERVICE_CONTROL_PAUSE);
                 break;
 
                 case ID_RESUME:
-                    Control(SERVICE_CONTROL_CONTINUE );
+                    Control(hProgDlg, SERVICE_CONTROL_CONTINUE );
                 break;
 
                 case ID_RESTART:
-                    if( Control(SERVICE_CONTROL_STOP) )
-                    {
-                        LVITEM item;
-
-                        item.pszText = '\0';
-                        item.iItem = GetSelectedItem();
-                        item.iSubItem = 2;
-                        SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
-
-                        if ( DoStartService() )
-                        {
-                            LVITEM item;
-                            TCHAR szStatus[64];
-
-                            LoadString(hInstance, IDS_SERVICES_STARTED, szStatus,
-                                sizeof(szStatus) / sizeof(TCHAR));
-                            item.pszText = szStatus;
-                            item.iItem = GetSelectedItem();
-                            item.iSubItem = 2;
-                            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
-                        }
-                    }
+                    SendMessage(hMainWnd, WM_COMMAND, 0, ID_STOP);
+                    SendMessage(hMainWnd, WM_COMMAND, 0, ID_START);
                 break;
 
                 case ID_NEW:
@@ -420,8 +461,8 @@
                 case ID_ABOUT:
                     DialogBox(hInstance,
                               MAKEINTRESOURCE(IDD_ABOUTBOX),
-                              hwnd,
-                              AboutDialogProc);
+                              hMainWnd,
+                              (DLGPROC)AboutDialogProc);
                  break;
 
 		    }
@@ -497,8 +538,11 @@
 
     while( GetMessage( &Msg, NULL, 0, 0 ) )
     {
-        TranslateMessage(&Msg);
-        DispatchMessage(&Msg);
+        if(! IsDialogMessage(hProgDlg, &Msg) )
+        {
+            TranslateMessage(&Msg);
+            DispatchMessage(&Msg);
+        }
 
     }
     return (int)Msg.wParam;

Modified: trunk/reactos/subsys/system/servman/servman.h
--- trunk/reactos/subsys/system/servman/servman.h	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/servman.h	2006-01-22 22:33:22 UTC (rev 20985)
@@ -15,12 +15,15 @@
 BOOL RefreshServiceList(VOID);
 
 BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
+BOOL CALLBACK ProgressDialogProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam);
 
-BOOL DoStartService(VOID);
-BOOL Control(DWORD Control);
+BOOL DoStartService(HWND hProgDlg);
+BOOL Control(HWND hProgBar, DWORD Control);
 
 INT GetSelectedItem(VOID);
 
+ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(VOID);
+
 VOID GetError(DWORD);
 VOID FreeMemory(VOID);
 VOID DisplayString(PTCHAR);

Modified: trunk/reactos/subsys/system/servman/servman.xml
--- trunk/reactos/subsys/system/servman/servman.xml	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/servman.xml	2006-01-22 22:33:22 UTC (rev 20985)
@@ -16,6 +16,7 @@
 		<file>about.c</file>
 		<file>control.c</file>
 		<file>geterror.c</file>
+		<file>progress.c</file>
 		<file>propsheet.c</file>
 		<file>query.c</file>
 		<file>servman.c</file>

Modified: trunk/reactos/subsys/system/servman/start.c
--- trunk/reactos/subsys/system/servman/start.c	2006-01-22 20:34:47 UTC (rev 20984)
+++ trunk/reactos/subsys/system/servman/start.c	2006-01-22 22:33:22 UTC (rev 20985)
@@ -10,17 +10,19 @@
 #include "servman.h"
 
 extern HWND hListView;
+extern HWND hMainWnd;
 
-BOOL DoStartService(VOID)
+BOOL DoStartService(HWND hProgDlg)
 {
+    HWND hProgBar;
     SC_HANDLE hSCManager;
     SC_HANDLE hSc;
     SERVICE_STATUS_PROCESS ServiceStatus;
     ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
     LVITEM item;
-    DWORD BytesNeeded;
+    DWORD BytesNeeded = 0;
     INT ArgCount = 0;
-    BOOL Loop = 10; //FIXME: testing value. needs better control
+    DWORD Loop = 5; //FIXME: testing value. needs better control
 
     item.mask = LVIF_PARAM;
     item.iItem = GetSelectedItem();
@@ -29,6 +31,11 @@
     /* copy pointer to selected service */
     Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;
 
+    /* set the progress bar range and step */
+    hProgBar = GetDlgItem(hProgDlg, IDC_SERVCON_PROGRESS);
+    SendMessage(hProgBar, PBM_SETRANGE, 0, MAKELPARAM(0, Loop));
+    SendMessage(hProgBar, PBM_SETSTEP, (WPARAM)1, 0);
+
     /* open handle to the SCM */
     hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
     if (hSCManager == NULL)
@@ -53,12 +60,11 @@
     }
 
     /* query the state of the service */
-    if (! QueryServiceStatusEx(
-            hSc,
-            SC_STATUS_PROCESS_INFO,
-            (LPBYTE)&ServiceStatus,
-            sizeof(SERVICE_STATUS_PROCESS),
-            &BytesNeeded))
+    if (! QueryServiceStatusEx(hSc,
+                               SC_STATUS_PROCESS_INFO,
+                               (LPBYTE)&ServiceStatus,
+                               sizeof(SERVICE_STATUS_PROCESS),
+                               &BytesNeeded))
     {
         GetError(0);
         return FALSE;
@@ -66,10 +72,13 @@
 
     /* loop whilst service is not running */
     /* FIXME: needs more control adding. 'Loop' is temparary */
-    while (ServiceStatus.dwCurrentState == SERVICE_START_PENDING || !Loop)
+    while (ServiceStatus.dwCurrentState != SERVICE_RUNNING || !Loop)
     {
+        /* increment the progress bar */
+        SendMessage(hProgBar, PBM_STEPIT, 0, 0);
+
         /* wait before checking status */
-        Sleep(ServiceStatus.dwWaitHint);
+        Sleep(ServiceStatus.dwWaitHint / 8);
 
         /* check status again */
         if (! QueryServiceStatusEx(
@@ -88,7 +97,11 @@
     CloseServiceHandle(hSc);
 
     if (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
+    {
+        SendMessage(hProgBar, PBM_DELTAPOS, Loop, 0);
+        Sleep(1000);
         return TRUE;
+    }
     else
         return FALSE;