You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2001/08/16 18:51:48 UTC

cvs commit: httpd-2.0/support/win32 ApacheMonitor.c ApacheMonitor.rc ApacheMonitor.h

wrowe       01/08/16 09:51:48

  Modified:    support/win32 ApacheMonitor.c ApacheMonitor.rc
                        ApacheMonitor.h
  Log:
    Bug fix to the WM_TIMER that was not properly called after it was moved
    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 <mt...@mappingsoft.com>
  
  Revision  Changes    Path
  1.7       +128 -48   httpd-2.0/support/win32/ApacheMonitor.c
  
  Index: ApacheMonitor.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/support/win32/ApacheMonitor.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ApacheMonitor.c	2001/08/16 06:59:53	1.6
  +++ ApacheMonitor.c	2001/08/16 16:51:48	1.7
  @@ -269,7 +269,7 @@
       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 @@
           mii.wID = uMenuId;
           if (fDefault)
               mii.fState = MFS_DEFAULT;
  +        if (!fEnabled)
  +            mii.fState |= MFS_DISABLED;
           mii.dwTypeData = szName;
       }
       else
  @@ -289,6 +291,27 @@
       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 @@
   
       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 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 addListBoxString(HWND hListBox, LPSTR lpStr)
   {
       static int nItems = 0;
  +    if (!g_bDlgServiceOn)
  +        return;
  +
       ++nItems;
       if ( nItems > MAX_LOADSTRING)
       {
  @@ -1137,52 +1187,58 @@
               SetTimer(hWnd, WM_TIMER_REFRESH, REFRESH_TIME, (TIMERPROC)WndProc);
               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())
  -            {
  -                ShowNotifyIcon(hWnd, NIM_MODIFY);
  -                if (g_hwndServiceDlg)
  -                    PostMessage(g_hwndServiceDlg, WM_UPDATEMESSAGE, 0, 0);
  +        case WM_TIMER:
  +            switch (wParam)
  +            {
  +                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 @@
                          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:
  
  
  
  1.6       +8 -4      httpd-2.0/support/win32/ApacheMonitor.rc
  
  Index: ApacheMonitor.rc
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/support/win32/ApacheMonitor.rc,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ApacheMonitor.rc	2001/08/16 06:33:37	1.5
  +++ ApacheMonitor.rc	2001/08/16 16:51:48	1.6
  @@ -23,9 +23,9 @@
       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 @@
       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 @@
       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
  
  
  
  1.5       +9 -1      httpd-2.0/support/win32/ApacheMonitor.h
  
  Index: ApacheMonitor.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/support/win32/ApacheMonitor.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ApacheMonitor.h	2001/08/16 02:12:13	1.4
  +++ ApacheMonitor.h	2001/08/16 16:51:48	1.5
  @@ -35,5 +35,13 @@
   #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