私はPythonアプリケーションを開発していて、HWND
開いている各ウィンドウを取得したいと思っています。ウィンドウの名前とHWND
、リストをフィルタリングして特定のウィンドウを管理し、それらを移動およびサイズ変更する必要があります。
私は自分で情報を探してそれをやろうとしましたが、正しいコードを取得できませんでした。このコードを試してみましたが、各ウィンドウのタイトルしか取得できません(これはすばらしいことです)が、必要なこともありHWND
ます。
import ctypes
import win32gui
EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible
titles = []
def foreach_window(hwnd, lParam):
if IsWindowVisible(hwnd):
length = GetWindowTextLength(hwnd)
buff = ctypes.create_unicode_buffer(length + 1)
GetWindowText(hwnd, buff, length + 1)
titles.append((hwnd, buff.value))
return True
EnumWindows(EnumWindowsProc(foreach_window), 0)
for i in range(len(titles)):
print(titles)[i]
win32gui.MoveWindow((titles)[5][0], 0, 0, 760, 500, True)
ここにエラーがあります:
win32gui.MoveWindow((titles)[5][0], 0, 0, 760, 500, True)
TypeError: The object is not a PyHANDLE object