如何使用 python 移动桌面图标?

How to move desktop icons with python?

我正在制作一个 python 程序,该程序使用 LVM_SETITEMPOSITIONwinapi 移动桌面图标,但我遇到 commctrl.LVM_SETITEMPOSITION 的问题,它给了我一个错误 'int' object is not callable。这是我的代码:

import win32gui
import commctrl
from time import sleep
from ctypes import wintypes

hd = wintypes.HWND

hd = win32gui.FindWindow("Progman", None)
hd = win32gui.FindWindowEx(hd, 0, "SHELLDLL_DefView", None)
hd = win32gui.FindWindowEx(hd, 0, "SysListView32", None)

i = 0
while i < 1000:
  commctrl.LVM_SETITEMPOSITION(hd, 0, i, i)
  i+100
  sleep(1)

对不起,我在[MS.Docs]: LVM_SETITEMPOSITION message中读错了WORD(如DWORD),所以我向左移动了太多。
这是一个工作示例(应该将项目移动到桌面的前导对角线上)。

code00.py:

#!/usr/bin/env python

import msvcrt
import sys
import time

import commctrl as cc
import win32gui as wgui


def main(*argv):
    search_criteria = (
        (0, "Progman", None),
        (0, "SHELLDLL_DefView", None),
        (0, "SysListView32", None),
    )
    wnd = 0
    for crit in search_criteria:
        wnd = wgui.FindWindowEx(wnd, *crit)
        if wnd == 0:
            print("Could not find child matching criteria: {:}".format(crit))
            return
    idx = 0
    for i in range(0, 1000, 16):
        lparam = (i << 16) | i
        print("{:d} - 0x{:08X}".format(i, lparam))
        wgui.SendMessage(wnd, cc.LVM_SETITEMPOSITION, idx, lparam)
        time.sleep(0.5)
        if msvcrt.kbhit():
            break


if __name__ == "__main__":
    print("Python {:s} {:03d}bit on {:s}\n".format(" ".join(elem.strip() for elem in sys.version.split("\n")),
                                                   64 if sys.maxsize > 0x100000000 else 32, sys.platform))
    rc = main(*sys.argv[1:])
    print("\nDone.")
    sys.exit(rc)