亲宝软件园·资讯

展开

C语言实现窗口抖动

人气:0

#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;
}
您可能感兴趣的文章:

加载全部内容

相关教程
猜你喜欢
用户评论