Reputation: 3
like for maximize we can do like this
elif 'maximize' in query:
speak('Ok sir!')
user32 = ctypes.WinDLL('user32')
SW_MAXIMISE = 3
hWnd = user32.GetForegroundWindow()
user32.ShowWindow(hWnd, SW_MAXIMISE)
speak('done sir!')
Upvotes: 0
Views: 1307
Reputation: 177600
Make sure to set .argtypes
and .restype
. HWND
is defined as a pointer, and 64-bit systems will not pass or return the parameter properly as ctypes
assumes int
(32-bit) if you don't specify.
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://learn.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)
Upvotes: 1