相关疑难解决方法(0)

如何在python中使用ctypes获取Windows窗口名称

我尝试通过长对象的句柄获取Windows窗口标题名称和pids.我的代码有效,但它有问题.当我应该获得10个或更多时,我只获得4个窗口标题.任何人都可以帮助并告诉我如何修复此代码?我认为问题在于我如何转换长对象(我不太了解它们,以及一般的ctypes).

from __future__ import print_function
from ctypes import *

psapi = windll.psapi
titles = []


# get window title from pid
def gwtfp():
    max_array = c_ulong * 4096
    pProcessIds = max_array()
    pBytesReturned = c_ulong()

    psapi.EnumProcesses(byref(pProcessIds),
                        sizeof(pProcessIds),
                        byref(pBytesReturned))

    # get the number of returned processes
    nReturned = pBytesReturned.value/sizeof(c_ulong())
    pidProcessArray = [i for i in pProcessIds][:nReturned]
    print(pidProcessArray)
    #
    EnumWindows = windll.user32.EnumWindows
    EnumWindowsProc = WINFUNCTYPE(c_bool, POINTER(c_int), POINTER(c_int))
    GetWindowText = windll.user32.GetWindowTextW
    GetWindowTextLength = windll.user32.GetWindowTextLengthW
    IsWindowVisible = windll.user32.IsWindowVisible


    for process in pidProcessArray:
        #print("Process PID %d" …
Run Code Online (Sandbox Code Playgroud)

python windows ctypes long-integer psapi

3
推荐指数
1
解决办法
4040
查看次数

标签 统计

ctypes ×1

long-integer ×1

psapi ×1

python ×1

windows ×1