跳到正文

个人记录

sdfhhdshfdf

SEF_711约 23 分钟
原文
文章信息与版本

文章信息

发布
2026年9月13日
收录
2026年9月13日
更新
2026年9月13日
篇幅
约 23 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<windows.h>
#include<vector>
using namespace std;
HWND hWnd=GetForegroundWindow();
int srcw=GetSystemMetrics(SM_CXSCREEN);
int srch=GetSystemMetrics(SM_CYSCREEN);
bool key[4];//WSAD
POINT mousepos;
void getkey(){
    // 32768
    srand(time(0));
    key[0] = ((rand() % 2) == 1 ? 32768 : 0);
    srand(time(0));
    key[1] = ((rand() % 2) == 1 ? 32768 : 0);
    srand(time(0));
    int x = rand() % 2;
    if (x == 1)
        key[2] = 1, key[3] = 0;
    else
        key[3] = 1, key[2] = 0;
//	key[0]=(GetAsyncKeyState('W')|GetAsyncKeyState(VK_UP))&0x8000;
//	key[1]=(GetAsyncKeyState('S')|GetAsyncKeyState(VK_DOWN))&0x8000;
//	key[2]=(GetAsyncKeyState('A')|GetAsyncKeyState(VK_LEFT))&0x8000;
//	key[3]=(GetAsyncKeyState('D')|GetAsyncKeyState(VK_RIGHT))&0x8000;
//	cout << key[2] << " " << key[3] << "\n";
}
bool inline inside(int x,int y,int w,int h,int mx,int my){
	return mx>=x&&mx<x+w&&my>=y&&my<y+h;
}
bool inline inside(int x,int l,int r){
	return x>l&&x<r;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam){
	vector<HWND>* data=reinterpret_cast<vector<HWND>*>(lParam);
	data->push_back(hwnd);
	return TRUE;
}
vector<RECT> windowsRect;
vector<HWND> hwnds;
void getWindowsRect(){
	windowsRect.clear();
	//static vector<HWND> hwnds;
	hwnds.clear();RECT rect;
	EnumWindows(EnumWindowsProc,(LPARAM)&hwnds);
	for(int i=0; i<hwnds.size(); i++) {
		HWND hwnd=hwnds[i];
		GetWindowRect(hwnd,&rect);

		char buf[256]={0};
		GetWindowText(hwnd,buf,sizeof(buf));
		LONG style=GetWindowLong(hwnd,GWL_STYLE);
		LONG exStyle=GetWindowLong(hwnd,GWL_EXSTYLE);

		bool isValid=
			IsWindowVisible(hwnd)&&		// 排除不可见窗口
			!IsIconic(hwnd)&&			// 排除最小化窗口
			(style&WS_VISIBLE)&&		// 必须包含可见样式
			!(style&WS_MINIMIZE)&&		// 排除最小化样式
			(rect.right-rect.left>5)&&	// 增加宽度阈值
			(rect.bottom-rect.top>5)&&	// 增加高度阈值
			(buf[0]!='\0')&&
			(hwnd!=hWnd);

		if(isValid) windowsRect.push_back(rect);
	}
}
int collideY(int x,int y,int w,int h){
	if(y<0) return 0;
	if(y+h>srch) return srch-h;
	for(int i=0;i<windowsRect.size();i++){
		if(inside(x,windowsRect[i].left,windowsRect[i].right)||inside(x+w,windowsRect[i].left,windowsRect[i].right)){
			if(inside(windowsRect[i].top,y,y+h)){
				if(y+h/2>windowsRect[i].top) return windowsRect[i].top;
				return windowsRect[i].top-h;
			}else if(inside(windowsRect[i].bottom,y,y+h)){
				if(y+h/2<windowsRect[i].bottom) return windowsRect[i].bottom-h;
				return windowsRect[i].bottom;
			}
		}
	}
	return -114514;
}
int collideX(int x,int y,int w,int h){
	if(x<0) return 0;
	if(x+w>srcw) return srcw-w;
	for(int i=0;i<windowsRect.size();i++){
		if(inside(windowsRect[i].top,y,y+h)||inside(windowsRect[i].bottom,y,y+h)){
			if(inside(windowsRect[i].left,x,x+w)) return windowsRect[i].left-w;
			else if(inside(windowsRect[i].right,x,x+w)) return windowsRect[i].right;
		}
	}
	return -114514;
}
bool IsMouseOverCloseButton(HWND hwnd) {
    // 获取窗口矩形
    RECT windowRect;
    GetWindowRect(hwnd, &windowRect);
    
    // 获取鼠标位置
    POINT mousePos;
    GetCursorPos(&mousePos);
    
    // 计算关闭按钮区域(通常在右上角)
    RECT closeButtonRect = {
        windowRect.right - 20,  // 假设关闭按钮宽度为20
        windowRect.top,
        windowRect.right,
        windowRect.top + 20     // 假设关闭按钮高度为20
    };
    
    // 检查鼠标是否在关闭按钮区域内
    return PtInRect(&closeButtonRect, mousePos);
}
int main(){
	cout << "                    \n";
	cout << "                    \n";
	cout << "    O( ∩ _ ∩ )O    \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
	cout << "                    ";
	int op = 60;
	float x=1,y=1,sx=0,sy=0,cx=200,cy=200,cyy=0;
	while(op --){
		getkey();
	    POINT pt;
		GetCursorPos(&mousepos);
		getWindowsRect();
		sx+=(key[3]-key[2]);sy+=0.5f;
//		    cout << x + 146 << " " << mousepos.x << "\n";
		if(mousepos.x >= x + 146 && mousepos.x <= x + 190 && mousepos.y >= y + 2 && mousepos.y <= y + 30){
		    if(x - 100 < 0){
		        x += 100;
		    }else{
		        x -= 100;
		    }
		    if(y - 100 < 0){
		        y += 100;
		    }else{
		        y -= 100;
		    }
		} 
		if(key[0])
			if(collideY(x,y,cx,cy+2)!=-114514||inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2))
				sy=-15;
		y+=sy;
		if(inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2)){ y=mousepos.y-cy;sy=0; }
		int c=collideY(x,y,cx,cy);
		if(c!=-114514){ y=c;sy=0; }
		x+=sx;
		if(inside(x,y+cy*0.2f,cx,cy*0.6f,mousepos.x,mousepos.y)){
			if(x+cx/2>mousepos.x) x=mousepos.x;
			else x=mousepos.x-cx;
			if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
		}
		c=collideX(x,y,cx,cy);
		if(c!=-114514){
			x=c;
			if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
		}
		sx*=0.9f;
		cyy+=(key[1]*cy/2-cyy)*0.5f;
		SetWindowPos(hWnd,HWND_TOPMOST,x,y+cyy,cx,cy-cyy,SWP_SHOWWINDOW);
		Sleep(20);
	}
	system("cls");
	cout << "                    \n";
	cout << "                    \n";
	cout << "Hi~ o(* ̄▽ ̄*)ブ  \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
