A bit of work towards populating the properties dialog. (untested)
[reactos.git] / reactos / subsys / system / servman / query.c
index 1c262c4..b5d1e15 100644 (file)
@@ -13,37 +13,67 @@ extern HINSTANCE hInstance;
 extern HWND hListView;\r
 extern HWND hStatus;\r
 \r
-/* Stores the service array */\r
+/* Stores the complete services array */\r
 ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;\r
 \r
 \r
-/* free service array */\r
+/* Free service array */\r
 VOID FreeMemory(VOID)\r
 {\r
     HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
 }\r
 \r
-VOID GetData(VOID)\r
+/* Retrives the service description from the registry */\r
+BOOL GetDescription(HKEY hKey, LPTSTR *retDescription)\r
 {\r
-    LVITEM item;\r
-    UINT sel;\r
-    TCHAR buf[200];\r
 \r
-    sel = ListView_GetHotItem(hListView);\r
+    LPTSTR Description = NULL;\r
+    DWORD dwValueSize = 0;\r
+    LONG ret = RegQueryValueEx(hKey,\r
+                               _T("Description"),\r
+                               NULL,\r
+                               NULL,\r
+                               NULL,\r
+                               &dwValueSize);\r
+    if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret != ERROR_INVALID_HANDLE)\r
+    {\r
+        RegCloseKey(hKey);\r
+        return FALSE;\r
+    }\r
+\r
+    if (ret != ERROR_FILE_NOT_FOUND)\r
+    {\r
+        Description = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);\r
+        if (Description == NULL)\r
+        {\r
+            RegCloseKey(hKey);\r
+            return FALSE;\r
+        }\r
+\r
+        if(RegQueryValueEx(hKey,\r
+                           _T("Description"),\r
+                           NULL,\r
+                           NULL,\r
+                           (LPBYTE)Description,\r
+                           &dwValueSize))\r
+        {\r
+            HeapFree(GetProcessHeap(), 0, Description);\r
+            RegCloseKey(hKey);\r
+            return FALSE;\r
+        }\r
+    }\r
 \r
-    ZeroMemory(&item, sizeof(LV_ITEM));\r
+    /* copy pointer over */\r
+    *retDescription = Description;\r
 \r
-    item.mask = LVIF_TEXT;\r
-    item.iItem = sel;\r
-    item.iSubItem = 0;\r
-    item.pszText = buf;\r
-    item.cchTextMax = 200;\r
+    return TRUE;\r
+}\r
 \r
-    ListView_GetItem(hListView, &item);\r
 \r
+BOOL GetExecutablePath(LPTSTR *ExePath)\r
+{\r
 \r
-    //DisplayString(sel);\r
-    DisplayString(item.pszText);\r
+    return FALSE;\r
 }\r
 \r
 \r
@@ -79,12 +109,10 @@ RefreshServiceList(VOID)
         /* assign the image to the list view */\r
         ListView_SetImageList(hListView, hSmall, LVSIL_SMALL);\r
 \r
-\r
         for (Index = 0; Index < NumServices; Index++)\r
         {\r
             HKEY hKey = NULL;\r
             LPTSTR Description = NULL;\r
-            LONG ret;\r
             LPTSTR LogOnAs = NULL;\r
             DWORD StartUp = 0;\r
             DWORD dwValueSize;\r
@@ -102,48 +130,25 @@ RefreshServiceList(VOID)
 \r
             /* set the display name */\r
 \r
-            ZeroMemory(&item, sizeof(LV_ITEM));\r
-            item.mask = LVIF_TEXT;\r
+            ZeroMemory(&item, sizeof(LVITEM));\r
+            item.mask = LVIF_TEXT | LVIF_PARAM;\r
             item.pszText = pServiceStatus[Index].lpDisplayName;\r
+\r
+            /* Set a pointer for each service so we can query it later.\r
+             * Not all services are added to the list, so we can't query\r
+             * the item number as they become out of sync with the array */\r
+            item.lParam = (LPARAM)&pServiceStatus[Index];\r
+\r
             item.iItem = ListView_GetItemCount(hListView);\r
             item.iItem = ListView_InsertItem(hListView, &item);\r
 \r
 \r
 \r
+\r
             /* set the description */\r
-            dwValueSize = 0;\r
-            ret = RegQueryValueEx(hKey,\r
-                                _T("Description"),\r
-                                NULL,\r
-                                NULL,\r
-                                NULL,\r
-                                &dwValueSize);\r
-            if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret != ERROR_INVALID_HANDLE)\r
-            {\r
-                RegCloseKey(hKey);\r
-                continue;\r
-            }\r
 \r
-            if (ret != ERROR_FILE_NOT_FOUND)\r
+            if (GetDescription(hKey, &Description))\r
             {\r
-                Description = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);\r
-                if (Description == NULL)\r
-                {\r
-                    RegCloseKey(hKey);\r
-                    return FALSE;\r
-                }\r
-                if(RegQueryValueEx(hKey,\r
-                                   _T("Description"),\r
-                                   NULL,\r
-                                   NULL,\r
-                                   (LPBYTE)Description,\r
-                                   &dwValueSize))\r
-                {\r
-                    HeapFree(GetProcessHeap(), 0, Description);\r
-                    RegCloseKey(hKey);\r
-                    continue;\r
-                }\r
-\r
                 item.pszText = Description;\r
                 item.iSubItem = 1;\r
                 SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
@@ -152,7 +157,6 @@ RefreshServiceList(VOID)
             }\r
 \r
 \r
-\r
             /* set the status */\r
 \r
             if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)\r
@@ -253,6 +257,9 @@ RefreshServiceList(VOID)
         SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
     }\r
 \r
+    /* turn redraw flag on. It's turned off initially via the LBS_NOREDRAW flag */\r
+    SendMessage (hListView, WM_SETREDRAW, TRUE, 0) ;\r
+\r
     return TRUE;\r
 }\r
 \r