This commit is contained in:
awin-x 2025-01-25 17:46:15 +08:00
parent 82afeb2859
commit d75488bf5b

View File

@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <queue>
using namespace Gdiplus; using namespace Gdiplus;
using namespace std; using namespace std;
#pragma comment (lib,"Gdiplus.lib") #pragma comment (lib,"Gdiplus.lib")
@ -17,10 +18,18 @@ mutex mtx;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
void CreateFullScreenTransparentWindow(const wchar_t* window_name, const wchar_t* class_name); void CreateFullScreenTransparentWindow(const wchar_t* window_name, const wchar_t* class_name);
int g_hotkeyId = 1; int g_hotkeyId = 1;
typedef struct {
int x1, y1, x2, y2;
int width;
int time;
}Vein;
queue<Vein> veins;
DWORD WINAPI eraser(LPVOID lpParam);
void vine2(int x1, int y1, float anchor, float turn, int speed, int cost, Color color, int count, int clone);
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{ {
HANDLE hMutex = CreateMutex(NULL, FALSE, L"cursorAnim"); HANDLE hMutex = CreateMutex(NULL, FALSE, L"cursorAnim");
if (hMutex == NULL) { if (hMutex == NULL) {
return 1; return 1;
@ -35,14 +44,33 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszA
HHOOK hook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0); HHOOK hook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0);
// 创建线程
HANDLE hThread = CreateThread(NULL, 0, eraser, NULL, 0, NULL);
if (hThread == NULL) {
MessageBox(nullptr, L"eraser线程启动失败", L"错误", MB_OK);
CloseHandle(hMutex);
return 1;
}
// 设置线程优先级为低
SetThreadPriority(hThread, THREAD_PRIORITY_LOWEST);
MSG msg; MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) while (GetMessage(&msg, nullptr, 0, 0))
{ {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
Sleep(1); Sleep(3);
} }
CloseHandle(hMutex); CloseHandle(hMutex);
// 等待线程结束
WaitForSingleObject(hThread, INFINITE);
// 关闭线程句柄
CloseHandle(hThread);
return 0; return 0;
} }
@ -61,7 +89,7 @@ void CreateFullScreenTransparentWindow(const wchar_t* window_name, const wchar_t
} }
hwnd = CreateWindowExW(WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW, class_name, window_name, WS_POPUP, 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), 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)-40,
nullptr, nullptr, GetModuleHandle(nullptr), nullptr); nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
if (hwnd == nullptr) if (hwnd == nullptr)
{ {
@ -103,6 +131,71 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
return 0; return 0;
} }
void vine2(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);
veins.push(Vein{x1,y1,x2,y2,speed,50});
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(vine2, 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;
vine2(x2, y2, anchor, turn, speed, cost, color, count, clone);
}
DWORD WINAPI eraser(LPVOID lpParam)
{
Pen erase(Color(255, 0, 0));
erase.SetEndCap(LineCapRound);
erase.SetStartCap(LineCapRound);
while(true)
{
if (!veins.empty())
{
veins.front().time--;
if (veins.front().time <= 0)
{
erase.SetWidth(veins.front().width * 2 + 2);
mtx.lock();
graphics->DrawLine(&erase, veins.front().x1, veins.front().y1, veins.front().x2, veins.front().y2);
veins.pop();
mtx.unlock();
}
}
else
{
Sleep(50);
}
}
}
void vine(int x1, int y1, float anchor, float turn, int speed, int cost, Color color, int count, int clone) void vine(int x1, int y1, float anchor, float turn, int speed, int cost, Color color, int count, int clone)
{ {
if (speed <= 0) if (speed <= 0)
@ -155,12 +248,23 @@ LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
POINT p; POINT p;
GetCursorPos(&p); GetCursorPos(&p);
float base = rand() % 10 / 3; float base = rand() % 10 / 3;
thread t0(vine, p.x, p.y, 0 + base, 0.02, 5, 2, Color(0, 255, 0), 0, 3); thread t0(vine2, p.x, p.y, 0 + base, 0.02, 5, 2, Color(0, 255, 0), 0, 3);
t0.detach(); t0.detach();
thread t1(vine, p.x, p.y, 2 + base, 0.010, 5, 2, Color(0, 255, 0), 0, 3); if (rand() % 3 != 0)
t1.detach(); {
thread t2(vine, p.x, p.y, -2 + base, 0.025, 5, 2, Color(0, 255, 0), 0, 3); thread t1(vine2, p.x, p.y, 2 + base, 0.010, 5, 2, Color(0, 255, 0), 0, 3);
t2.detach(); t1.detach();
}
if (rand() % 2 == 0) {
thread t2(vine2, p.x, p.y, -2 + base, 0.025, 5, 2, Color(0, 255, 0), 0, 3);
t2.detach();
}
else {
thread t3(vine2, p.x, p.y, -0.5 + base, 0.025, 5, 2, Color(0, 255, 0), 0, 3);
t3.detach();
thread t4(vine2, p.x, p.y, -3 + base, 0.025, 5, 2, Color(0, 255, 0), 0, 3);
t4.detach();
}
} }
} }
return CallNextHookEx(NULL, nCode, wParam, lParam); return CallNextHookEx(NULL, nCode, wParam, lParam);