仅仅让黑窗口抖动以供小白娱乐
1 #include<stdio.h> 2 #include<windows.h> 3 4 int main() 5 { 6 RECT rect;//RECT定义了一个矩形结构体,存储矩形边框 7 HWND hwnd = NULL, oldhwnd = NULL;//窗口句柄 8 9 int x, y, width, height; 10 int i; 11 12 system("title Hello World!");//标题:Hello World 13 14 for (i = 0; i < 50; i++) 15 { 16 hwnd = GetForegroundWindow();//获取活动窗口的句柄 17 18 if (hwnd != oldhwnd) 19 { 20 GetWindowRect(hwnd, &rect);//获取指定窗口位置 21 x = rect.left; 22 y = rect.top; 23 width = rect.right - x; 24 height = rect.bottom - y; 25 oldhwnd = hwnd;//保存新获取的句柄窗口 26 } 27 28 MoveWindow(hwnd, x - 5, y, width, height, TRUE); 29 Sleep(20); 30 MoveWindow(hwnd, x - 5, y-5, width, height, TRUE); 31 Sleep(20); 32 MoveWindow(hwnd, x , y-5, width, height, TRUE); 33 Sleep(20); 34 MoveWindow(hwnd, x , y, width, height, TRUE); 35 Sleep(20); 36 37 system("cls");//刷新缓冲区 38 printf("对方给您发送了一个加长版窗口抖动 "); 39 } 40 41 return 0; 42 }