Commit 0de2f142 authored by William A. Rowe Jr's avatar William A. Rowe Jr
Browse files

  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 <mturk@mappingsoft.com>


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@90226 13f79535-47bb-0310-9956-ffa450edef68
parent b26445e6
Loading
Loading
Loading
Loading
+127 −47
Original line number Diff line number Diff line
@@ -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,17 +320,41 @@ 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);
        TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);
    }
}

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)
{
@@ -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,9 +1188,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
            SetTimer(hWnd, WM_TIMER_RESCAN,  RESCAN_TIME, (TIMERPROC)WndProc);
            g_hwndServiceDlg = NULL;                      
            break;
        case WM_TIMER:
            switch (wParam)
            {
                case WM_TIMER_RESCAN:
                {
                    int nPrev = 0, nNew = 0;
                    OutputDebugString("Rescan");
                    EnterCriticalSection(&g_stcSection);
                    if (FindRunningServices() || g_bRescanServices)
                    {
@@ -1183,6 +1237,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
                    LeaveCriticalSection(&g_stcSection);
                    break;
                }
            }
            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:
+9 −1
Original line number Diff line number Diff line
@@ -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
+8 −4
Original line number Diff line number Diff line
@@ -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