//	cout << "                    \n";
	cout << "                    ";
	op = 100;
	while(op --){
		getkey();
	    POINT pt;
		GetCursorPos(&mousepos);
		getWindowsRect();
		sx+=(key[3]-key[2]);sy+=0.5f;
//		    cout << x + 146 << " " << mousepos.x << "\n";
		if(mousepos.x >= x + 146 && mousepos.x <= x + 190 && mousepos.y >= y + 2 && mousepos.y <= y + 30){
		    if(x - 100 < 0){
		        x += 100;
		    }else{
		        x -= 100;
		    }
		    if(y - 100 < 0){
		        y += 100;
		    }else{
		        y -= 100;
		    }
		} 
		if(key[0])
			if(collideY(x,y,cx,cy+2)!=-114514||inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2))
				sy=-15;
		y+=sy;
		if(inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2)){ y=mousepos.y-cy;sy=0; }
		int c=collideY(x,y,cx,cy);
		if(c!=-114514){ y=c;sy=0; }
		x+=sx;
		if(inside(x,y+cy*0.2f,cx,cy*0.6f,mousepos.x,mousepos.y)){
			if(x+cx/2>mousepos.x) x=mousepos.x;
			else x=mousepos.x-cx;
			if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
		}
		c=collideX(x,y,cx,cy);
		if(c!=-114514){
			x=c;
			if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
		}
		sx*=0.9f;
		cyy+=(key[1]*cy/2-cyy)*0.5f;
		SetWindowPos(hWnd,HWND_TOPMOST,x,y+cyy,cx,cy-cyy,SWP_SHOWWINDOW);
		Sleep(20);
	}
	int now_f = -1, opp = 0, f = 1, fff = 0, sum = 0;
	while(1){
		if(sum >= 5){
			system("cls");
			cout << "\n";
			cout << "I'm angry! \n";
			cout << "      (╬▔^▔)╯ \n";
			op = 200;
			sum = 0;
			while(op --){
        		getkey();
        	    POINT pt;
        		GetCursorPos(&mousepos);
        		getWindowsRect();
        		sx+=(key[3]-key[2]);sy+=0.5f;
        //		    cout << x + 146 << " " << mousepos.x << "\n";
        		if(mousepos.x >= x + 146 && mousepos.x <= x + 190 && mousepos.y >= y + 2 && mousepos.y <= y + 30){
        		    if(x - 100 < 0){
        		        x += 100;
        		    }else{
        		        x -= 100;
        		    }
        		    if(y - 100 < 0){
        		        y += 100;
        		    }else{
        		        y -= 100;
        		    }
        		} 
				if(key[0])
					if(collideY(x,y,cx,cy+2)!=-114514||inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2))
						sy=-15;
				y+=sy;
				if(inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2)){ y=mousepos.y-cy;sy=0; }
				int c=collideY(x,y,cx,cy);
				if(c!=-114514){ y=c;sy=0; }
				x+=sx;
				if(inside(x,y+cy*0.2f,cx,cy*0.6f,mousepos.x,mousepos.y)){
					if(x+cx/2>mousepos.x) x=mousepos.x;
					else x=mousepos.x-cx;
					if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
				}
				c=collideX(x,y,cx,cy);
				if(c!=-114514){
					x=c;
					if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
				}
				sx*=0.9f;
				cyy+=(key[1]*cy/2-cyy)*0.5f;
				SetWindowPos(hWnd,HWND_TOPMOST,x,y+cyy,cx,cy-cyy,SWP_SHOWWINDOW);
				Sleep(20);
			}
			now_f = -1;
			f = 1;
		}else if(opp >= 3){
//			now_f = 3; 
			opp = 0;
			system("cls");
			cout << "\n";
			cout << "                    \n";
			cout << "       ╥﹏╥ \n";
			op = 30;
			sum ++;
			while(op --){
        		getkey();
        	    POINT pt;
        		GetCursorPos(&mousepos);
        		getWindowsRect();
        		sx+=(key[3]-key[2]);sy+=0.5f;
        //		    cout << x + 146 << " " << mousepos.x << "\n";
        		if(mousepos.x >= x + 146 && mousepos.x <= x + 190 && mousepos.y >= y + 2 && mousepos.y <= y + 30){
        		    if(x - 100 < 0){
        		        x += 100;
        		    }else{
        		        x -= 100;
        		    }
        		    if(y - 100 < 0){
        		        y += 100;
        		    }else{
        		        y -= 100;
        		    }
        		} 
				if(key[0])
					if(collideY(x,y,cx,cy+2)!=-114514||inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2))
						sy=-15;
				y+=sy;
				if(inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2)){ y=mousepos.y-cy;sy=0; }
				int c=collideY(x,y,cx,cy);
				if(c!=-114514){ y=c;sy=0; }
				x+=sx;
				if(inside(x,y+cy*0.2f,cx,cy*0.6f,mousepos.x,mousepos.y)){
					if(x+cx/2>mousepos.x) x=mousepos.x;
					else x=mousepos.x-cx;
					if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
				}
				c=collideX(x,y,cx,cy);
				if(c!=-114514){
					x=c;
					if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
				}
				sx*=0.9f;
				cyy+=(key[1]*cy/2-cyy)*0.5f;
				SetWindowPos(hWnd,HWND_TOPMOST,x,y+cyy,cx,cy-cyy,SWP_SHOWWINDOW);
				Sleep(20);
			}
			now_f = -1;
			f = 1;
		}else if(y <= 200 && now_f != 1){
			now_f = 1;
			fff = 1;
			system("cls");
			cout << "\n";
			cout << "                    \n";
			cout << "       (._.`) \n";
		}else if(fff == 1 && now_f != 2 && y > 200 && y <= 300){
			now_f = 2;
			fff = 0;
			system("cls");
			cout << "\n";
			cout << "                    \n";
			cout << "       >﹏< \n";
		}else if(now_f == 2 && sy == 0){
//			now_f = 3;
			opp ++;
			if(opp == 1){
				system("cls");
				cout << "\n";
				cout << "                    \n";
				cout << "       ⊙﹏⊙ \n";
			}
		}else if(now_f == -1 && f){
			now_f = -1;
			f = 0;
			system("cls");
			cout << "                    \n";
			cout << "    \n";
			cout << "    O( ∩ _ ∩ )O    \n";
//			cout << "                    \n";0 1720
//			cout << "                    \n";1 848.5
		//	cout << "                    \n";147 878
		//	cout << "                    \n";191 878
		//	cout << "                    \n";147 850
		//	cout << "                    \n";191 850
			cout << "                    ";
		}
		getkey();
	    POINT pt;
		GetCursorPos(&mousepos);
		getWindowsRect();
		sx+=(key[3]-key[2]);sy+=0.5f;
