我正在尝试使用 ctypes.windll.user32.GetWindowThreadProcessId 获取 proccessId,但打印与任务管理器中看到的 PID 不匹配。这是代码
import ctypes
from ctypes import windll
import time
time.sleep(2)
hwnd = windll.user32.GetForegroundWindow()
pid = ctypes.c_ulong()
GetWindowThreadProcessId =ctypes.windll.user32.GetWindowThreadProcessId(hwnd,pid)
print GetWindowThreadProcessId
请您参考如下方法:
对第二个参数使用'byref',像这样:
lpdw_process_id = ctypes.c_ulong()
result = user32.GetWindowThreadProcessId(h_wnd, ctypes.byref(lpdw_process_id))
process_id = lpdw_process_id.value
