- popup menu on right click
authorGed Murphy <gedmurphy@reactos.org>
Tue, 10 Jan 2006 22:39:49 +0000 (22:39 +0000)
committerGed Murphy <gedmurphy@reactos.org>
Tue, 10 Jan 2006 22:39:49 +0000 (22:39 +0000)
- fix some bugs when reading from reg
- query the active list to get num items

svn path=/trunk/; revision=20773

reactos/subsys/system/servman/En.rc
reactos/subsys/system/servman/geterror.c
reactos/subsys/system/servman/query.c
reactos/subsys/system/servman/resource.h
reactos/subsys/system/servman/servman.c
reactos/subsys/system/servman/servman.h

index da6fd91..ada7775 100644 (file)
@@ -23,10 +23,40 @@ BEGIN
   END\r
   POPUP "Help"\r
   BEGIN\r
-    MENUITEM "About",ID_HELP_ABOUT\r
+    MENUITEM "About",ID_ABOUT\r
   END\r
 END\r
 \r
+\r
+IDR_POPUP MENU\r
+BEGIN\r
+  POPUP "popup"\r
+  BEGIN  \r
+    MENUITEM "Start",ID_START\r
+    MENUITEM "Stop",ID_STOP\r
+    MENUITEM "Pause",ID_PAUSE\r
+    MENUITEM "Resume",ID_RESUME\r
+    MENUITEM "Restart",ID_RESTART\r
+    MENUITEM SEPARATOR\r
+    POPUP "All tasks"\r
+    BEGIN\r
+      MENUITEM "Start",ID_START\r
+      MENUITEM "Stop",ID_STOP\r
+      MENUITEM "Pause",ID_PAUSE\r
+      MENUITEM "Resume",ID_RESUME\r
+      MENUITEM "Restart",ID_RESTART\r
+      MENUITEM "Refresh",ID_REFRESH\r
+    END\r
+    MENUITEM SEPARATOR\r
+    MENUITEM "Refresh",ID_REFRESH\r
+    MENUITEM SEPARATOR\r
+    MENUITEM "Properties",ID_PROP, "Default"\r
+    MENUITEM SEPARATOR\r
+    MENUITEM "About",ID_HELP\r
+  END\r
+END\r
+\r
+\r
 IDD_ABOUTBOX DIALOG DISCARDABLE  22,16,190,182\r
 STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU\r
 CAPTION "About Service Manager"\r
@@ -34,7 +64,7 @@ FONT 8, "Tahoma"
 BEGIN\r
     CONTROL         "Service Manager v0.1\nCopyright (C) 2006\nby Ged Murphy (gedmurphy@gmail.com)",\r
                     IDC_STATIC,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,48,7,130,26\r
-    DEFPUSHBUTTON   "Close",IDOK,140,162,44,15,WS_GROUP\r
+    DEFPUSHBUTTON   "Close",IDOK,75,162,44,15,WS_GROUP\r
     ICON            IDI_SM_ICON,IDC_STATIC,12,7,30,20\r
     EDITTEXT        IDC_LICENSE_EDIT,8,44,174,107,ES_MULTILINE |\r
                     ES_READONLY | WS_VSCROLL\r
@@ -80,19 +110,16 @@ END
 \r
 STRINGTABLE DISCARDABLE\r
 BEGIN\r
-  IDS_SERVICES_STATUS_RUNNING "Started"\r
-  IDS_SERVICES_STATUS_STOPPED "Stopped"\r
-  IDS_SERVICES_YES            "Yes"\r
-  IDS_SERVICES_UNKNOWN        "Unknown"\r
-  IDS_SERVICES_AUTO           "Automatic"\r
-  IDS_SERVICES_MAN            "Manual"\r
-  IDS_SERVICES_DIS            "Disabled"\r
+  IDS_SERVICES_STARTED      "Started"\r
+  IDS_SERVICES_AUTO         "Automatic"\r
+  IDS_SERVICES_MAN          "Manual"\r
+  IDS_SERVICES_DIS          "Disabled"\r
 END\r
 \r
 STRINGTABLE DISCARDABLE\r
 BEGIN\r
