移動windows桌面圖標(biāo)實現(xiàn)簡單動畫
這個操作需要關(guān)閉 桌面圖標(biāo)的自動排列
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; // 橫坐標(biāo)
int y; // 縱坐標(biāo)
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;
}