use GET_X/Y_LPARAM as per MSDN
[reactos.git] / reactos / subsys / system / servman / servman.c
index 393154d..0d00680 100644 (file)
-#include <windows.h>\r
-#include <stdio.h>\r
-#include <tchar.h>\r
-#include <commctrl.h>\r
-#include "resource.h"\r
+/*\r
+ * PROJECT:     ReactOS Services\r
+ * LICENSE:     GPL - See COPYING in the top level directory\r
+ * 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
+#include "servman.h"\r
 \r
 const TCHAR ClassName[] = _T("ServiceManager");\r
 \r
 HINSTANCE hInstance;\r
+HWND hMainWnd;\r
 HWND hListView;\r
 HWND hStatus;\r
+HWND hTool;\r
+HMENU hShortcutMenu;\r
 \r
 \r
-void\r
-GetServices ( void )\r
+LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
 {\r
-    LV_ITEM item;\r
-    WORD wCodePage;\r
-    WORD wLangID;\r
-    SC_HANDLE ScHandle;\r
-    SC_HANDLE hService;\r
-    DWORD BytesNeeded = 0;\r
-    DWORD ResumeHandle = 0;\r
-    DWORD NumServices = 0;\r
-    DWORD dwHandle, dwLen;\r
-    size_t Index;\r
-    UINT BufLen;\r
-    TCHAR szStatus[128];\r
-    TCHAR* lpData;\r
-    TCHAR* lpBuffer;\r
-    TCHAR szStrFileInfo[80];\r
-    TCHAR FileName[MAX_PATH];\r
-    TCHAR szNumServices[32];\r
-    LPVOID pvData;\r
-\r
-    LPSERVICE_FAILURE_ACTIONS pServiceFailureActions = NULL;\r
-    LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;\r
-    ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;\r
-\r
-    ScHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);\r
-    if (ScHandle != INVALID_HANDLE_VALUE)\r
+    switch(msg)\r
     {\r
-        if (EnumServicesStatusEx(ScHandle,\r
-                                 SC_ENUM_PROCESS_INFO,\r
-                                 SERVICE_WIN32,\r
-                                 SERVICE_STATE_ALL,\r
-                                 (LPBYTE)pServiceStatus,\r
-                                 0, &BytesNeeded,\r
-                                 &NumServices,\r
-                                 &ResumeHandle,\r
-                                 0) == 0)\r
+        case WM_CREATE:\r
         {\r
-            /* Call function again if required size was returned */\r
-            if (GetLastError() == ERROR_MORE_DATA)\r
-            {\r
-                /* reserve memory for service info array */\r
-                pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
-                if (pServiceStatus == NULL)\r
-                               return;\r
-\r
-                /* fill array with service info */\r
-                if (EnumServicesStatusEx(ScHandle,\r
-                                         SC_ENUM_PROCESS_INFO,\r
-                                         SERVICE_WIN32,\r
-                                         SERVICE_STATE_ALL,\r
-                                         (LPBYTE)pServiceStatus,\r
-                                         BytesNeeded,\r
-                                         &BytesNeeded,\r
-                                         &NumServices,\r
-                                         &ResumeHandle,\r
-                                         0) == 0)\r
-                {\r
-                    HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
-                    return;\r
-                }\r
-            }\r
-            else /* exit on failure */\r
-            {\r
-                return;\r
-            }\r
-        }\r
-\r
-        if (NumServices)\r
-        {\r
-            HICON hiconItem;     // icon for list-view items\r
-            HIMAGELIST hSmall;   // image list for other views\r
-            TCHAR buf[40];\r
-\r
-            /* Create the icon image lists */\r
-            hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),\r
-                GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1);\r
-\r
-            /* Add an icon to each image list */\r
-            hiconItem = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));\r
-            ImageList_AddIcon(hSmall, hiconItem);\r
-            DestroyIcon(hiconItem);\r
-\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
-            _stprintf(buf, szNumServices, NumServices);\r
-            SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
+             //HFONT hfDefault;\r
 \r
-            for (Index = 0; Index < NumServices; Index++)\r
-            {\r
-                memset(&item, 0, sizeof(LV_ITEM));\r
-                item.mask = LVIF_TEXT;\r
-                //item.iImage = 0;\r
-                item.pszText = pServiceStatus[Index].lpDisplayName;\r
-                item.iItem = ListView_GetItemCount(hListView);\r
-                item.lParam = 0;\r
-                item.iItem = ListView_InsertItem(hListView, &item);\r
-\r
-                BytesNeeded = 0;\r
-                hService = OpenService(ScHandle,\r
-                                       pServiceStatus[Index].lpServiceName,\r
-                                       SC_MANAGER_CONNECT);\r
-                if (hService != INVALID_HANDLE_VALUE)\r
-                {\r
-                    /* check if service is required by the system*/\r
-                    if (!QueryServiceConfig2(hService,\r
-                                             SERVICE_CONFIG_FAILURE_ACTIONS,\r
-                                             (LPBYTE)pServiceFailureActions,\r
-                                             0,\r
-                                             &BytesNeeded))\r
-                    {\r
-                        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
-                        {\r
-                            pServiceFailureActions = (LPSERVICE_FAILURE_ACTIONS)\r
-                                HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
-                            if (pServiceFailureActions == NULL)\r
-                                           return;\r
-\r
-                            if (!QueryServiceConfig2(hService,\r
-                                                     SERVICE_CONFIG_FAILURE_ACTIONS,\r
-                                                     (LPBYTE)pServiceFailureActions,\r
-                                                     BytesNeeded,\r
-                                                     &BytesNeeded))\r
-                            {\r
-                                HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
-                                return;\r
-                            }\r
-                        }\r
-                        else /* exit on failure */\r
-                        {\r
-                            return;\r
-                        }\r
-                    }\r
-                    if (pServiceFailureActions->cActions)\r
-                    {\r
-                        if (pServiceFailureActions->lpsaActions[0].Type == SC_ACTION_REBOOT)\r
-                        {\r
-                            LoadString(hInstance, IDS_SERVICES_YES, szStatus, 128);\r
-                            item.pszText = szStatus;\r
-                            item.iSubItem = 1;\r
-                            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                        }\r
-                    }\r
+            TBADDBITMAP tbab;\r
+            INT iImageOffset;\r
+            INT statwidths[] = {110, -1}; /* widths of status bar */\r
+            TCHAR szTemp[256];\r
+            LVCOLUMN lvc = { 0 };\r
 \r
-                                       if (pServiceFailureActions != NULL)\r
-                                       {\r
-                                               HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
-                                               pServiceFailureActions = NULL;\r
-                                       }\r
+            /* Toolbar 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
+                {TBICON_EXPORT,  ID_EXPORT,  TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},    /* export */\r
 \r
-                    /* get vendor of service binary */\r
-                    BytesNeeded = 0;\r
-                    if (!QueryServiceConfig(hService, pServiceConfig, 0, &BytesNeeded))\r
-                    {\r
-                        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
-                        {\r
-                            pServiceConfig = (LPQUERY_SERVICE_CONFIG)\r
-                                HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
-                            if (pServiceConfig == NULL)\r
-                                           return;\r
-\r
-                            if (!QueryServiceConfig(hService,\r
-                                                    pServiceConfig,\r
-                                                    BytesNeeded,\r
-                                                    &BytesNeeded))\r
-                            {\r
-                                HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
-                                return;\r
-                            }\r
-                        }\r
-                        else /* exit on failure */\r
-                        {\r
-                            return;\r
-                        }\r
-                    }\r
+                /* Note: First item for a seperator is its width in pixels */\r
+                {25, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                             /* separator */\r
 \r
-                    memset(&FileName, 0, MAX_PATH);\r
-                    if (_tcscspn(pServiceConfig->lpBinaryPathName, _T("\"")))\r
-                    {\r
-                        _tcsncpy(FileName, pServiceConfig->lpBinaryPathName,\r
-                            _tcscspn(pServiceConfig->lpBinaryPathName, _T(" ")) );\r
-                    }\r
-                    else\r
-                    {\r
-                        _tcscpy(FileName, pServiceConfig->lpBinaryPathName);\r
-                    }\r
-\r
-                                       HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
-                                       pServiceConfig = NULL;\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_RESTART, ID_RESTART, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* restart */\r
 \r
-                                       dwLen = GetFileVersionInfoSize(FileName, &dwHandle);\r
-                    if (dwLen)\r
-                    {\r
-                        lpData = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, dwLen);\r
-                        if (lpData == NULL)\r
-                                       return;\r
-\r
-                        if (!GetFileVersionInfo (FileName, dwHandle, dwLen, lpData)) {\r
-                                   HeapFree(GetProcessHeap(), 0, lpData);\r
-                                   return;\r
-                           }\r
-\r
-                        if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &pvData, (PUINT) &BufLen))\r
-                        {\r
-                            wCodePage = LOWORD(*(DWORD*) pvData);\r
-                            wLangID = HIWORD(*(DWORD*) pvData);\r
-                            wsprintf(szStrFileInfo, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage, wLangID);\r
-                        }\r
-\r
-                        if (VerQueryValue (lpData, szStrFileInfo, (LPVOID) &lpBuffer, (PUINT) &BufLen)) {\r
-                            item.pszText = lpBuffer;\r
-                            item.iSubItem = 2;\r
-                            SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                        }\r
-                                               HeapFree(GetProcessHeap(), 0, lpData);\r
-                    }\r
-                    else\r
-                    {\r
-                        LoadString(hInstance, IDS_SERVICES_UNKNOWN, szStatus, 128);\r
-                        item.pszText = szStatus;\r
-                        item.iSubItem = 2;\r
-                        SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
-                    }\r
-                    CloseServiceHandle(hService);\r
-                }\r
+                {25, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                             /* separator */\r
 \r
-                if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)\r
-                {\r
-                    LoadString(hInstance, IDS_SERVICES_STATUS_RUNNING, 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
+                {TBICON_NEW,     ID_NEW,   TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* start */\r
+                {TBICON_HELP,    ID_HELP,    TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* stop */\r
+                {TBICON_EXIT,    ID_EXIT,   TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 },   /* pause */\r
 \r
-            }\r
-        }\r
+            };\r
 \r
-        HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
-        CloseServiceHandle(ScHandle);\r
-    }\r
+/* ======================== Create Toolbar ============================== */\r
 \r
+            /* Create Toolbar */\r
+            hTool = CreateWindowEx(0,\r
+                                   TOOLBARCLASSNAME,\r
+                                   NULL,\r
+                                   WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,\r
+                                   0, 0, 0, 0,\r
+                                   hwnd,\r
+                                   (HMENU)IDC_TOOLBAR,\r
+                                   hInstance,\r
+                                   NULL);\r
+            if(hTool == NULL)\r
+                MessageBox(hwnd, _T("Could not create tool bar."), _T("Error"), MB_OK | MB_ICONERROR);\r
 \r
-}\r
+            /* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */\r
+            SendMessage(hTool, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);\r
 \r
+            /* Add standard image list */\r
+            tbab.hInst = HINST_COMMCTRL;\r
+            tbab.nID = IDB_STD_SMALL_COLOR;\r
+            SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM) &tbab);\r
 \r
+            /* Add custom images */\r
+            tbab.hInst = hInstance;\r
+            tbab.nID = IDB_BUTTONS;\r
+            iImageOffset = (INT)SendMessage(hTool, TB_ADDBITMAP, 11, (LPARAM)&tbab);\r
+            tbb[0].iBitmap += iImageOffset; /* properties */\r
+            tbb[1].iBitmap += iImageOffset; /* refresh */\r
+            tbb[2].iBitmap += iImageOffset; /* export */\r
+            tbb[4].iBitmap += iImageOffset; /* start */\r
+            tbb[5].iBitmap += iImageOffset; /* stop */\r
+            tbb[6].iBitmap += iImageOffset; /* pause */\r
+            tbb[7].iBitmap += iImageOffset; /* restart */\r
+            tbb[9].iBitmap += iImageOffset; /* new */\r
+            tbb[10].iBitmap += iImageOffset; /* help */\r
+            tbb[11].iBitmap += iImageOffset; /* exit */\r
 \r
-LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
-{\r
-       switch(msg)\r
-       {\r
-               case WM_CREATE:\r
-               {\r
-                       //HFONT hfDefault;\r
+            /* Add buttons to toolbar */\r
+            SendMessage(hTool, TB_ADDBUTTONS, NUM_BUTTONS, (LPARAM) &tbb);\r
 \r
-                       HWND hTool;\r
-                       TBBUTTON tbb[7];\r
-                       TBADDBITMAP tbab;\r
+            /* Show toolbar */\r
+            ShowWindow(hTool, SW_SHOWNORMAL);\r
 \r
-                       int statwidths[] = {110, -1};\r
 \r
-                       TCHAR szTemp[256];\r
 \r
-                       /* Create List View */\r
-            LVCOLUMN lvc = { 0 };\r
-            //LVITEM   lv  = { 0 };\r
+/* ======================== Create List View ============================== */\r
 \r
-            //GetClientRect(hwnd, &rc);\r
             hListView = CreateWindow(WC_LISTVIEW,\r
                                      NULL,\r
-                                     WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER | LVS_EDITLABELS,\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
                                      (HMENU) IDC_SERVLIST,\r
                                      hInstance,\r
                                      NULL);\r
+            if (hListView == NULL)\r
+                MessageBox(hwnd, _T("Could not create List View."), _T("Error"), MB_OK | MB_ICONERROR);\r
 \r
             ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT |\r
-                    /*LVS_EX_GRIDLINES |*/ LVS_EX_HEADERDRAGDROP);\r
+                    LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);\r
 \r
             lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH  | LVCF_FMT;\r
             lvc.fmt  = LVCFMT_LEFT;\r
 \r
-            /* Add columns to the list-view (first column contains check box). */\r
+            /* Add columns to the list-view */\r
+\r
+            /* name */\r
             lvc.iSubItem = 0;\r
             lvc.cx       = 160;\r
             LoadString(hInstance, IDS_FIRSTCOLUMN, szTemp, 256);\r
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 0, &lvc);\r
 \r
+            /* description */\r
             lvc.iSubItem = 1;\r
-            lvc.cx       = 150;\r
+            lvc.cx       = 260;\r
             LoadString(hInstance, IDS_SECONDCOLUMN, szTemp, 256);\r
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 1, &lvc);\r
 \r
+            /* status */\r
             lvc.iSubItem = 2;\r
-            lvc.cx       = 80;\r
+            lvc.cx       = 75;\r
             LoadString(hInstance, IDS_THIRDCOLUMN, szTemp, 256);\r
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 2, &lvc);\r
 \r
+            /* startup type */\r
             lvc.iSubItem = 3;\r
             lvc.cx       = 80;\r
             LoadString(hInstance, IDS_FOURTHCOLUMN, szTemp, 256);\r
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 3, &lvc);\r
 \r
+            /* logon as */\r
             lvc.iSubItem = 4;\r
             lvc.cx       = 100;\r
             LoadString(hInstance, IDS_FITHCOLUMN, szTemp, 256);\r
             lvc.pszText  = szTemp;\r
             ListView_InsertColumn(hListView, 4, &lvc);\r
 \r
-                       // Create Toolbar\r
-                       hTool = CreateWindowEx(0,\r
-                                   TOOLBARCLASSNAME,\r
-                                   NULL,\r
-                                   WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,\r
-                                   0, 0, 0, 0,\r
-                                   hwnd,\r
-                                   (HMENU)IDC_TOOLBAR,\r
-                                   hInstance,\r
-                                   NULL);\r
-                       if(hTool == NULL)\r
-                               MessageBox(hwnd, _T("Could not create tool bar."), _T("Error"), MB_OK | MB_ICONERROR);\r
-\r
-                       // Send the TB_BUTTONSTRUCTSIZE message, which is required for\r
-                       // backward compatibility.\r
-                       SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);\r
-\r
-                       tbab.hInst = HINST_COMMCTRL;\r
-                       tbab.nID = IDB_STD_SMALL_COLOR;\r
-                       SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);\r
-\r
-            ZeroMemory(tbb, sizeof(tbb));\r
-            tbb[0].iBitmap = STD_PROPERTIES;\r
-            tbb[0].fsState = TBSTATE_ENABLED;\r
-            tbb[0].fsStyle = TBSTYLE_BUTTON;\r
-            tbb[0].idCommand = ID_PROP;\r
-            tbb[1].iBitmap = STD_FILENEW;\r
-            tbb[1].fsState = TBSTATE_ENABLED;\r
-            tbb[1].fsStyle = TBSTYLE_BUTTON;\r
-            tbb[1].idCommand = ID_REFRESH;\r
-            tbb[2].iBitmap = STD_FILENEW;\r
-            tbb[2].fsState = TBSTATE_ENABLED;\r
-            tbb[2].fsStyle = TBSTYLE_BUTTON;\r
-            tbb[2].idCommand = ID_EXPORT;\r
-            /* seperator */\r
-            tbb[3].iBitmap = STD_FILENEW;\r
-            tbb[3].fsState = TBSTATE_ENABLED;\r
-            tbb[3].fsStyle = TBSTYLE_BUTTON;\r
-            tbb[3].idCommand = ID_START;\r
-            tbb[4].iBitmap = STD_FILENEW;\r
-            tbb[4].fsState = TBSTATE_ENABLED;\r
-            tbb[4].fsStyle = TBSTYLE_BUTTON;\r
-            tbb[4].idCommand = ID_STOP;\r
-            tbb[5].iBitmap = STD_FILENEW;\r
-            tbb[5].fsState = TBSTATE_ENABLED;\r
-            tbb[5].fsStyle = TBSTYLE_BUTTON;\r
-            tbb[5].idCommand = ID_PAUSE;\r
-            tbb[6].iBitmap = STD_FILENEW;\r
-            tbb[6].fsState = TBSTATE_ENABLED;\r
-            tbb[6].fsStyle = TBSTYLE_BUTTON;\r
-            tbb[6].idCommand = ID_RESTART;\r
-            SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);\r
-\r
-                       /* Create Status bar */\r
-                       hStatus = CreateWindowEx(0,\r
+\r
+\r
+/* ======================== Create Status Bar ============================== */\r
+\r
+                   hStatus = CreateWindowEx(0,\r
                                      STATUSCLASSNAME,\r
                                      NULL,\r
                                      WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,\r
@@ -397,55 +173,74 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                                      hInstance,\r
                                      NULL);\r
             if(hStatus == NULL)\r
-                               MessageBox(hwnd, _T("Could not create status bar."), _T("Error"), MB_OK | MB_ICONERROR);\r
+                           MessageBox(hwnd, _T("Could not create status bar."),\r
+                           _T("Error!"), MB_OK | MB_ICONERROR);\r
+\r
+                   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
+                   RefreshServiceList();\r
 \r
-                       SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);\r
+           }\r
+           break;\r
 \r
-                       /* populate the list view with all services */\r
-                       GetServices();\r
-               }\r
-               break;\r
-               case WM_SIZE:\r
-               {\r
-                       HWND hTool;\r
-                       RECT rcTool;\r
-                       int iToolHeight;\r
+           case WM_SIZE:\r
+           {\r
+                   RECT rcTool;\r
+                   int iToolHeight;\r
 \r
-                       HWND hStatus;\r
-                       RECT rcStatus;\r
-                       int iStatusHeight;\r
+                   RECT rcStatus;\r
+                   int iStatusHeight;\r
 \r
-                       HWND hListView;\r
-                       int lvHeight;\r
-                       RECT rcClient;\r
+                   int lvHeight;\r
+                   RECT rcClient;\r
 \r
-                       /* Size toolbar and get height */\r
-                       hTool = GetDlgItem(hwnd, IDC_TOOLBAR);\r
-                       SendMessage(hTool, TB_AUTOSIZE, 0, 0);\r
+                   /* Size toolbar and get height */\r
+            hTool = GetDlgItem(hwnd, IDC_TOOLBAR);\r
+                   SendMessage(hTool, TB_AUTOSIZE, 0, 0);\r
 \r
-                       GetWindowRect(hTool, &rcTool);\r
-                       iToolHeight = rcTool.bottom - rcTool.top;\r
+                   GetWindowRect(hTool, &rcTool);\r
+                   iToolHeight = rcTool.bottom - rcTool.top;\r
 \r
-                       /* Size status bar and get height */\r
-                       hStatus = GetDlgItem(hwnd, IDC_STATUSBAR);\r
-                       SendMessage(hStatus, WM_SIZE, 0, 0);\r
+                   /* Size status bar and get height */\r
+                   hStatus = GetDlgItem(hwnd, IDC_STATUSBAR);\r
+                   SendMessage(hStatus, WM_SIZE, 0, 0);\r
 \r
-                       GetWindowRect(hStatus, &rcStatus);\r
-                       iStatusHeight = rcStatus.bottom - rcStatus.top;\r
+                   GetWindowRect(hStatus, &rcStatus);\r
+                   iStatusHeight = rcStatus.bottom - rcStatus.top;\r
 \r
-                       /* Calculate remaining height and size list view */\r
-                       GetClientRect(hwnd, &rcClient);\r
+                   /* Calculate remaining height and size list view */\r
+                   GetClientRect(hwnd, &rcClient);\r
 \r
-                       lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;\r
+                   lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;\r
 \r
-                       hListView = GetDlgItem(hwnd, IDC_SERVLIST);\r
-                       SetWindowPos(hListView, NULL, 0, iToolHeight, rcClient.right, lvHeight, SWP_NOZORDER);\r
-               }\r
-               break;\r
+                   hListView = GetDlgItem(hwnd, IDC_SERVLIST);\r
+                   SetWindowPos(hListView, NULL, 0, iToolHeight, rcClient.right, lvHeight, SWP_NOZORDER);\r
+           }\r
+           break;\r
+\r
+           case WM_NOTIFY:\r
+        {\r
+            LPNMITEMACTIVATE item;\r
+            \r
 \r
-               case WM_NOTIFY:\r
             switch (((LPNMHDR) lParam)->code)\r
             {\r
+                   case NM_DBLCLK:\r
+                    item = (LPNMITEMACTIVATE) lParam;\r
+                    PropSheets(hwnd);\r
+                           break;\r
+\r
                 case TTN_GETDISPINFO:\r
                 {\r
                     LPTOOLTIPTEXT lpttt;\r
@@ -456,7 +251,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 \r
                     // Specify the resource identifier of the descriptive\r
                     // text for the given button.\r
-                    idButton = lpttt->hdr.idFrom;\r
+                    idButton = (UINT)lpttt->hdr.idFrom;\r
                     switch (idButton)\r
                     {\r
                         case ID_PROP:\r
@@ -487,32 +282,65 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                             lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);\r
                         break;\r
 \r
+                        case ID_NEW:\r
+                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_NEW);\r
+                        break;\r
+\r
+                        case ID_HELP:\r
+                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP);\r
+                        break;\r
+\r
+                        case ID_EXIT:\r
+                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);\r
+                        break;\r
+\r
                     }\r
                 }\r
                 break;\r
 \r
-                // Process other notifications here.\r
-\r
                 default:\r
                 break;\r
             }\r
+        }\r
         break;\r
 \r
-               case WM_CLOSE:\r
-                       DestroyWindow(hwnd);\r
-               break;\r
-               case WM_DESTROY:\r
-                       PostQuitMessage(0);\r
-               break;\r
-               case WM_COMMAND:\r
-                       switch(LOWORD(wParam))\r
-                       {\r
-                               case ID_FILE_EXIT:\r
-                                       PostMessage(hwnd, WM_CLOSE, 0, 0);\r
-                               break;\r
-\r
-                               case ID_START:\r
-                               break;\r
+           case WM_CLOSE:\r
+            FreeMemory(); /* free the service array */\r
+            DestroyMenu(hShortcutMenu);\r
+                   DestroyWindow(hwnd);\r
+           break;\r
+\r
+           case WM_DESTROY:\r
+                   PostQuitMessage(0);\r
+           break;\r
+\r
+        case WM_CONTEXTMENU:\r
+            {\r
+                int xPos, yPos;\r
+\r
+                xPos = GET_X_LPARAM(lParam); \r
+                yPos = GET_Y_LPARAM(lParam);\r
+\r
+                TrackPopupMenuEx(hShortcutMenu, TPM_RIGHTBUTTON, xPos, yPos, hwnd, NULL);\r
+            }\r
+        break;\r
+\r
+           case WM_COMMAND:\r
+                   switch(LOWORD(wParam))\r
+                   {\r
+                case ID_PROP:\r
+                    PropSheets(hwnd);\r
+                break;\r
+\r
+                case ID_REFRESH:\r
+                    if (! RefreshServiceList() )\r
+                        GetError(0);\r
+\r
+                case ID_EXPORT:\r
+                break;\r
+\r
+                case ID_START:\r
+                           break;\r
 \r
                 case ID_STOP:\r
                 break;\r
@@ -526,81 +354,89 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 case ID_RESTART:\r
                 break;\r
 \r
-                case ID_REFRESH:\r
+                case ID_NEW:\r
                 break;\r
 \r
-                case ID_PROP:\r
+                case ID_HELP:\r
+                    MessageBox(NULL, _T("Help is not yet implemented\n"),\r
+                        _T("Note!"), MB_OK | MB_ICONINFORMATION);\r
                 break;\r
 \r
-                case ID_VIEW_CUSTOMIZE:\r
+                case ID_EXIT:\r
+                    PostMessage(hwnd, WM_CLOSE, 0, 0);\r
                 break;\r
 \r
-                case ID_HELP_ABOUT:\r
+                case ID_VIEW_CUSTOMIZE:\r
                 break;\r
 \r
-                case ID_EXPORT:\r
-                break;\r
-\r
-                       }\r
-               break;\r
-               default:\r
-                       return DefWindowProc(hwnd, msg, wParam, lParam);\r
-       }\r
-       return 0;\r
-}\r
+                case ID_ABOUT:\r
+                    DialogBox(hInstance,\r
+                              MAKEINTRESOURCE(IDD_ABOUTBOX),\r
+                              hwnd,\r
+                              AboutDialogProc);\r
+                 break;\r
 \r
+                   }\r
+           break;\r
 \r
+           default:\r
+                   return DefWindowProc(hwnd, msg, wParam, lParam);\r
+    }\r
+    return 0;\r
+}\r
 \r
