本文实例为大家分享了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;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持悠悠之家。

点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部