-  IDS_SERVICES_NUM_SERVICES "Num Services: %d"\r
-  \r
+  IDS_NUM_SERVICES "Num Services: %d"\r
+\r
   IDS_LICENSE "This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.\r\n\r\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.\r\n\r\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA."\r
   /*"This program is free software; you can redistribute it "\r
               "and/or modify it under the terms of the GNU Lesser General "\r
@@ -106,7 +133,7 @@ BEGIN
               "General Public License along with this program; if not, write "\r
               "to the Free Software Foundation, Inc., 59 Temple Place - Suite "\r
               "330, Boston, MA  02111-1307, USA." */\r
-  \r
+\r
 END\r
 \r
 STRINGTABLE DISCARDABLE\r
index 5786eab..55f395c 100644 (file)
@@ -2,15 +2,18 @@
 #include "servman.h"\r
 /* temp file for debugging */\r
 \r
-VOID GetError(VOID)\r
+VOID GetError(DWORD err)\r
 {\r
     LPVOID lpMsgBuf;\r
 \r
+    if (err == 0)\r
+        err = GetLastError();\r
+\r
     FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r
                   FORMAT_MESSAGE_FROM_SYSTEM |\r
                   FORMAT_MESSAGE_IGNORE_INSERTS,\r
                   NULL,\r
-                  GetLastError(),\r
+                  err,\r
                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */\r
                   (LPTSTR) &lpMsgBuf,\r
                    0,\r
index 523b223..1c262c4 100644 (file)
@@ -4,7 +4,7 @@
  * FILE:        subsys/system/servman/query.c\r
  * PURPOSE:     Query service information\r
  * COPYRIGHT:   Copyright 2005 Ged Murphy <gedmurphy@gmail.com>\r
- *               \r
+ *\r
  */\r
 \r
 #include "servman.h"\r
@@ -23,6 +23,29 @@ VOID FreeMemory(VOID)
     HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
 }\r
 \r
+VOID GetData(VOID)\r
+{\r
+    LVITEM item;\r
+    UINT sel;\r
+    TCHAR buf[200];\r
+\r
+    sel = ListView_GetHotItem(hListView);\r
+\r
+    ZeroMemory(&item, sizeof(LV_ITEM));\r
+\r
+    item.mask = LVIF_TEXT;\r
+    item.iItem = sel;\r
+    item.iSubItem = 0;\r
+    item.pszText = buf;\r
+    item.cchTextMax = 200;\r
+\r
+    ListView_GetItem(hListView, &item);\r
+\r
+\r
+    //DisplayString(sel);\r
+    DisplayString(item.pszText);\r
+}\r
+\r
 \r
 BOOL\r
 RefreshServiceList(VOID)\r
@@ -40,9 +63,10 @@ RefreshServiceList(VOID)
 \r
     if (NumServices)\r
     {\r
-        HICON hiconItem;     /* icon for list-view items */\r
-        HIMAGELIST hSmall;   /* image list for other views */\r
-        TCHAR buf[300];\r
+        HICON hiconItem;    /* icon for list-view items */\r
+        HIMAGELIST hSmall;  /* image list for other views */\r
+        TCHAR buf[300];     /* buffer to hold key path */\r
+        INT NumListedServ = 0; /* how many services were listed */\r
 \r
         /* Create the icon image lists */\r
         hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),\r
@@ -52,13 +76,9 @@ RefreshServiceList(VOID)
         hiconItem = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);\r
         ImageList_AddIcon(hSmall, hiconItem);\r
 \r
+        /* assign the image to the list view */\r
         ListView_SetImageList(hListView, hSmall, LVSIL_SMALL);\r
 \r