//		    cout << x + 146 << " " << mousepos.x << "\n";
		if(mousepos.x >= x + 146 && mousepos.x <= x + 190 && mousepos.y >= y + 2 && mousepos.y <= y + 30){
		    if(x - 100 < 0){
		        x += 100;
		    }else{
		        x -= 100;
		    }
		    if(y - 100 < 0){
		        y += 100;
		    }else{
		        y -= 100;
		    }
		} 
		if(key[0])
			if(collideY(x,y,cx,cy+2)!=-114514||inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2))
				sy=-15;
		y+=sy;
		if(inside(x,y+cy*0.8f,cx,cy*0.2f,mousepos.x,mousepos.y-2)){ y=mousepos.y-cy;sy=0; }
		int c=collideY(x,y,cx,cy);
		if(c!=-114514){ y=c;sy=0; }
		x+=sx;
		if(inside(x,y+cy*0.2f,cx,cy*0.6f,mousepos.x,mousepos.y)){
			if(x+cx/2>mousepos.x) x=mousepos.x;
			else x=mousepos.x-cx;
			if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
		}
		c=collideX(x,y,cx,cy);
		if(c!=-114514){
			x=c;
			if(key[0]){ sy=-15;sx=sx<0?10:-10; }else sx=0;
		}
		sx*=0.9f;
		cyy+=(key[1]*cy/2-cyy)*0.5f;
		SetWindowPos(hWnd,HWND_TOPMOST,x,y+cyy,cx,cy-cyy,SWP_SHOWWINDOW);
		Sleep(20);
	}
	return 0;
}
原文