Skip to content

Instantly share code, notes, and snippets.

@Crozzers
Created June 8, 2024 15:49
Show Gist options
  • Save Crozzers/0362f37422429fcd1c2f66e7569dcd59 to your computer and use it in GitHub Desktop.
Save Crozzers/0362f37422429fcd1c2f66e7569dcd59 to your computer and use it in GitHub Desktop.
Short snippet for exposing the IsWindowArranged win32 function in Python
import win32api
import ctypes
user32 = win32api.LoadLibrary('User32.dll')
# IsWindowArranged doesn't have a header file, so I assume that's why it's not exposed in win32api (py version).
# We can still access that function by getting it's address with ctypes.
# See https://learn.microsoft.com/en-us/windows/win32/winmsg/winuser/nf-winuser-iswindowarranged#remarks
# get function address
_iwa_addr = win32api.GetProcAddress(user32, 'IsWindowArranged')
# create prototype for said function
_iwa_proto = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_int)
# initialise prototype at that address
IsWindowArranged = _iwa_proto(_iwa_addr)
'''
Check whether a window is arranged (snapped).
Args:
hwnd (int): the handle of the window to be checked
Returns:
Nonzero value for snapped windows, zero otherwise. Can basically be treated as a bool.
See: https://learn.microsoft.com/en-us/windows/win32/winmsg/winuser/nf-winuser-iswindowarranged
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment