]> granicus.if.org Git - apache/commitdiff
Bug fix to the WM_TIMER that was not properly called after it was moved
authorWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 16 Aug 2001 16:51:48 +0000 (16:51 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 16 Aug 2001 16:51:48 +0000 (16:51 +0000)
  to WndProc. (The message is WM_TIMER and wParam is timer event)

  Enhancement to left button click which now displays the popup menu with
  all Apache's installed, and to each installed service adds the submenu
  with the options to start, stop or restart the service.

Submitted by:  Mladen Turk <mturk@mappingsoft.com>

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@90226 13f79535-47bb-0310-9956-ffa450edef68

support/win32/ApacheMonitor.c
support/win32/ApacheMonitor.h
support/win32/ApacheMonitor.rc

index e16d8b85dc3e98e7236ef8a8752218517b00f77e..ad37cb232429a0c945d21c0267c50b237e357a93 100644 (file)
@@ -269,7 +269,7 @@ static VOID ShowNotifyIcon(HWND hWnd, DWORD dwMessage)
     Shell_NotifyIcon(dwMessage, &nid);
 }
 
-void appendMenuItem(HMENU hMenu, UINT uMenuId, LPSTR szName, BOOL fDefault)
+void appendMenuItem(HMENU hMenu, UINT uMenuId, LPSTR szName, BOOL fDefault, BOOL fEnabled)
 {
     MENUITEMINFO mii;
     
@@ -282,6 +282,8 @@ void appendMenuItem(HMENU hMenu, UINT uMenuId, LPSTR szName, BOOL fDefault)
         mii.wID = uMenuId;
         if (fDefault)
             mii.fState = MFS_DEFAULT;
+        if (!fEnabled)
+            mii.fState |= MFS_DISABLED;
         mii.dwTypeData = szName;
     }
     else
@@ -289,6 +291,27 @@ void appendMenuItem(HMENU hMenu, UINT uMenuId, LPSTR szName, BOOL fDefault)
     InsertMenuItem(hMenu, uMenuId, FALSE, &mii);
 }
 
+void appendServiceMenu(HMENU hMenu, UINT uMenuId, LPSTR szServiceName, BOOL fRunning)
+{
+    MENUITEMINFO mii;
+    HMENU        smh;    
+
+    smh = CreatePopupMenu();
+
+    appendMenuItem(smh,  IDM_SM_START + uMenuId, g_lpMsg[IDS_MSG_SSTART-IDS_MSG_FIRST], FALSE, !fRunning);
+    appendMenuItem(smh,  IDM_SM_STOP + uMenuId, g_lpMsg[IDS_MSG_SSTOP-IDS_MSG_FIRST], FALSE, fRunning);
+    appendMenuItem(smh,  IDM_SM_RESTART + uMenuId, g_lpMsg[IDS_MSG_SRESTART-IDS_MSG_FIRST], FALSE, fRunning);
+
+    ZeroMemory(&mii, sizeof(MENUITEMINFO));
+    mii.cbSize = sizeof(MENUITEMINFO);
+    mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_SUBMENU;
+    mii.fType = MFT_STRING;
+    mii.wID = uMenuId;
+    mii.dwTypeData = szServiceName;
+    mii.hSubMenu = smh;
+    InsertMenuItem(hMenu, IDM_SM_SERVICE + uMenuId, FALSE, &mii);
+}
+
 void ShowTryPopupMenu(HWND hWnd)
 {
     /* create popup menu */
@@ -297,11 +320,11 @@ void ShowTryPopupMenu(HWND hWnd)
 
     if (hMenu)
     {
-        appendMenuItem(hMenu, IDM_RESTORE, g_lpMsg[IDS_MSG_MNUSHOW-IDS_MSG_FIRST], TRUE);
+        appendMenuItem(hMenu, IDM_RESTORE, g_lpMsg[IDS_MSG_MNUSHOW-IDS_MSG_FIRST], TRUE, TRUE);
         if (g_dwOSVersion >= OS_VERSION_WINNT)
-            appendMenuItem(hMenu, IDC_SMANAGER, g_lpMsg[IDS_MSG_MNUSERVICES-IDS_MSG_FIRST], FALSE);
-        appendMenuItem(hMenu, 0, "", FALSE);
-        appendMenuItem(hMenu, IDM_EXIT,  g_lpMsg[IDS_MSG_MNUEXIT-IDS_MSG_FIRST], FALSE);
+            appendMenuItem(hMenu, IDC_SMANAGER, g_lpMsg[IDS_MSG_MNUSERVICES-IDS_MSG_FIRST], FALSE, TRUE);
+        appendMenuItem(hMenu, 0, "", FALSE, TRUE);
+        appendMenuItem(hMenu, IDM_EXIT,  g_lpMsg[IDS_MSG_MNUEXIT-IDS_MSG_FIRST], FALSE, TRUE);
 
         GetCursorPos(&pt);
         SetForegroundWindow(NULL);
@@ -309,6 +332,30 @@ void ShowTryPopupMenu(HWND hWnd)
     }
 }
 
+void ShowTryServicesMenu(HWND hWnd)
+{
+    /* create services list popup menu and submenus */
+    HMENU hMenu = CreatePopupMenu();
+    POINT pt;
+    int i = 0;
+
+    if (hMenu)
+    {
+        while (g_stServices[i].szServiceName != NULL)
+        {   
+            appendServiceMenu(hMenu, i, g_stServices[i].szDisplayName,
+                              g_stServices[i].dwPid != 0);               
+            ++i;
+        }
+        if (i)
+        {
+            GetCursorPos(&pt);
+            SetForegroundWindow(NULL);
+            TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);
+        }
+    }
+}
+
 BOOL CenterWindow(HWND hwndChild)
 {
    RECT    rChild, rWorkArea;
@@ -350,6 +397,9 @@ static void addListBoxItem(HWND hDlg, LPSTR lpStr, HBITMAP hBmp)
 static void addListBoxString(HWND hListBox, LPSTR lpStr)
 {
     static int nItems = 0;
+    if (!g_bDlgServiceOn)
+        return;
+
     ++nItems;
     if ( nItems > MAX_LOADSTRING)
     {
@@ -1138,51 +1188,57 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
             SetTimer(hWnd, WM_TIMER_RESCAN,  RESCAN_TIME, (TIMERPROC)WndProc);
             g_hwndServiceDlg = NULL;                      
             break;
-        case WM_TIMER_RESCAN:
-        {
-            int nPrev = 0, nNew = 0;
-            EnterCriticalSection(&g_stcSection);
-            if (FindRunningServices() || g_bRescanServices)
-            {
-                ShowNotifyIcon(hWnd, NIM_MODIFY);
-                if (g_hwndServiceDlg)
-                    PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
-            }
-            /* check if services list changed */
-            while (g_stServices[nPrev].szServiceName != NULL)
-                ++nPrev;
-            GetApacheServicesStatus();
-            while (g_stServices[nNew].szServiceName != NULL)
-                ++nNew;
-            if (nPrev != nNew)
-            {
-                ShowNotifyIcon(hWnd, NIM_MODIFY);
-                if (g_hwndServiceDlg)
-                    PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
-            }
-            LeaveCriticalSection(&g_stcSection);
-            break;
-        }
-        case WM_TIMER_REFRESH:
-        {
-            int nPrev = 0, nNew = 0;
-            EnterCriticalSection(&g_stcSection);
-            if (g_bRescanServices)
-            {
-                GetApacheServicesStatus();
-                ShowNotifyIcon(hWnd, NIM_MODIFY);
-                if (g_hwndServiceDlg)
-                    PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
-            }
-            else if (FindRunningServices())
+        case WM_TIMER:
+            switch (wParam)
             {
-                ShowNotifyIcon(hWnd, NIM_MODIFY);
-                if (g_hwndServiceDlg)
-                    PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
+                case WM_TIMER_RESCAN:
+                {
+                    int nPrev = 0, nNew = 0;
+                    OutputDebugString("Rescan");
+                    EnterCriticalSection(&g_stcSection);
+                    if (FindRunningServices() || g_bRescanServices)
+                    {
+                        ShowNotifyIcon(hWnd, NIM_MODIFY);
+                        if (g_hwndServiceDlg)
+                            PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
+                    }
+                    /* check if services list changed */
+                    while (g_stServices[nPrev].szServiceName != NULL)
+                        ++nPrev;
+                    GetApacheServicesStatus();
+                    while (g_stServices[nNew].szServiceName != NULL)
+                        ++nNew;
+                    if (nPrev != nNew)
+                    {
+                        ShowNotifyIcon(hWnd, NIM_MODIFY);
+                        if (g_hwndServiceDlg)
+                            PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
+                    }
+                    LeaveCriticalSection(&g_stcSection);
+                break;
+                }
+                case WM_TIMER_REFRESH:
+                {
+                    int nPrev = 0, nNew = 0;
+                    EnterCriticalSection(&g_stcSection);
+                    if (g_bRescanServices)
+                    {       
+                        GetApacheServicesStatus();
+                        ShowNotifyIcon(hWnd, NIM_MODIFY);
+                        if (g_hwndServiceDlg)
+                            PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
+                    }
+                    else if (FindRunningServices())
+                    {
+                        ShowNotifyIcon(hWnd, NIM_MODIFY);
+                        if (g_hwndServiceDlg)
+                            PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
+                    }
+                    LeaveCriticalSection(&g_stcSection);
+                    break;
+                }
             }
-            LeaveCriticalSection(&g_stcSection);
             break;
-        }
         case WM_QUIT:
             ShowNotifyIcon(hWnd, NIM_DELETE);
             break;
@@ -1208,12 +1264,36 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
                        SetFocus(g_hwndServiceDlg);
                    }
                 break;
+                case WM_LBUTTONUP:
+                    ShowTryServicesMenu(hWnd);
+                break;    
                 case WM_RBUTTONUP:
                     ShowTryPopupMenu(hWnd);
                 break;    
             }
             break;
         case WM_COMMAND:
+            if (LOWORD(wParam) & IDM_SM_START)
+            {
+                ApacheManageService(g_stServices[LOWORD(wParam) - IDM_SM_START].szServiceName,
+                                    g_stServices[LOWORD(wParam) - IDM_SM_START].szImagePath,
+                                    SERVICE_CONTROL_CONTINUE);                
+                return TRUE;
+            }
+            else if (LOWORD(wParam) & IDM_SM_STOP)
+            {
+                ApacheManageService(g_stServices[LOWORD(wParam) - IDM_SM_STOP].szServiceName,
+                                    g_stServices[LOWORD(wParam) - IDM_SM_STOP].szImagePath,
+                                    SERVICE_CONTROL_STOP);                
+                return TRUE;
+            }
+            else if (LOWORD(wParam) & IDM_SM_RESTART)
+            {
+                ApacheManageService(g_stServices[LOWORD(wParam) - IDM_SM_RESTART].szServiceName,
+                                    g_stServices[LOWORD(wParam) - IDM_SM_RESTART].szImagePath,
+                                    SERVICE_APACHE_RESTART);                
+                return TRUE;
+            }
             switch (LOWORD(wParam))
             {
                case IDM_RESTORE:
index 9dda3b2574938e0e4d22953ee33d151c097ab149..682bfb790ea2cc8753408fbdeaf7c4579fb43e65 100644 (file)
 #define IDS_MSG_SRVRESTART              269
 #define IDS_MSG_SRVRESTARTED            270
 #define IDS_MSG_SRVFAILED               271
-#define IDS_MSG_LAST                    271
+#define IDS_MSG_SSTART                  272
+#define IDS_MSG_SSTOP                   273
+#define IDS_MSG_SRESTART                274
+#define IDS_MSG_SERVICES                275
+#define IDS_MSG_LAST                    275
+#define IDM_SM_SERVICE                  0x1100
+#define IDM_SM_START                    0x1200
+#define IDM_SM_STOP                     0x1400
+#define IDM_SM_RESTART                  0x1800
 #define IDC_STATIC                      -1
index 5aa3204ad778fb50c572b6445c9549b51d20f133..359ce85d5716a4fa61390036260d9a2667766c21 100644 (file)
@@ -23,9 +23,9 @@ BEGIN
     PUSHBUTTON      "&Start",IDC_SSTART,298,75,50,14
     PUSHBUTTON      "S&top",IDC_SSTOP,298,91,50,14
     PUSHBUTTON      "&Restart",IDC_SRESTART,298,107,50,14
-    PUSHBUTTON      "Ser&vices",IDC_SMANAGER,298,127,50,14
+    PUSHBUTTON      "Ser&vices",IDC_SMANAGER,298,123,50,14
     CONTROL         113,IDC_STATIC,"Static",SS_BITMAP,0,0,349,38
-    PUSHBUTTON      "&Exit",IDC_SEXIT,298,147,50,14
+    PUSHBUTTON      "E&xit",IDC_SEXIT,298,147,50,14
 END
 
 IDB_BMPSTOP             BITMAP  DISCARDABLE     "sstop.bmp"
@@ -46,9 +46,9 @@ BEGIN
     IDS_MSG_RUNNING         "Running %d from %d Apache services"
     IDS_MSG_RUNNINGNONE     "Running none from %d Apache services"
     IDS_MSG_NOSERVICES      "No services installed"
-    IDS_MSG_MNUSERVICES     "&Open Services"
+    IDS_MSG_MNUSERVICES     "Open &Services"
     IDS_MSG_MNUSHOW         "&Open Apache Monitor"
-    IDS_MSG_MNUEXIT         "&Exit..."
+    IDS_MSG_MNUEXIT         "E&xit"
     IDS_MSG_SRVSTART        "The %s is starting."
     IDS_MSG_SRVSTARTED      "The %s has started."
     IDS_MSG_SRVSTOP         "The %s is stopping."
@@ -56,4 +56,8 @@ BEGIN
     IDS_MSG_SRVRESTART      "The %s is restarting."
     IDS_MSG_SRVRESTARTED    "The %s has restarted."
     IDS_MSG_SRVFAILED       "The requested operation has failed!"
+    IDS_MSG_SSTART          "&Start"
+    IDS_MSG_SSTOP           "S&top"
+    IDS_MSG_SRESTART        "&Restart"
+    IDS_MSG_SERVICES        "Ser&vices"
 END