-        /* set the number of services in the status bar */\r
-        LoadString(hInstance, IDS_SERVICES_NUM_SERVICES, szNumServices, 32);\r
-        _sntprintf(buf, 300, szNumServices, NumServices);\r
-        SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
-\r
 \r
         for (Index = 0; Index < NumServices; Index++)\r
         {\r
@@ -73,15 +93,11 @@ RefreshServiceList(VOID)
             _sntprintf(buf, 300, Path,\r
                       pServiceStatus[Index].lpServiceName);\r
 \r
-            if( RegOpenKeyEx(HKEY_LOCAL_MACHINE,\r
-                             buf,\r
-                             0,\r
-                             KEY_READ,\r
-                             &hKey) != ERROR_SUCCESS)\r
-            {\r
-                GetError();\r
-                return FALSE;\r
-            }\r
+            RegOpenKeyEx(HKEY_LOCAL_MACHINE,\r
+                         buf,\r
+                         0,\r
+                         KEY_READ,\r
+                         &hKey);\r
 \r
 \r
             /* set the display name */\r
@@ -92,7 +108,7 @@ RefreshServiceList(VOID)
             item.iItem = ListView_GetItemCount(hListView);\r
             item.iItem = ListView_InsertItem(hListView, &item);\r
 \r
-            \r
+\r
 \r
             /* set the description */\r
             dwValueSize = 0;\r
@@ -102,12 +118,12 @@ RefreshServiceList(VOID)
                                 NULL,\r
                                 NULL,\r
                                 &dwValueSize);\r
-            if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND)\r
+            if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret != ERROR_INVALID_HANDLE)\r
             {\r
                 RegCloseKey(hKey);\r
-                return FALSE;\r
+                continue;\r
             }\r
-            \r
+\r
             if (ret != ERROR_FILE_NOT_FOUND)\r
             {\r
                 Description = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);\r
@@ -125,7 +141,7 @@ RefreshServiceList(VOID)
                 {\r
                     HeapFree(GetProcessHeap(), 0, Description);\r
                     RegCloseKey(hKey);\r
-                    return FALSE;\r
+                    continue;\r
                 }\r
 \r
                 item.pszText = Description;\r
@@ -134,29 +150,20 @@ RefreshServiceList(VOID)
 \r
                 HeapFree(GetProcessHeap(), 0, Description);\r
             }\r
-            else\r
-            {\r
-                item.pszText = '\0';\r
-                item.iSubItem = 1;\r
-                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-            }            \r
+\r
 \r
 \r
             /* set the status */\r
 \r
             if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)\r
             {\r
-                LoadString(hInstance, IDS_SERVICES_STATUS_RUNNING, szStatus, 128);\r
+                LoadString(hInstance, IDS_SERVICES_STARTED, szStatus, 128);\r
                 item.pszText = szStatus;\r
                 item.iSubItem = 2;\r
                 SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
             }\r
-            else\r
-            {\r
-                item.pszText = '\0';\r
-                item.iSubItem = 2;\r
-                SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-            }\r
+\r
+\r
 \r
             /* set the startup type */\r
 \r
@@ -169,7 +176,7 @@ RefreshServiceList(VOID)
                                 &dwValueSize))\r
             {\r
                 RegCloseKey(hKey);\r
-                return FALSE;\r
+                continue;\r
             }\r
 \r
             if (StartUp == 0x02)\r
@@ -207,9 +214,9 @@ RefreshServiceList(VOID)
                                 &dwValueSize))\r
             {\r
                 RegCloseKey(hKey);\r
-                return FALSE;\r
+                continue;\r
             }\r
-            \r
+\r
             LogOnAs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);\r
             if (LogOnAs == NULL)\r
             {\r
@@ -225,7 +232,7 @@ RefreshServiceList(VOID)
             {\r
                 HeapFree(GetProcessHeap(), 0, LogOnAs);\r
                 RegCloseKey(hKey);\r
-                return FALSE;\r
+                continue;\r
             }\r
 \r
             item.pszText = LogOnAs;\r
@@ -237,7 +244,14 @@ RefreshServiceList(VOID)
             RegCloseKey(hKey);\r
 \r
         }\r
