美文网首页
c语言移动Windows桌面图标

c语言移动Windows桌面图标

作者: Luxin23 | 来源:发表于2019-06-19 16:24 被阅读0次

    移动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;
    }
    

    相关文章

      网友评论

          本文标题:c语言移动Windows桌面图标

          本文链接:https://www.haomeiwen.com/subject/ievkqctx.html