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;
mii.wID = uMenuId;
if (fDefault)
mii.fState = MFS_DEFAULT;
+ if (!fEnabled)
+ mii.fState |= MFS_DISABLED;
mii.dwTypeData = szName;
}
else
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 */
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);
}
}
+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;
static void addListBoxString(HWND hListBox, LPSTR lpStr)
{
static int nItems = 0;
+ if (!g_bDlgServiceOn)
+ return;
+
++nItems;
if ( nItems > MAX_LOADSTRING)
{
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;
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:
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"
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."
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