-    } \r
+\r
+        NumListedServ = ListView_GetItemCount(hListView);\r
+\r
+        /* set the number of listed services in the status bar */\r
+        LoadString(hInstance, IDS_NUM_SERVICES, szNumServices, 32);\r
+        _sntprintf(buf, 300, szNumServices, NumListedServ);\r
+        SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
+    }\r
 \r
     return TRUE;\r
 }\r
index 71b3e9a..8774a45 100644 (file)
@@ -22,8 +22,9 @@
 #define ID_EXIT             2010\r
 \r
 #define IDR_MAINMENU        102\r
+#define IDR_POPUP           103\r
 #define ID_VIEW_CUSTOMIZE   4021\r
-#define ID_HELP_ABOUT       4031\r
+#define ID_ABOUT            4031\r
 \r
 #define IDS_FIRSTCOLUMN     1\r
 #define IDS_SECONDCOLUMN    2\r
 #define IDS_TOOLTIP_HELP    6008\r
 #define IDS_TOOLTIP_EXIT    6009\r
 \r
-#define IDS_SERVICES_STATUS_RUNNING 5000\r
-#define IDS_SERVICES_STATUS_STOPPED 5001\r
-#define IDS_SERVICES_YES    5002\r
-#define IDS_SERVICES_UNKNOWN 5003\r
-#define IDS_SERVICES_AUTO   5004\r
-#define IDS_SERVICES_MAN    5005\r
-#define IDS_SERVICES_DIS    5006\r
-#define IDS_SERVICES_NUM_SERVICES 5010\r
+#define IDS_SERVICES_STARTED 5000\r
+#define IDS_SERVICES_AUTO    5004\r
+#define IDS_SERVICES_MAN     5005\r
+#define IDS_SERVICES_DIS     5006\r
+#define IDS_NUM_SERVICES     5010\r
 \r
 #define IDI_SM_ICON         50\r
 #define IDB_BUTTONS         51\r
index 1e774bc..17503ed 100644 (file)
@@ -4,7 +4,7 @@
  * FILE:        subsys/system/servman/servman.c\r
  * PURPOSE:     Main window message handler\r
  * COPYRIGHT:   Copyright 2005 Ged Murphy <gedmurphy@gmail.com>\r
- *               \r
+ *\r
  */\r
 \r
 #include "servman.h"\r
@@ -16,6 +16,7 @@ HWND hMainWnd;
 HWND hListView;\r
 HWND hStatus;\r
 HWND hTool;\r
+HMENU hShortcutMenu;\r
 \r
 \r
 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
@@ -33,7 +34,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             LVCOLUMN lvc = { 0 };\r
 \r
             /* Toolbar buttons */\r
