From 7ed279cfe970797e8276fb85c7b210dcea92c75a Mon Sep 17 00:00:00 2001 From: maowenrui <3505719167@qq.com> Date: Thu, 8 Oct 2026 10:00:37 +0800 Subject: [PATCH] feat tray --- Anit-Cheat_EXE/Tray.cpp | 111 ++++++++++++++++++++++++++++++++++++++++ Anit-Cheat_EXE/Tray.h | 6 +++ 2 files changed, 117 insertions(+) create mode 100644 Anit-Cheat_EXE/Tray.cpp create mode 100644 Anit-Cheat_EXE/Tray.h diff --git a/Anit-Cheat_EXE/Tray.cpp b/Anit-Cheat_EXE/Tray.cpp new file mode 100644 index 0000000..41f0275 --- /dev/null +++ b/Anit-Cheat_EXE/Tray.cpp @@ -0,0 +1,111 @@ +#include "Tray.h" +#include "resource.h" + + +HWND g_hWnd = NULL; +HICON g_hTrayIcon = NULL; +BOOL g_bIconAdded = FALSE; + +// 自定义消息,托盘通知消息 +#define WM_TRAYMESSAGE (WM_USER + 1001) + +LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + NOTIFYICONDATA nid = { 0 }; + switch (msg) + { + case WM_TRAYMESSAGE: + { + // 托盘消息 + switch (LOWORD(lParam)) + { + case WM_RBUTTONUP: + { + // 右键弹出菜单 + POINT pt; + GetCursorPos(&pt); + HMENU hMenu = CreatePopupMenu(); + AppendMenuA(hMenu, MF_STRING, 1001, "关于"); + AppendMenuA(hMenu, MF_STRING, 1002, "退出程序"); + + // 弹出菜单 + SetForegroundWindow(hWnd); + TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL); + DestroyMenu(hMenu); + break; + } + } + break; + } + case WM_COMMAND: + { + UINT cmdId = LOWORD(wParam); + if (cmdId == 1001) + { + MessageBoxA(hWnd, "ESP反挂插件\nwww.espgom.com", "", MB_OK); + } + else if (cmdId == 1002) + { + // 退出,先移除托盘图标 + nid.cbSize = sizeof(nid); + nid.hWnd = g_hWnd; + Shell_NotifyIcon(NIM_DELETE, &nid); + ExitProcess(0); + } + break; + } + case WM_DESTROY: + nid.cbSize = sizeof(nid); + nid.hWnd = g_hWnd; + Shell_NotifyIcon(NIM_DELETE, &nid); + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, msg, wParam, lParam); + } + return 0; +} + +BOOL CreateHiddenWindow() +{ + WNDCLASSEXA wc = { 0 }; + wc.cbSize = sizeof(WNDCLASSEXA); + wc.lpfnWndProc = WndProc; + wc.hInstance = GetModuleHandle(NULL); + wc.lpszClassName = "TrayWndClass"; + RegisterClassExA(&wc); + + g_hWnd = CreateWindowExA(0, wc.lpszClassName, "Tray", 0, + CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, wc.hInstance, NULL); + + // 不显示窗口(隐藏) + ShowWindow(g_hWnd, SW_HIDE); + return g_hWnd != NULL; +} +BOOL AddTrayIcon() +{ + NOTIFYICONDATAA nid = { 0 }; + nid.cbSize = sizeof(NOTIFYICONDATAA); + nid.hWnd = g_hWnd; + nid.uID = 3276147; // 图标唯一ID + nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + nid.uCallbackMessage = WM_TRAYMESSAGE; + + // 图标:可以 LoadIcon/LoadImage,也可以用自带默认图标 + // ========== 加载资源图标(托盘建议16x16) ========== + g_hTrayIcon = (HICON)LoadImageA( + GetModuleHandle(NULL), + MAKEINTRESOURCEA(IDI_ICON1), + IMAGE_ICON, + 64, 64, // 托盘标准尺寸 16*16 + LR_DEFAULTCOLOR + ); + + nid.hIcon = g_hTrayIcon; + strcpy_s(nid.szTip, "Esp Tray System"); + + BOOL ok = Shell_NotifyIconA(NIM_ADD, &nid); + if (ok) + g_bIconAdded = TRUE; + return ok; +} \ No newline at end of file diff --git a/Anit-Cheat_EXE/Tray.h b/Anit-Cheat_EXE/Tray.h new file mode 100644 index 0000000..0418e87 --- /dev/null +++ b/Anit-Cheat_EXE/Tray.h @@ -0,0 +1,6 @@ +#pragma once +#include "Base.h" + +BOOL AddTrayIcon(); + +BOOL CreateHiddenWindow(); \ No newline at end of file