我正在制作一個 python 程式,它使用LVM_SETITEMPOSITIONfrom移動桌面圖示,winapi但我遇到了問題,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)
uj5u.com熱心網友回復:
抱歉,我誤讀了[MS.Docs]: LVM_SETITEMPOSITION message中的WORD (as DWORD ) ,所以我向左移動了太多。這是一個作業示例(應該將專案移動到桌面上的前對角線上)。
代碼00.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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/463093.html
