如何在 python 中使用 Ctypes 最小化 window
How to minimize window using Ctypes in python
喜欢最大化我们可以这样做
elif 'maximize' 在查询中:
speak('Ok sir!')
user32 = ctypes.WinDLL('user32')
SW_MAXIMISE = 3
hWnd = user32.GetForegroundWindow()
user32.ShowWindow(hWnd, SW_MAXIMISE)
speak('done sir!')
确保设置 .argtypes
和 .restype
。 HWND
被定义为指针,64 位系统将不会正确传递或 return 参数,因为 ctypes
假设 int
(32 位),如果你不这样做指定。
import ctypes
from ctypes import wintypes as w
user32 = ctypes.WinDLL('user32')
user32.GetForegroundWindow.argtypes = ()
user32.GetForegroundWindow.restype = w.HWND
user32.ShowWindow.argtypes = w.HWND,w.BOOL
user32.ShowWindow.restype = w.BOOL
# From https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
hWnd = user32.GetForegroundWindow()
user32.ShowWindow(hWnd, SW_MINIMIZE)
喜欢最大化我们可以这样做
elif 'maximize' 在查询中:
speak('Ok sir!')
user32 = ctypes.WinDLL('user32')
SW_MAXIMISE = 3
hWnd = user32.GetForegroundWindow()
user32.ShowWindow(hWnd, SW_MAXIMISE)
speak('done sir!')
确保设置 .argtypes
和 .restype
。 HWND
被定义为指针,64 位系统将不会正确传递或 return 参数,因为 ctypes
假设 int
(32 位),如果你不这样做指定。
import ctypes
from ctypes import wintypes as w
user32 = ctypes.WinDLL('user32')
user32.GetForegroundWindow.argtypes = ()
user32.GetForegroundWindow.restype = w.HWND
user32.ShowWindow.argtypes = w.HWND,w.BOOL
user32.ShowWindow.restype = w.BOOL
# From https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
hWnd = user32.GetForegroundWindow()
user32.ShowWindow(hWnd, SW_MINIMIZE)