天天看点

用C语言实现窗口抖动

#include "stdafx.h"
#include <stdio.h>
#include<Windows.h>
int main()
{

    int shake_time = 50; //休眠的时间,为5毫秒
    int shake_distance = 10; //移动了10像素
    RECT rect; //RECT是一个矩形结构体,相当于保存了一个矩形的四条边的坐标
    HWND window = NULL, oldwindow = NULL; //两个窗口句柄
    int x, y, width, height; //用来保存窗口横纵坐标和宽度、高度的变量
    int i;
    //抖50次吧
    for (i = 0; i < 10; i++) {
        window = GetForegroundWindow(); //拿到活动窗口
        if (window != oldwindow) {
            //获取指定窗口的位置
            GetWindowRect(window, &rect);
            x = rect.left;
            y = rect.top;
            width = rect.right - x;
            height = rect.bottom - y;
            oldwindow = window;
        }
        MoveWindow(window, x - shake_distance, y, width, height, TRUE); //移动窗口,向左移动了10像素,下同
        Sleep(shake_time);  //休眠time毫秒,线程休眠
        MoveWindow(window, x - shake_distance, y - shake_distance, width, height, TRUE);
        Sleep(shake_time);
        MoveWindow(window, x, y - shake_distance, width, height, TRUE);
        Sleep(shake_time);
        MoveWindow(window, x, y, width, height, TRUE);
        Sleep(shake_time);
    }
    return 0;
}      

网名:浩秦;

邮箱:root#landv.pw;

只要我能控制一個國家的貨幣發行,我不在乎誰制定法律。金錢一旦作響,壞話隨之戛然而止。

上一篇: java修饰符
下一篇: Java基本语法

继续阅读