时间:2021-02-15 10:20:17 | 栏目:C代码 | 点击:次
本文实例为大家分享了C语言给QQ好友发窗口抖动的具体代码,供大家参考,具体内容如下
1.首先来个简单点的,抖动当前窗口,代码如下:
#include <stdio.h> #include <windows.h> int main (int argc, char argv[]) { HWND hwnd = NULL; int x,y,width,height; int i; RECT rect; hwnd = GetForegroundWindow();//获取当前窗口 GetClientRect(hwnd,&rect);//获取当前窗口区域 x = rect.left; y = rect.top; width = rect.right - x; height = rect.bottom - y; if(hwnd != NULL) { for(i=0;i<50;i++)//抖动50次 { MoveWindow(hwnd,x-10,y,width,height,true); Sleep(5); MoveWindow(hwnd,x-10,y-10,width,height,true); Sleep(5); MoveWindow(hwnd,x,y-10,width,height,true); Sleep(5); MoveWindow(hwnd,x,y,width,height,true); Sleep(5); Sleep(2000);//每个半秒抖动一次 } } return 0; }
这段代码可以使当前窗口每隔2秒抖动一次。
2. 再来个复杂点的,自动给指定QQ好友发送窗口抖动
#include <stdio.h> #include <windows.h> int main (int argc, char argv[]) { HWND hwnd = NULL; RECT rect; TCHAR pQQName[20]=TEXT("闹眼子的");//好友呢称,首先需要将好友窗口在任务拦显示 hwnd = FindWindow(NULL,pQQName);//获取窗口 if(hwnd!=NULL) { SetForegroundWindow(hwnd);//设为前端窗口 GetWindowRect(hwnd, &rect); while(1) { SetCursorPos(103+rect.left,390+rect.top); mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); Sleep(10050); hwnd = FindWindow(NULL,pQQName);//获取窗口 SetForegroundWindow(hwnd);//设为前端窗口 GetWindowRect(hwnd, &rect); } } return 0; }