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閱讀 8,913評論 0 12
  • ★Windows環境下的文件后綴名絕大多數DOS文件名后綴在Windows下繼續有效,但Windows本身也引出了...
    jianghu000閱讀 1,522評論 0 5
  • 你以為他是小朋友,其實他啥都懂,懂感情,有喜好。 四個月匆匆過去,對于一個不滿一歲的小朋友來說,四個月的變化和成長...
    大大芳芳閱讀 270評論 0 0
  • 從未像今天這樣的恐慌和不安過,我找不到一點可以讓自己安心的理由,包括從我自己這里。突然覺得自己很無能,連自己都照...
    那一土閱讀 152評論 0 2
  • 2017年6月14日星期三 晴 自我介紹:你好,我是一名寶媽,平時上班兼職付愛寶一級代理,很高興認識你,能交個朋友...
    未于閱讀 164評論 0 1