c语言移动Windows桌面图标

移动windows桌面图标实现简单动画

这个操作需要关闭 桌面图标的自动排列

image.png
#include<stdio.h>
#include<windows.h>
#include<time.h>
#include<conio.h>
#include<commctrl.h>

#define N 200

typedef struct node {
    int x;  // 横坐标
    int y;  // 纵坐标
    int fx; // x 运动方向
    int fy; // y 运动方向
}Node;

int main() {
    int length, x = 60, y = 50, sum, i, weight = 1800, height = 850;
    Node nodes[N];
    HWND hwnd = FindWindow("Progman", NULL);  
    hwnd = GetWindow(hwnd, GW_CHILD);  
    hwnd = GetWindow(hwnd, GW_CHILD); 
    length = ListView_GetItemCount(hwnd);
    length = length > N ? N : length;
    for (i = 0; i < length; i++) {
        nodes[i].x = x;
        nodes[i].y = y;
        nodes[i].fx = 1;
        nodes[i].fy = 0;
        SendMessage(hwnd, LVM_SETITEMPOSITION, i, MAKELPARAM(x, y));
    }
    while(!kbhit()){
        for(sum = 1; sum < length; sum ++){
            for(i = 0; i < sum; i++ ){
                x = nodes[i].x + 60 *  nodes[i].fx;
                y = nodes[i].y + 50 *  nodes[i].fy;
                if(x > weight) {
                    nodes[i].fx = 0;
                    nodes[i].fy = 1;
                    if(y > height){
                        nodes[i].fx = -1;
                        nodes[i].fy = 0;
                    }
                }
                if(x <= 60) {
                    if(y >= height){
                        nodes[i].fy = -1;
                        nodes[i].fx = 0;
                    }
                    if(y <= 50){
                        nodes[i].fy = 0;
                        nodes[i].fx = 1;
                    }
                }
                nodes[i].x = x;
                nodes[i].y = y; 
            }
            for(i = 0; i < sum; i ++){
                x = nodes[i].x;
                y = nodes[i].y;
                SendMessage(hwnd, LVM_SETITEMPOSITION, i, MAKELPARAM(x, y));
                Sleep(2);
            }
        }
    }
    return 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • [[图片上传失败...(image-cae8e3-1541926581609)]](file://C:\Users...
    沉默的大多数1876阅读 9,010评论 0 12
  • ★Windows环境下的文件后缀名绝大多数DOS文件名后缀在Windows下继续有效,但Windows本身也引出了...
    jianghu000阅读 1,573评论 0 5
  • 你以为他是小朋友,其实他啥都懂,懂感情,有喜好。 四个月匆匆过去,对于一个不满一岁的小朋友来说,四个月的变化和成长...
    大大芳芳阅读 320评论 0 0
  • 从未像今天这样的恐慌和不安过,我找不到一点可以让自己安心的理由,包括从我自己这里。突然觉得自己很无能,连自己都照...
    那一土阅读 158评论 0 2
  • 2017年6月14日星期三 晴 自我介绍:你好,我是一名宝妈,平时上班兼职付爱宝一级代理,很高兴认识你,能交个朋友...
    未于阅读 182评论 0 1