-            TBBUTTON tbb [NUM_BUTTONS] = \r
+            TBBUTTON tbb [NUM_BUTTONS] =\r
             {   /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */\r
                 {TBICON_PROP,    ID_PROP,    TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},    /* properties */\r
                 {TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},    /* refresh */\r
@@ -42,9 +43,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 /* Note: First item for a seperator is its width in pixels */\r
                 {25, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                             /* separator */\r
 \r
-                {TBICON_START,   ID_START,   TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* start */ \r
+                {TBICON_START,   ID_START,   TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* start */\r
                 {TBICON_STOP,    ID_STOP,    TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* stop */\r
-                {TBICON_PAUSE,   ID_PAUSE,   TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* pause */   \r
+                {TBICON_PAUSE,   ID_PAUSE,   TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* pause */\r
                 {TBICON_RESTART, ID_RESTART, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* restart */\r
 \r
                 {25, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                             /* separator */\r
@@ -105,7 +106,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 \r
             hListView = CreateWindow(WC_LISTVIEW,\r
                                      NULL,\r
-                                     WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER | \r
+                                     WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER |\r
                                      LVS_EDITLABELS | LVS_SORTASCENDING,\r
                                      0, 0, 0, 0, /* sized via WM_SIZE */\r
                                      hwnd,\r
@@ -178,10 +179,17 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                    SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);\r
 \r
 \r
+/* ======================== Create Popup Menu ============================== */\r
+\r
+            hShortcutMenu = LoadMenu(hInstance, MAKEINTRESOURCE (IDR_POPUP));\r
+            hShortcutMenu = GetSubMenu(hShortcutMenu, 0);\r
+\r
+\r
+\r
+\r
 /* ================= populate the list view with all services =================== */\r
 \r
-                   if (! RefreshServiceList() )\r
-                GetError();\r
+                   RefreshServiceList();\r
 \r
            }\r
            break;\r
@@ -224,16 +232,26 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
            case WM_NOTIFY:\r
         {\r
             LPNMITEMACTIVATE item;\r
+            \r
 \r
             switch (((LPNMHDR) lParam)->code)\r
             {\r
+                case NM_RCLICK:\r
+                {\r
+                    //item = (LPNMITEMACTIVATE) lParam;\r
+                    //lpnmh = (LPNMHDR) lParam;\r
+                    POINT pt;\r
 \r
-                   case NM_DBLCLK:\r
-                           item = (LPNMITEMACTIVATE) lParam;\r
-                           PropSheets(hwnd);\r
+                    GetCursorPos(&pt);\r
+                    TrackPopupMenuEx(hShortcutMenu, TPM_RIGHTBUTTON, pt.x, pt.y, hwnd, NULL);\r
+                }\r
+                break;\r
 \r
+                   case NM_DBLCLK:\r
+                    item = (LPNMITEMACTIVATE) lParam;\r
+                    PropSheets(hwnd);\r
                            break;\r
-            \r
+\r
                 case TTN_GETDISPINFO:\r
                 {\r
                     LPTOOLTIPTEXT lpttt;\r
@@ -274,7 +292,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                         case ID_RESTART:\r
                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);\r
                         break;\r
-                        \r
+\r
                         case ID_NEW:\r
                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_NEW);\r
                         break;\r
@@ -300,6 +318,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
            case WM_CLOSE:\r
             /* free the service array */\r
             FreeMemory();\r
+            DestroyMenu(hShortcutMenu);\r
                    DestroyWindow(hwnd);\r
            break;\r
 \r
@@ -313,10 +332,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 case ID_PROP:\r
                     PropSheets(hwnd);\r
                 break;\r
-                \r
+\r
                 case ID_REFRESH:\r
                     if (! RefreshServiceList() )\r
-                        GetError();\r
+                        GetError(0);\r
 \r
                 case ID_EXPORT:\r
                 break;\r
@@ -340,7 +359,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 break;\r
 \r
                 case ID_HELP:\r
-                    MessageBox(NULL, _T("Help is not yet implemented\n"), \r
+                    MessageBox(NULL, _T("Help is not yet implemented\n"),\r
                         _T("Note!"), MB_OK | MB_ICONINFORMATION);\r
                 break;\r
 \r
@@ -351,7 +370,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 case ID_VIEW_CUSTOMIZE:\r
                 break;\r
 \r
-                case ID_HELP_ABOUT:\r
+                case ID_ABOUT:\r
                     DialogBox(hInstance,\r
                               MAKEINTRESOURCE(IDD_ABOUTBOX),\r
                               hwnd,\r
index 691ab5e..a1c1830 100644 (file)
@@ -15,10 +15,14 @@ BOOL RefreshServiceList(VOID);
 \r
 BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
 \r
-VOID GetError(VOID);\r
+BOOL Start(LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount);\r
+\r
+VOID GetError(DWORD);\r
 VOID FreeMemory(VOID);\r
 VOID DisplayString(PTCHAR);\r
 \r
+VOID GetData(VOID);\r
+\r
 LONG APIENTRY PropSheets(HWND hwnd);\r
 \r
 DWORD GetServiceList(VOID);\r