zoukankan      html  css  js  c++  java
  • 控制某个程序走8字

    1.红线部分需注意下。

    #include<stdio.h>
    #include <stdlib.h>
    #include <Windows.h>
    #include <math.h>
    #define  PI 3.1415926
    #define  R 200
    
    void main()
    {
    
        int px1 = 400;
        int px2 = 800;
        int py = 500;//设定为圆心
    
        //HWND win = FindWindowA("QWidget", "Google Earth");
        HWND win = FindWindowA("Notepad", "无标题 - 记事本");    //通过spy软件搞出来的标题和类名
        if (win == NULL)
        {
            printf("can not find");
        }
        else
        {
            int angle = 0;//角度
    
            int status = 1;
    
    
            while (1)
            {
                if (angle==0)
                {
                    if (status==1)//1.0标示不同的圆上运动
                    {
                        status = 0;
                    } 
                    else
                    {
                        status = 1;
                    }
                }
                int x;
                int y;
    
                if (status==0)//顺时针移动
                {
                    x = px2 +cos(angle *PI/180)*R;
                    y = py +sin(angle *PI/180)*R;
                
                } 
                else  //逆时针移动
                {
                    x = px1 + cos(angle*PI/180)*R;
                    y = py - sin(angle*PI/180)*R;
                
                }
                //SetWindowPos(win, NULL, x, y, 500, 500, 1);//1不会改变大小
                MoveWindow(win, x, y, 300, 300, 1);//1重新绘制
    
                angle++;
                if (angle == 360)
                {
                    angle = 0;
                }
                Sleep(10);
            }
        }
        system("pause");
    }

    2. SetWindowPos(win, NULL, x, y, 500, 500, 1)和MoveWindow(win, x, y, 300, 300, 1)达到的效果是一样的。

    3.SetWindowPos(win, NULL, x, y, 500, 500, 1)中,x,y表示坐标,500,500分别表示宽和高。最后那个1不是很明白,说是不改变大小。

    4. MoveWindow(win, x, y, 300, 300, NULL)最后一项表示你的窗口是否重新绘制,在显卡的显存里边,如果设定为1就是重新绘制,通常选1.

  • 相关阅读:
    bzoj3932 [CQOI2015]任务查询系统
    bzoj1901 Zju2112 Dynamic Rankings
    bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI
    bzoj1529 [POI2005]ska Piggy banks
    bzoj1552 [Cerc2007]robotic sort
    bzoj2208 [Jsoi2010]连通数
    2016NOI冬令营day5
    A1035 Password (20)(20 分)
    1048 数字加密(20 分)
    福尔摩斯的约会
  • 原文地址:https://www.cnblogs.com/sjxbg/p/5609208.html
Copyright © 2011-2022 走看看