+#ifdef _MSC_VER\r
+#pragma warning(disable : 4100)\r
+#endif\r
 int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,\r
-       LPSTR lpCmdLine, int nCmdShow)\r
+    LPSTR lpCmdLine, int nCmdShow)\r
 {\r
-       WNDCLASSEX wc;\r
-       HWND hwnd;\r
-       MSG Msg;\r
-       BOOL bRet;\r
-\r
-       hInstance = hThisInstance;\r
-\r
-       InitCommonControls();\r
-\r
-       wc.cbSize                = sizeof(WNDCLASSEX);\r
-       wc.style                 = 0;\r
-       wc.lpfnWndProc   = WndProc;\r
-       wc.cbClsExtra    = 0;\r
-       wc.cbWndExtra    = 0;\r
-       wc.hInstance     = hInstance;\r
-       wc.hIcon                 = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SM_ICON));\r
-       wc.hCursor               = LoadCursor(NULL, IDC_ARROW);\r
-       wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);\r
-       wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINMENU);\r
-       wc.lpszClassName = ClassName;\r
-       wc.hIconSm               = (HICON)LoadImage(GetModuleHandle(NULL),\r
+    WNDCLASSEX wc;\r
+    MSG Msg;\r
+    BOOL bRet;\r
+\r
+    hInstance = hThisInstance;\r
+\r
+    InitCommonControls();\r
+\r
+    wc.cbSize           = sizeof(WNDCLASSEX);\r
+    wc.style            = 0;\r
+    wc.lpfnWndProc      = WndProc;\r
+    wc.cbClsExtra       = 0;\r
+    wc.cbWndExtra       = 0;\r
+    wc.hInstance        = hInstance;\r
+    wc.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));\r
+    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);\r
+    wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);\r
+    wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINMENU);\r
+    wc.lpszClassName = ClassName;\r
+    wc.hIconSm          = (HICON)LoadImage(hInstance,\r
                         MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);\r
 \r
-       if(!RegisterClassEx(&wc))\r
-       {\r
-               MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),\r
-                       MB_ICONEXCLAMATION | MB_OK);\r
-               return 0;\r
-       }\r
-\r
-       hwnd = CreateWindowEx(\r
-               0,\r
-               ClassName,\r
-               _T("ReactOS Service Manager"),\r
-               WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,\r
-               CW_USEDEFAULT, CW_USEDEFAULT, 700, 500,\r
-               NULL, NULL, hInstance, NULL);\r
-\r
-       if(hwnd == NULL)\r
-       {\r
-               MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),\r
-                       MB_ICONEXCLAMATION | MB_OK);\r
-               return 0;\r
-       }\r
-\r
-       ShowWindow(hwnd, nCmdShow);\r
-       UpdateWindow(hwnd);\r
+    if(!RegisterClassEx(&wc))\r
+    {\r
+           MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),\r
+                   MB_ICONEXCLAMATION | MB_OK);\r
+           return 0;\r
+    }\r
+\r
+    hMainWnd = CreateWindowEx(\r
+           0,\r
+           ClassName,\r
+           _T("ReactOS Service Manager"),\r
+           WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,\r
+           CW_USEDEFAULT, CW_USEDEFAULT, 700, 500,\r
+           NULL, NULL, hInstance, NULL);\r
+\r
+    if(hMainWnd == NULL)\r
+    {\r
+           MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),\r
+                   MB_ICONEXCLAMATION | MB_OK);\r
+           return 0;\r
+    }\r
+\r
+    ShowWindow(hMainWnd, nCmdShow);\r
+    UpdateWindow(hMainWnd);\r
 \r
     while( (bRet = GetMessage( &Msg, NULL, 0, 0 )) != 0)\r
     {\r
@@ -614,7 +450,7 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
             DispatchMessage(&Msg);\r
         }\r
     }\r
-       return Msg.wParam;\r
+    return (int)Msg.wParam;\r
 }\r
 \r
 \r