From 78f3996215a1f6a2f2373c87e557a2adfc7f8b38 Mon Sep 17 00:00:00 2001 From: awinx Date: Sat, 25 Jan 2025 16:58:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- veinCur.cpp | 167 ++++++++++++++++++++++++++++++++++++++++ veinCur.sln | 31 ++++++++ veinCur.vcxproj | 135 ++++++++++++++++++++++++++++++++ veinCur.vcxproj.filters | 22 ++++++ 4 files changed, 355 insertions(+) create mode 100644 veinCur.cpp create mode 100644 veinCur.sln create mode 100644 veinCur.vcxproj create mode 100644 veinCur.vcxproj.filters diff --git a/veinCur.cpp b/veinCur.cpp new file mode 100644 index 0000000..c75e575 --- /dev/null +++ b/veinCur.cpp @@ -0,0 +1,167 @@ +#include +#include +#include +#include +#include +using namespace Gdiplus; +using namespace std; +#pragma comment (lib,"Gdiplus.lib") + +LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam); + +Gdiplus::Graphics* graphics; +ULONG_PTR gdiplusToken; +HWND hwnd; +mutex mtx; + +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); +void CreateFullScreenTransparentWindow(const wchar_t* window_name, const wchar_t* class_name); +int g_hotkeyId = 1; + +int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) +{ + + HANDLE hMutex = CreateMutex(NULL, FALSE, L"cursorAnim"); + if (hMutex == NULL) { + return 1; + } + if (GetLastError() == ERROR_ALREADY_EXISTS) { + MessageBox(nullptr, L"已运行", L"错误", MB_OK); + CloseHandle(hMutex); + return 1; + } + + CreateFullScreenTransparentWindow(L"鼠标特效", L"cursor_anim"); + HHOOK hook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0); + + + MSG msg; + while (GetMessage(&msg, nullptr, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + Sleep(1); + } + CloseHandle(hMutex); + return 0; +} + +void CreateFullScreenTransparentWindow(const wchar_t* window_name, const wchar_t* class_name) +{ + WNDCLASS wc = {}; + wc.lpfnWndProc = WndProc; + wc.hInstance = GetModuleHandle(nullptr); + wc.lpszClassName = class_name; + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(255, 0, 0)); + if (!RegisterClass(&wc)) + { + MessageBox(nullptr, L"窗口类注册失败", L"错误", MB_OK); + return; + } + + hwnd = CreateWindowExW(WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW, class_name, window_name, WS_POPUP, + 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), + nullptr, nullptr, GetModuleHandle(nullptr), nullptr); + if (hwnd == nullptr) + { + MessageBox(nullptr, L"窗口创建失败", L"错误", MB_OK); + return; + } + + SetLayeredWindowAttributes(hwnd, RGB(255, 0, 0), 100, LWA_COLORKEY); + ShowWindow(hwnd, SW_SHOW); + UpdateWindow(hwnd); +} + + +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) +{ + switch (message) + { + case WM_CREATE: + { + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); + graphics = new Gdiplus::Graphics(hwnd); + break; + } + case WM_TIMER: + break; + case WM_DESTROY: + { + MessageBox(nullptr, L"关闭", L"关闭", MB_OK); + delete graphics; + UnregisterHotKey(hwnd, g_hotkeyId); + Gdiplus::GdiplusShutdown(gdiplusToken); + PostQuitMessage(0); + break; + } + default: + return DefWindowProc(hwnd, message, wparam, lparam); + } + return 0; +} + +void vine(int x1, int y1, float anchor, float turn, int speed, int cost, Color color, int count, int clone) +{ + if (speed <= 0) + { + Sleep(300); + return; + } + count++; + int x2 = x1 + (speed)*cos(anchor); + int y2 = y1 + (speed)*sin(anchor); + Pen penline(color, speed); + penline.SetEndCap(LineCapRound); + penline.SetStartCap(LineCapRound); + mtx.lock(); + graphics->DrawLine(&penline, x1, y1, x2, y2); + mtx.unlock(); + Sleep(1); + if (clone > 0 && rand() % 10 == 0) + { + int x_copy = x1; + int y_copy = y1; + float anchor_copy = anchor + rand() % 10 / 26.0; + float turn_copy = turn * (-1 + rand() % 2 * 2); + int speed_copy = speed + rand() % 3; + int cost_copy = cost + rand() % 3; + thread t(vine, x_copy, y_copy, anchor_copy, turn_copy, speed_copy, cost_copy, Color(rand() % 50, 100 + rand() % 100, 20 + rand() % 50), 0, --clone); + t.detach(); + } + if (count % 10 == 0) + speed -= cost; + anchor += turn; + if (count % 3 == 0) + turn += turn / 2; + if (turn > 0.6) + speed = 0; + vine(x2, y2, anchor, turn, speed, cost, color, count, clone); + Sleep(count / 3); + Pen erase(Color(255, 0, 0), speed * 2 + 3); + erase.SetEndCap(LineCapRound); + erase.SetStartCap(LineCapRound); + mtx.lock(); + graphics->DrawLine(&erase, x1, y1, x2, y2); + mtx.unlock(); +} + +LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) { + if (nCode >= 0) { + if (wParam == WM_LBUTTONDOWN) { + // 获取鼠标点击位置 + POINT p; + GetCursorPos(&p); + float base = rand() % 10 / 3; + thread t0(vine, p.x, p.y, 0 + base, 0.02, 5, 2, Color(0, 255, 0), 0, 3); + t0.detach(); + thread t1(vine, p.x, p.y, 2 + base, 0.010, 5, 2, Color(0, 255, 0), 0, 3); + t1.detach(); + thread t2(vine, p.x, p.y, -2 + base, 0.025, 5, 2, Color(0, 255, 0), 0, 3); + t2.detach(); + } + } + return CallNextHookEx(NULL, nCode, wParam, lParam); +} diff --git a/veinCur.sln b/veinCur.sln new file mode 100644 index 0000000..626791e --- /dev/null +++ b/veinCur.sln @@ -0,0 +1,31 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35312.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "veinCur", "veinCur.vcxproj", "{7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Debug|x64.ActiveCfg = Debug|x64 + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Debug|x64.Build.0 = Debug|x64 + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Debug|x86.ActiveCfg = Debug|Win32 + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Debug|x86.Build.0 = Debug|Win32 + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Release|x64.ActiveCfg = Release|x64 + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Release|x64.Build.0 = Release|x64 + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Release|x86.ActiveCfg = Release|Win32 + {7850B2FB-9E7D-4A88-A226-1B6C70D3F5C9}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B17741C1-FBB6-41B2-A947-FCD09A623D05} + EndGlobalSection +EndGlobal diff --git a/veinCur.vcxproj b/veinCur.vcxproj new file mode 100644 index 0000000..7176d0e --- /dev/null +++ b/veinCur.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {7850b2fb-9e7d-4a88-a226-1b6c70d3f5c9} + veinCur + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/veinCur.vcxproj.filters b/veinCur.vcxproj.filters new file mode 100644 index 0000000..0653f8d --- /dev/null +++ b/veinCur.vcxproj.filters @@ -0,0 +1,22 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + \ No newline at end of file