⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apachemonitor.c

📁 最新apache的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
               SetBkColor(lpdis->hDC, GetSysColor(COLOR_WINDOW));                FillRect(lpdis->hDC, &rcBitmap, (HBRUSH)(COLOR_WINDOW+1));             }            TextOut(lpdis->hDC, XBITMAP + 6, y, szBuf, strlen(szBuf));             break;         case ODA_FOCUS:             break;         }         return TRUE;    case WM_COMMAND:         switch (LOWORD(wParam))         {         case IDL_SERVICES:            switch (HIWORD(wParam))            {            case LBN_DBLCLK:                /* if started then stop, if stopped then start */                hListBox = GetDlgItem(hDlg, IDL_SERVICES);                 nItem = SendMessage(hListBox, LB_GETCURSEL, 0, 0);                if (nItem != LB_ERR)                {                    g_hBmpPicture = (HBITMAP)SendMessage(hListBox,                                                          LB_GETITEMDATA,                                                         nItem, (LPARAM) 0);                    if (g_hBmpPicture == g_hBmpStop) {                        SendMessage(hDlg, WM_MANAGEMESSAGE, nItem,                                     SERVICE_CONTROL_CONTINUE);                    }                    else {                        SendMessage(hDlg, WM_MANAGEMESSAGE, nItem,                                     SERVICE_CONTROL_STOP);                    }                }                return TRUE;            }            break;        case IDOK:             EndDialog(hDlg, TRUE);             return TRUE;         case IDC_SSTART:             Button_Enable(GetDlgItem(hDlg, IDC_SSTART), FALSE);            hListBox = GetDlgItem(hDlg, IDL_SERVICES);             nItem = SendMessage(hListBox, LB_GETCURSEL, 0, 0);             if (nItem != LB_ERR) {                SendMessage(hDlg, WM_MANAGEMESSAGE, nItem,                             SERVICE_CONTROL_CONTINUE);            }            Button_Enable(GetDlgItem(hDlg, IDC_SSTART), TRUE);            return TRUE;        case IDC_SSTOP:             Button_Enable(GetDlgItem(hDlg, IDC_SSTOP), FALSE);            hListBox = GetDlgItem(hDlg, IDL_SERVICES);             nItem = SendMessage(hListBox, LB_GETCURSEL, 0, 0);             if (nItem != LB_ERR) {                SendMessage(hDlg, WM_MANAGEMESSAGE, nItem,                             SERVICE_CONTROL_STOP);            }            Button_Enable(GetDlgItem(hDlg, IDC_SSTOP), TRUE);            return TRUE;        case IDC_SRESTART:             Button_Enable(GetDlgItem(hDlg, IDC_SRESTART), FALSE);            hListBox = GetDlgItem(hDlg, IDL_SERVICES);             nItem = SendMessage(hListBox, LB_GETCURSEL, 0, 0);             if (nItem != LB_ERR) {                SendMessage(hDlg, WM_MANAGEMESSAGE, nItem,                             SERVICE_APACHE_RESTART);            }            Button_Enable(GetDlgItem(hDlg, IDC_SRESTART), TRUE);            return TRUE;        case IDC_SMANAGER:             if (g_dwOSVersion >= OS_VERSION_WIN2K) {                ShellExecute(hDlg, "open", "services.msc", "/s",                             NULL, SW_NORMAL);            }            else {                WinExec("Control.exe SrvMgr.cpl Services", SW_NORMAL);            }            return TRUE;        case IDC_SEXIT:             EndDialog(hDlg, TRUE);            SendMessage(g_hwndMain, WM_COMMAND, (WPARAM)IDM_EXIT, 0);            return TRUE;        case IDC_SCONNECT:             DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DLGCONNECT),                      hDlg, (DLGPROC)ConnectDlgProc);            return TRUE;        case IDC_SDISCONN:             hListBox = GetDlgItem(hDlg, IDL_SERVICES);             nItem = SendMessage(hListBox, LB_GETCURSEL, 0, 0);             if (nItem != LB_ERR) {                am_DisconnectComputer(g_stServices[nItem].szComputerName);                SendMessage(g_hwndMain, WM_TIMER, WM_TIMER_RESCAN, 0);            }            return TRUE;        }        break;    case WM_SIZE:        switch (LOWORD(wParam))         {         case SIZE_MINIMIZED:            EndDialog(hDlg, TRUE);             return TRUE;             break;        }        break;    case WM_QUIT:    case WM_CLOSE:         EndDialog(hDlg, TRUE);        return TRUE;    default:        return FALSE;    }    return FALSE;}LRESULT CALLBACK WndProc(HWND hWnd, UINT message,                          WPARAM wParam, LPARAM lParam){    if (message == g_bUiTaskbarCreated)    {        /* restore the tray icon on shell restart */        ShowNotifyIcon(hWnd, NIM_ADD);        return DefWindowProc(hWnd, message, wParam, lParam);    }    switch (message)     {    case WM_CREATE:        GetApacheServicesStatus();        ShowNotifyIcon(hWnd, NIM_ADD);        SetTimer(hWnd, WM_TIMER_REFRESH, REFRESH_TIME, NULL);        SetTimer(hWnd, WM_TIMER_RESCAN,  RESCAN_TIME, NULL);        break;    case WM_TIMER:        switch (wParam)        {        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);                }            }            LeaveCriticalSection(&g_stcSection);            break;        }        }        break;    case WM_QUIT:        ShowNotifyIcon(hWnd, NIM_DELETE);        break;    case WM_TRAYMESSAGE:        switch (lParam)        {        case WM_LBUTTONDBLCLK:            if (!g_bDlgServiceOn)            {                g_bDlgServiceOn = TRUE;                DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DLGSERVICES),                          hWnd, (DLGPROC)ServiceDlgProc);                g_bDlgServiceOn = FALSE;                g_hwndServiceDlg = NULL;            }            else if (IsWindow(g_hwndServiceDlg))            {                /* Dirty hack to bring the window to the foreground */                SetWindowPos(g_hwndServiceDlg, HWND_TOPMOST, 0, 0, 0, 0,                             SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);                SetWindowPos(g_hwndServiceDlg, HWND_NOTOPMOST, 0, 0, 0, 0,                             SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);                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) == IDM_SM_START)        {            ApacheManageService(g_stServices[LOWORD(wParam)                                            - IDM_SM_START].szServiceName,                                g_stServices[LOWORD(wParam)                                            - IDM_SM_START].szImagePath,                                g_stServices[LOWORD(wParam)                                            - IDM_SM_START].szComputerName,                                SERVICE_CONTROL_CONTINUE);            return TRUE;        }        else if ((LOWORD(wParam) & IDM_SM_STOP) == IDM_SM_STOP)        {            ApacheManageService(g_stServices[LOWORD(wParam)                                            - IDM_SM_STOP].szServiceName,                                g_stServices[LOWORD(wParam)                                            - IDM_SM_STOP].szImagePath,                                g_stServices[LOWORD(wParam)                                            - IDM_SM_STOP].szComputerName,                                SERVICE_CONTROL_STOP);            return TRUE;        }        else if ((LOWORD(wParam) & IDM_SM_RESTART) == IDM_SM_RESTART)        {            ApacheManageService(g_stServices[LOWORD(wParam)                                            - IDM_SM_RESTART].szServiceName,                                g_stServices[LOWORD(wParam)                                            - IDM_SM_RESTART].szImagePath,                                g_stServices[LOWORD(wParam)                                            - IDM_SM_RESTART].szComputerName,                                SERVICE_APACHE_RESTART);            return TRUE;        }        switch (LOWORD(wParam))        {        case IDM_RESTORE:            if (!g_bDlgServiceOn)            {                g_bDlgServiceOn = TRUE;                DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DLGSERVICES),                          hWnd, (DLGPROC)ServiceDlgProc);                g_bDlgServiceOn = FALSE;                g_hwndServiceDlg = NULL;            }            else if (IsWindow(g_hwndServiceDlg)) {                SetFocus(g_hwndServiceDlg);            }            break;        case IDC_SMANAGER:             if (g_dwOSVersion >= OS_VERSION_WIN2K) {                ShellExecute(NULL, "open", "services.msc", "/s",                             NULL, SW_NORMAL);            }            else {                WinExec("Control.exe SrvMgr.cpl Services", SW_NORMAL);            }            return TRUE;        case IDM_EXIT:            ShowNotifyIcon(hWnd, NIM_DELETE);            PostQuitMessage(0);            return TRUE;        }    default:        return DefWindowProc(hWnd, message, wParam, lParam);    }    return FALSE;}/* Create main invisible window */HWND CreateMainWindow(HINSTANCE hInstance){    HWND hWnd = NULL;    WNDCLASSEX wcex;    if (!GetSystemOSVersion(&g_dwOSVersion))    {        ErrorMessage(NULL, TRUE);        return hWnd;    }    wcex.cbSize = sizeof(WNDCLASSEX);     wcex.style          = CS_HREDRAW | CS_VREDRAW;    wcex.lpfnWndProc    = (WNDPROC)WndProc;    wcex.cbClsExtra     = 0;    wcex.cbWndExtra     = 0;    wcex.hInstance      = hInstance;    wcex.hIcon   = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_APSRVMON),                                    IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);    wcex.hCursor        = g_hCursorArrow;    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);    wcex.lpszMenuName   = 0;    wcex.lpszClassName  = g_szWindowClass;    wcex.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_APSRVMON),                                    IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);    if (RegisterClassEx(&wcex)) {        hWnd = CreateWindow(g_szWindowClass, g_szTitle,                            0, 0, 0, 0, 0,                            NULL, NULL, hInstance, NULL);    }    return hWnd;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                   LPSTR lpCmdLine, int nCmdShow){    CHAR szTmp[MAX_LOADSTRING];    CHAR szCmp[MAX_COMPUTERNAME_LENGTH+4];    MSG msg;    /* single instance mutex */    HANDLE hMutex;    int i;    DWORD d;    g_LangID = GetUserDefaultLangID();    if ((g_LangID & 0xFF) != LANG_ENGLISH) {        g_LangID = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);    }    for (i = IDS_MSG_FIRST; i <= IDS_MSG_LAST; ++i) {        LoadString(hInstance, i, szTmp, MAX_LOADSTRING);        g_lpMsg[i - IDS_MSG_FIRST] = strdup(szTmp);    }    LoadString(hInstance, IDS_APMONITORTITLE, szTmp, MAX_LOADSTRING);    d = MAX_COMPUTERNAME_LENGTH+1;    strcpy(szCmp, "\\\\");    GetComputerName(szCmp + 2, &d);    strupr(szCmp);    g_szLocalHost = strdup(szCmp);    memset(g_stComputers, 0, sizeof(ST_MONITORED_COMP) * MAX_APACHE_COMPUTERS);    g_stComputers[0].szComputerName = strdup(szCmp);    g_stComputers[0].hRegistry = HKEY_LOCAL_MACHINE;    g_szTitle = strdup(szTmp);    LoadString(hInstance, IDS_APMONITORCLASS, szTmp, MAX_LOADSTRING);    g_szWindowClass = strdup(szTmp);    g_icoStop          = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICOSTOP),                                   IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);    g_icoRun           = LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICORUN),                                   IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);    g_hCursorHourglass = LoadImage(NULL, MAKEINTRESOURCE(OCR_WAIT),                                    IMAGE_CURSOR, LR_DEFAULTSIZE,                                    LR_DEFAULTSIZE, LR_SHARED);    g_hCursorArrow     = LoadImage(NULL, MAKEINTRESOURCE(OCR_NORMAL),                                    IMAGE_CURSOR, LR_DEFAULTSIZE,                                    LR_DEFAULTSIZE, LR_SHARED);    g_hBmpStart        = LoadImage(hInstance, MAKEINTRESOURCE(IDB_BMPRUN),                                   IMAGE_BITMAP, XBITMAP, YBITMAP,                                    LR_DEFAULTCOLOR);    g_hBmpStop         = LoadImage(hInstance, MAKEINTRESOURCE(IDB_BMPSTOP),                                   IMAGE_BITMAP, XBITMAP, YBITMAP,                                    LR_DEFAULTCOLOR);    hMutex = CreateMutex(NULL, FALSE, "APSRVMON_MUTEX");    if ((hMutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS))    {        ErrorMessage(g_lpMsg[IDS_MSG_APPRUNNING - IDS_MSG_FIRST], FALSE);        if (hMutex) {            CloseHandle(hMutex);        }        return 0;    }    memset(g_stServices, 0, sizeof(ST_APACHE_SERVICE) * MAX_APACHE_SERVICES);    CoInitialize(NULL);    InitCommonControls();    g_hInstance = hInstance;    g_hwndMain = CreateMainWindow(hInstance);    g_bUiTaskbarCreated = RegisterWindowMessage("TaskbarCreated");    InitializeCriticalSection(&g_stcSection);    g_hwndServiceDlg = NULL;    if (g_hwndMain != NULL)    {        while (GetMessage(&msg, NULL, 0, 0) == TRUE)         {            TranslateMessage(&msg);            DispatchMessage(&msg);        }        am_ClearServicesSt();    }    am_ClearComputersSt();    DeleteCriticalSection(&g_stcSection);    CloseHandle(hMutex);    DestroyIcon(g_icoStop);    DestroyIcon(g_icoRun);    DestroyCursor(g_hCursorHourglass);    DestroyCursor(g_hCursorArrow);    DeleteObject(g_hBmpStart);     DeleteObject(g_hBmpStop);     CoUninitialize();    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -