@ -31,192 +31,678 @@
""" Defines Windows(tm) functions """
""" Defines Windows(tm) functions """
import ctypes
from ctypes import LibraryLoader
from ctypes import WinDLL
from ctypes import wintypes
from ctypes import wintypes
from . import win32defines , win32structures
from . import win32defines , win32structures
from . actionlogger import ActionLogger
from . actionlogger import ActionLogger
from ctypes import c_uint , c_short , c_long
from ctypes import c_short
from ctypes import WINFUNCTYPE
from ctypes import c_void_p
from ctypes import c_int
from ctypes import byref
from ctypes import POINTER
from ctypes import c_ubyte
from ctypes import c_size_t
# Quote: "If you want cached libs without polluting ctypes.cdll or
# ctypes.windll, just create your own instance such as
# windll = ctypes.LibraryLoader(ctypes.WinDLL)."
# see https://bugs.python.org/issue22552
windll = LibraryLoader ( WinDLL )
import sys
if sys . platform == " cygwin " :
windll = ctypes . cdll
HRESULT = c_long
UINT = c_uint
SHORT = c_short
SHORT = c_short
CreateBrushIndirect = ctypes . windll . gdi32 . CreateBrushIndirect
CreateBrushIndirect = windll . gdi32 . CreateBrushIndirect
CreateDC = ctypes . windll . gdi32 . CreateDCW
CreateBrushIndirect . restype = wintypes . HBRUSH
CreateFontIndirect = ctypes . windll . gdi32 . CreateFontIndirectW
CreateBrushIndirect . argtypes = [
CreatePen = ctypes . windll . gdi32 . CreatePen
c_void_p ,
DeleteDC = ctypes . windll . gdi32 . DeleteDC
]
GetObject = ctypes . windll . gdi32 . GetObjectW
CreateDC = windll . gdi32 . CreateDCW
DeleteObject = ctypes . windll . gdi32 . DeleteObject
CreateDC . restype = wintypes . HDC
DrawText = ctypes . windll . user32 . DrawTextW
CreateDC . argtypes = [
TextOut = ctypes . windll . gdi32 . TextOutW
wintypes . LPCWSTR ,
Rectangle = ctypes . windll . gdi32 . Rectangle
wintypes . LPCWSTR ,
SelectObject = ctypes . windll . gdi32 . SelectObject
wintypes . LPCWSTR ,
GetStockObject = ctypes . windll . gdi32 . GetStockObject
c_void_p ,
GetSystemMetrics = ctypes . windll . user32 . GetSystemMetrics
]
GetSystemMetrics . restype = ctypes . c_int
CreateFontIndirect = windll . gdi32 . CreateFontIndirectW
GetSystemMetrics . argtypes = ( ctypes . c_int , )
CreateFontIndirect . restype = wintypes . HFONT
GetTextMetrics = ctypes . windll . gdi32 . GetTextMetricsW
CreateFontIndirect . argtypes = [
POINTER ( win32structures . LOGFONTW ) ,
]
EnumChildWindows = ctypes . windll . user32 . EnumChildWindows
CreatePen = windll . gdi32 . CreatePen
EnumDesktopWindows = ctypes . windll . user32 . EnumDesktopWindows
CreatePen . restype = wintypes . HPEN
EnumWindows = ctypes . windll . user32 . EnumWindows
CreatePen . argtypes = [
GetDC = ctypes . windll . user32 . GetDC
c_int ,
GetDesktopWindow = ctypes . windll . user32 . GetDesktopWindow
c_int ,
wintypes . COLORREF ,
]
SendInput = ctypes . windll . user32 . SendInput
DeleteDC = windll . gdi32 . DeleteDC
SetCursorPos = ctypes . windll . user32 . SetCursorPos
DeleteDC . restype = wintypes . BOOL
GetCursorPos = ctypes . windll . user32 . GetCursorPos
DeleteDC . argtypes = [
GetCaretPos = ctypes . windll . user32 . GetCaretPos
wintypes . HDC ,
]
GetObject = windll . gdi32 . GetObjectW
GetObject . restype = c_int
GetObject . argtypes = [
wintypes . HANDLE ,
c_int ,
wintypes . LPVOID ,
]
DeleteObject = windll . gdi32 . DeleteObject
DeleteObject . restype = wintypes . BOOL
DeleteObject . argtypes = [
wintypes . HGDIOBJ ,
]
DrawText = windll . user32 . DrawTextW
DrawText . restype = c_int
DrawText . argtypes = [
wintypes . HDC ,
wintypes . LPCWSTR ,
c_int ,
POINTER ( wintypes . RECT ) ,
wintypes . UINT ,
]
TextOut = windll . gdi32 . TextOutW
TextOut . restype = wintypes . BOOL
TextOut . argtypes = [
wintypes . HDC ,
c_int ,
c_int ,
wintypes . LPCWSTR ,
c_int ,
]
Rectangle = windll . gdi32 . Rectangle
Rectangle . restype = wintypes . BOOL
Rectangle . argtypes = [
wintypes . HDC ,
c_int ,
c_int ,
c_int ,
c_int ,
]
SelectObject = windll . gdi32 . SelectObject
SelectObject . restype = wintypes . HGDIOBJ
SelectObject . argtypes = [
wintypes . HDC ,
wintypes . HGDIOBJ ,
]
GetStockObject = windll . gdi32 . GetStockObject
GetStockObject . restype = wintypes . HGDIOBJ
GetStockObject . argtypes = [
c_int ,
]
GetSystemMetrics = windll . user32 . GetSystemMetrics
GetSystemMetrics . restype = c_int
GetSystemMetrics . argtypes = [
c_int ,
]
GetTextMetrics = windll . gdi32 . GetTextMetricsW
GetTextMetrics . restype = wintypes . BOOL
GetTextMetrics . argtypes = [
wintypes . HDC ,
POINTER ( win32structures . TEXTMETRICW ) ,
]
EnumChildWindows = windll . user32 . EnumChildWindows
EnumChildWindows . restype = wintypes . BOOL
EnumChildWindows . argtypes = [
wintypes . HWND ,
WINFUNCTYPE ( wintypes . BOOL , wintypes . HWND , wintypes . LPARAM ) ,
wintypes . LPARAM ,
]
EnumDesktopWindows = windll . user32 . EnumDesktopWindows
EnumDesktopWindows . restype = wintypes . BOOL
EnumDesktopWindows . argtypes = [
wintypes . LPVOID ,
WINFUNCTYPE ( wintypes . BOOL , wintypes . HWND , wintypes . LPARAM ) ,
wintypes . LPARAM ,
]
EnumWindows = windll . user32 . EnumWindows
EnumWindows . restype = wintypes . BOOL
EnumWindows . argtypes = [
WINFUNCTYPE ( wintypes . BOOL , wintypes . HWND , wintypes . LPARAM ) ,
wintypes . LPARAM ,
]
GetDC = windll . user32 . GetDC
GetDC . restype = wintypes . LPVOID
GetDC . argtypes = [
wintypes . HWND ,
]
GetDesktopWindow = windll . user32 . GetDesktopWindow
GetDesktopWindow . restype = wintypes . HWND
GetDesktopWindow . argtypes = [
]
SendInput = windll . user32 . SendInput
SendInput . restype = wintypes . UINT
SendInput . argtypes = [
wintypes . UINT ,
c_void_p , # using POINTER(win32structures.INPUT) needs rework in keyboard.py
c_int ,
]
SetCursorPos = windll . user32 . SetCursorPos
SetCursorPos . restype = wintypes . BOOL
SetCursorPos . argtypes = [
c_int ,
c_int ,
]
GetCursorPos = windll . user32 . GetCursorPos
GetCursorPos . restype = wintypes . BOOL
GetCursorPos . argtypes = [
POINTER ( wintypes . POINT ) ,
]
GetCaretPos = windll . user32 . GetCaretPos
GetCaretPos . restype = wintypes . BOOL
GetCaretPos . argtypes = [
POINTER ( wintypes . POINT ) ,
]
GetKeyboardState = windll . user32 . GetKeyboardState
GetKeyboardState . restype = wintypes . BOOL
GetKeyboardState . argtypes = [
POINTER ( c_ubyte ) ,
]
SetKeyboardState = windll . user32 . SetKeyboardState
SetKeyboardState . restype = wintypes . BOOL
SetKeyboardState . argtypes = [
POINTER ( c_ubyte ) ,
]
GetKeyboardLayout = windll . user32 . GetKeyboardLayout
GetKeyboardLayout . restype = wintypes . HKL
GetKeyboardLayout . argtypes = [
wintypes . DWORD ,
]
VkKeyScanW = windll . user32 . VkKeyScanW
VkKeyScanW . restype = SHORT
VkKeyScanW . argtypes = [
wintypes . WCHAR ,
]
VkKeyScanExW = windll . user32 . VkKeyScanExW
VkKeyScanExW . restype = SHORT
VkKeyScanExW . argtypes = [
wintypes . WCHAR ,
wintypes . HKL ,
]
GetMessageExtraInfo = windll . user32 . GetMessageExtraInfo
MapVirtualKeyW = windll . user32 . MapVirtualKeyW
# menu functions
# menu functions
DrawMenuBar = ctypes . windll . user32 . DrawMenuBar
DrawMenuBar = windll . user32 . DrawMenuBar
GetMenu = ctypes . windll . user32 . GetMenu
DrawMenuBar . restype = wintypes . BOOL
GetMenuBarInfo = ctypes . windll . user32 . GetMenuBarInfo
DrawMenuBar . argstype = [
GetMenuInfo = ctypes . windll . user32 . GetMenuInfo
wintypes . HWND ,
GetMenuItemCount = ctypes . windll . user32 . GetMenuItemCount
]
GetMenuItemInfo = ctypes . windll . user32 . GetMenuItemInfoW
GetMenu = windll . user32 . GetMenu
SetMenuItemInfo = ctypes . windll . user32 . SetMenuItemInfoW
GetMenu . restype = wintypes . HMENU
GetMenuItemRect = ctypes . windll . user32 . GetMenuItemRect
GetMenu . argtypes = [
CheckMenuItem = ctypes . windll . user32 . CheckMenuItem
wintypes . HWND ,
GetMenuState = ctypes . windll . user32 . GetMenuState
]
GetSubMenu = ctypes . windll . user32 . GetSubMenu
GetMenuBarInfo = windll . user32 . GetMenuBarInfo
GetSystemMenu = ctypes . windll . user32 . GetSystemMenu
GetMenuBarInfo . restype = wintypes . BOOL
HiliteMenuItem = ctypes . windll . user32 . HiliteMenuItem
GetMenuBarInfo . argtypes = [
IsMenu = ctypes . windll . user32 . IsMenu
wintypes . HWND ,
MenuItemFromPoint = ctypes . windll . user32 . MenuItemFromPoint
wintypes . LONG ,
wintypes . LONG ,
BringWindowToTop = ctypes . windll . user32 . BringWindowToTop
POINTER ( win32structures . MENUBARINFO ) ,
]
GetVersion = ctypes . windll . kernel32 . GetVersion
GetMenuInfo = windll . user32 . GetMenuInfo
GetMenuInfo . restype = wintypes . BOOL
GetParent = ctypes . windll . user32 . GetParent
GetMenuInfo . argtypes = [
GetWindow = ctypes . windll . user32 . GetWindow
wintypes . HWND ,
ShowWindow = ctypes . windll . user32 . ShowWindow
POINTER ( win32structures . MENUINFO ) ,
GetWindowContextHelpId = ctypes . windll . user32 . GetWindowContextHelpId
]
GetWindowLong = ctypes . windll . user32 . GetWindowLongW
GetMenuItemCount = windll . user32 . GetMenuItemCount
GetWindowPlacement = ctypes . windll . user32 . GetWindowPlacement
GetMenuItemCount . restype = c_int
GetWindowRect = ctypes . windll . user32 . GetWindowRect
GetMenuItemCount . argtypes = [
GetWindowText = ctypes . windll . user32 . GetWindowTextW
wintypes . HMENU ,
GetWindowTextLength = ctypes . windll . user32 . GetWindowTextLengthW
]
GetClassName = ctypes . windll . user32 . GetClassNameW
GetMenuItemInfo = windll . user32 . GetMenuItemInfoW
GetClassName . argtypes = [ win32structures . HWND , wintypes . LPWSTR , ctypes . c_int ]
GetMenuItemInfo . restype = wintypes . BOOL
GetClassName . restrype = ctypes . c_int
GetMenuItemInfo . argtypes = [
GetClientRect = ctypes . windll . user32 . GetClientRect
wintypes . HMENU ,
IsChild = ctypes . windll . user32 . IsChild
wintypes . UINT ,
IsWindow = ctypes . windll . user32 . IsWindow
wintypes . BOOL ,
IsWindow . argtypes = [ win32structures . HWND ]
POINTER ( win32structures . MENUITEMINFOW ) ,
IsWindow . restype = win32structures . BOOL
]
IsWindowUnicode = ctypes . windll . user32 . IsWindowUnicode
SetMenuItemInfo = windll . user32 . SetMenuItemInfoW
IsWindowUnicode . argtypes = [ win32structures . HWND ]
SetMenuItemInfo . restype = wintypes . BOOL
IsWindowUnicode . restype = win32structures . BOOL
SetMenuItemInfo . argtypes = [
IsWindowVisible = ctypes . windll . user32 . IsWindowVisible
wintypes . HMENU ,
IsWindowVisible . argtypes = [ win32structures . HWND ]
wintypes . UINT ,
IsWindowVisible . restype = win32structures . BOOL
wintypes . BOOL ,
IsWindowEnabled = ctypes . windll . user32 . IsWindowEnabled
POINTER ( win32structures . MENUITEMINFOW ) ,
IsWindowEnabled . argtypes = [ win32structures . HWND ]
]
IsWindowEnabled . restype = win32structures . BOOL
GetMenuItemRect = windll . user32 . GetMenuItemRect
ClientToScreen = ctypes . windll . user32 . ClientToScreen
GetMenuItemRect . restype = wintypes . BOOL
ScreenToClient = ctypes . windll . user32 . ScreenToClient
GetMenuItemRect . argtypes = [
wintypes . HWND ,
GetCurrentThreadId = ctypes . windll . Kernel32 . GetCurrentThreadId
wintypes . HMENU ,
GetWindowThreadProcessId = ctypes . windll . user32 . GetWindowThreadProcessId
wintypes . UINT ,
GetGUIThreadInfo = ctypes . windll . user32 . GetGUIThreadInfo
POINTER ( wintypes . RECT ) ,
AttachThreadInput = ctypes . windll . user32 . AttachThreadInput
]
AttachThreadInput . restype = win32structures . BOOL
CheckMenuItem = windll . user32 . CheckMenuItem
AttachThreadInput . argtypes = [ win32structures . DWORD , win32structures . DWORD , win32structures . BOOL ]
CheckMenuItem . restype = wintypes . DWORD
#GetWindowThreadProcessId = ctypes.windll.user32.GetWindowThreadProcessId
CheckMenuItem . argtypes = [
GetLastError = ctypes . windll . kernel32 . GetLastError
wintypes . HMENU ,
wintypes . UINT ,
OpenProcess = ctypes . windll . kernel32 . OpenProcess
wintypes . UINT ,
CloseHandle = ctypes . windll . kernel32 . CloseHandle
]
CreateProcess = ctypes . windll . kernel32 . CreateProcessW
GetMenuState = windll . user32 . GetMenuState
TerminateProcess = ctypes . windll . kernel32 . TerminateProcess
GetMenuState . restype = wintypes . UINT
ExitProcess = ctypes . windll . kernel32 . ExitProcess
GetMenuState . argtypes = [
wintypes . HMENU ,
ReadProcessMemory = ctypes . windll . kernel32 . ReadProcessMemory
wintypes . UINT ,
GlobalAlloc = ctypes . windll . kernel32 . GlobalAlloc
wintypes . UINT ,
GlobalLock = ctypes . windll . kernel32 . GlobalLock
]
GlobalUnlock = ctypes . windll . kernel32 . GlobalUnlock
GetSubMenu = windll . user32 . GetSubMenu
GetSubMenu . restype = wintypes . HMENU
SendMessage = ctypes . windll . user32 . SendMessageW
GetSubMenu . argtypes = [
SendMessageTimeout = ctypes . windll . user32 . SendMessageTimeoutW
wintypes . HMENU ,
SendMessageTimeout . argtypes = [ win32structures . HWND , win32structures . UINT , win32structures . WPARAM ,
c_int ,
win32structures . LPARAM , win32structures . UINT , win32structures . UINT ,
]
win32structures . PDWORD_PTR ]
GetSystemMenu = windll . user32 . GetSystemMenu
SendMessageTimeout . restype = win32structures . LRESULT
GetSystemMenu . restype = wintypes . HMENU
SendMessageA = ctypes . windll . user32 . SendMessageA
GetSystemMenu . argtypes = [
PostMessage = ctypes . windll . user32 . PostMessageW
wintypes . HWND ,
GetMessage = ctypes . windll . user32 . GetMessageW
wintypes . BOOL ,
RegisterWindowMessage = ctypes . windll . user32 . RegisterWindowMessageW
]
RegisterWindowMessage . restype = UINT
HiliteMenuItem = windll . user32 . HiliteMenuItem
HiliteMenuItem . restype = wintypes . BOOL
MoveWindow = ctypes . windll . user32 . MoveWindow
HiliteMenuItem . argtypes = [
EnableWindow = ctypes . windll . user32 . EnableWindow
wintypes . HWND ,
SetActiveWindow = ctypes . windll . user32 . SetActiveWindow
wintypes . HMENU ,
GetFocus = ctypes . windll . user32 . GetFocus
wintypes . UINT ,
SetFocus = ctypes . windll . user32 . SetFocus
wintypes . UINT ,
SetForegroundWindow = ctypes . windll . user32 . SetForegroundWindow
]
GetForegroundWindow = ctypes . windll . user32 . GetForegroundWindow
IsMenu = windll . user32 . IsMenu
SetWindowLong = ctypes . windll . user32 . SetWindowLongW
IsMenu . restype = wintypes . BOOL
IsMenu . argtypes = [
wintypes . HMENU ,
]
MenuItemFromPoint = windll . user32 . MenuItemFromPoint
MenuItemFromPoint . restype = c_int
MenuItemFromPoint . argtypes = [
wintypes . HWND ,
wintypes . HMENU ,
POINTER ( wintypes . POINT ) ,
]
BringWindowToTop = windll . user32 . BringWindowToTop
BringWindowToTop . restype = wintypes . BOOL
BringWindowToTop . argtypes = [
wintypes . HWND ,
]
GetParent = windll . user32 . GetParent
GetParent . restype = wintypes . HWND
GetParent . argtypes = [
wintypes . HWND ,
]
GetWindow = windll . user32 . GetWindow
GetWindow . restype = wintypes . HWND
GetWindow . argtypes = [
wintypes . HWND ,
wintypes . UINT ,
]
ShowWindow = windll . user32 . ShowWindow
ShowWindow . restype = wintypes . BOOL
ShowWindow . argtypes = [
wintypes . HWND ,
c_int ,
]
GetWindowContextHelpId = windll . user32 . GetWindowContextHelpId
GetWindowContextHelpId . restype = wintypes . DWORD
GetWindowContextHelpId . argtypes = [
wintypes . HWND ,
]
GetWindowLong = windll . user32 . GetWindowLongW
GetWindowLong . restype = wintypes . LONG
GetWindowLong . argtypes = [
wintypes . HWND ,
c_int ,
]
GetWindowPlacement = windll . user32 . GetWindowPlacement
GetWindowPlacement . restype = wintypes . BOOL
GetWindowPlacement . argtypes = [
wintypes . HWND ,
POINTER ( win32structures . WINDOWPLACEMENT ) ,
]
GetWindowRect = windll . user32 . GetWindowRect
GetWindowRect . restype = wintypes . BOOL
GetWindowRect . argtypes = [
wintypes . HWND ,
POINTER ( wintypes . RECT ) ,
]
GetWindowText = windll . user32 . GetWindowTextW
GetWindowText . restype = c_int
GetWindowText . argtypes = [
wintypes . HWND ,
wintypes . LPWSTR ,
c_int ,
]
GetWindowTextLength = windll . user32 . GetWindowTextLengthW
GetWindowTextLength . restype = c_int
GetWindowTextLength . argtypes = [
wintypes . HWND ,
]
GetClassName = windll . user32 . GetClassNameW
GetClassName . restype = c_int
GetClassName . argtypes = [
wintypes . HWND ,
wintypes . LPWSTR ,
c_int ,
]
GetClientRect = windll . user32 . GetClientRect
GetClientRect . restype = wintypes . BOOL
GetClientRect . argtypes = [
wintypes . HWND ,
POINTER ( wintypes . RECT ) ,
]
IsChild = windll . user32 . IsChild
IsChild . restype = wintypes . BOOL
IsChild . argtypes = [
wintypes . HWND ,
wintypes . HWND ,
]
IsWindow = windll . user32 . IsWindow
IsWindow . restype = wintypes . BOOL
IsWindow . argtypes = [
wintypes . HWND ,
]
IsWindowUnicode = windll . user32 . IsWindowUnicode
IsWindowUnicode . restype = wintypes . BOOL
IsWindowUnicode . argtypes = [
wintypes . HWND ,
]
IsWindowVisible = windll . user32 . IsWindowVisible
IsWindowVisible . restype = wintypes . BOOL
IsWindowVisible . argtypes = [
wintypes . HWND ,
]
IsWindowEnabled = windll . user32 . IsWindowEnabled
IsWindowEnabled . restype = wintypes . BOOL
IsWindowEnabled . argtypes = [
wintypes . HWND ,
]
ClientToScreen = windll . user32 . ClientToScreen
ClientToScreen . restype = wintypes . BOOL
ClientToScreen . argtypes = [
wintypes . HWND ,
POINTER ( wintypes . POINT ) ,
]
ScreenToClient = windll . user32 . ScreenToClient
ScreenToClient . restype = wintypes . BOOL
ScreenToClient . argtypes = [
wintypes . HWND ,
POINTER ( wintypes . POINT ) ,
]
GetCurrentThreadId = windll . kernel32 . GetCurrentThreadId
GetCurrentThreadId . restype = wintypes . DWORD
GetCurrentThreadId . argtypes = [
]
GetWindowThreadProcessId = windll . user32 . GetWindowThreadProcessId
GetWindowThreadProcessId . restype = wintypes . DWORD
GetWindowThreadProcessId . argtypes = [
wintypes . HWND ,
POINTER ( wintypes . DWORD ) ,
]
GetGUIThreadInfo = windll . user32 . GetGUIThreadInfo
GetGUIThreadInfo . restype = wintypes . BOOL
GetGUIThreadInfo . argtypes = [
wintypes . DWORD ,
POINTER ( win32structures . GUITHREADINFO ) ,
]
AttachThreadInput = windll . user32 . AttachThreadInput
AttachThreadInput . restype = wintypes . BOOL
AttachThreadInput . argtypes = [
wintypes . DWORD ,
wintypes . DWORD ,
wintypes . BOOL
]
OpenProcess = windll . kernel32 . OpenProcess
OpenProcess . restype = wintypes . HANDLE
OpenProcess . argtypes = [
wintypes . DWORD ,
wintypes . BOOL ,
wintypes . DWORD ,
]
CloseHandle = windll . kernel32 . CloseHandle
CloseHandle . restype = wintypes . BOOL
CloseHandle . argtypes = [
wintypes . HANDLE ,
]
CreateProcess = windll . kernel32 . CreateProcessW
CreateProcess . restype = wintypes . BOOL
CreateProcess . argtypes = [
wintypes . LPCWSTR ,
wintypes . LPWSTR ,
POINTER ( win32structures . SECURITY_ATTRIBUTES ) ,
POINTER ( win32structures . SECURITY_ATTRIBUTES ) ,
wintypes . BOOL ,
wintypes . DWORD ,
wintypes . LPVOID ,
wintypes . LPCWSTR ,
POINTER ( win32structures . STARTUPINFOW ) ,
POINTER ( win32structures . PROCESS_INFORMATION ) ,
]
TerminateProcess = windll . kernel32 . TerminateProcess
TerminateProcess . restype = wintypes . BOOL
TerminateProcess . argtypes = [
wintypes . HANDLE ,
wintypes . UINT ,
]
ExitProcess = windll . kernel32 . ExitProcess
ExitProcess . restype = None
ExitProcess . argtypes = [
wintypes . UINT ,
]
ReadProcessMemory = windll . kernel32 . ReadProcessMemory
ReadProcessMemory . restype = wintypes . BOOL
ReadProcessMemory . argtypes = [
wintypes . HANDLE ,
wintypes . LPVOID ,
wintypes . LPVOID ,
c_size_t ,
POINTER ( c_size_t ) ,
]
GlobalAlloc = windll . kernel32 . GlobalAlloc
GlobalLock = windll . kernel32 . GlobalLock
GlobalUnlock = windll . kernel32 . GlobalUnlock
SendMessage = windll . user32 . SendMessageW
SendMessage . restype = wintypes . LPARAM
SendMessage . argtypes = [
wintypes . HWND ,
wintypes . UINT ,
wintypes . WPARAM ,
wintypes . LPVOID ,
]
SendMessageTimeout = windll . user32 . SendMessageTimeoutW
SendMessageTimeout . restype = wintypes . LPARAM
SendMessageTimeout . argtypes = [
wintypes . HWND ,
wintypes . UINT ,
wintypes . WPARAM ,
wintypes . LPARAM ,
wintypes . UINT ,
wintypes . UINT ,
win32structures . PDWORD_PTR ,
]
PostMessage = windll . user32 . PostMessageW
PostMessage . restype = wintypes . BOOL
PostMessage . argtypes = [
wintypes . HWND ,
wintypes . UINT ,
wintypes . WPARAM ,
wintypes . LPARAM ,
]
GetMessage = windll . user32 . GetMessageW
GetMessage . restype = wintypes . BOOL
GetMessage . argtypes = [
POINTER ( wintypes . MSG ) ,
wintypes . HWND ,
wintypes . UINT ,
wintypes . UINT ,
]
RegisterWindowMessage = windll . user32 . RegisterWindowMessageW
RegisterWindowMessage . restype = wintypes . UINT
RegisterWindowMessage . argtypes = [
wintypes . LPCWSTR ,
]
MoveWindow = windll . user32 . MoveWindow
MoveWindow . restype = wintypes . BOOL
MoveWindow . argtypes = [
wintypes . HWND ,
c_int ,
c_int ,
c_int ,
c_int ,
wintypes . BOOL ,
]
EnableWindow = windll . user32 . EnableWindow
EnableWindow . restype = wintypes . BOOL
EnableWindow . argtypes = [
wintypes . HWND ,
wintypes . BOOL ,
]
SetFocus = windll . user32 . SetFocus
SetFocus . restype = wintypes . HWND
SetFocus . argtypes = [
wintypes . HWND ,
]
SetWindowLong = windll . user32 . SetWindowLongW
SetWindowLong . restype = wintypes . LONG
SetWindowLong . argtypes = [
wintypes . HWND ,
c_int ,
wintypes . LONG ,
]
try :
try :
SetWindowLongPtr = ctypes . windll . user32 . SetWindowLongPtrW
SetWindowLongPtr = windll . user32 . SetWindowLongPtrW
SetWindowLongPtr . argtypes = [ win32structures . HWND , ctypes . c_int , win32structures . LONG_PTR ]
SetWindowLongPtr . argtypes = [ win types. HWND , c_int , wintyp es. LONG_PTR ]
SetWindowLongPtr . restype = win32structures . LONG_PTR
SetWindowLongPtr . restype = win typ es. LONG_PTR
except AttributeError :
except AttributeError :
SetWindowLongPtr = SetWindowLong
SetWindowLongPtr = SetWindowLong
SystemParametersInfo = ctypes . windll . user32 . SystemParametersInfoW
SystemParametersInfo = windll . user32 . SystemParametersInfoW
VirtualAllocEx = ctypes . windll . kernel32 . VirtualAllocEx
SystemParametersInfo . restype = wintypes . UINT
VirtualAllocEx . restype = ctypes . c_void_p
SystemParametersInfo . argtypes = [
VirtualFreeEx = ctypes . windll . kernel32 . VirtualFreeEx
wintypes . UINT ,
DebugBreakProcess = ctypes . windll . kernel32 . DebugBreakProcess
wintypes . UINT ,
wintypes . LPVOID , # should map well to PVOID
VirtualAlloc = ctypes . windll . kernel32 . VirtualAlloc
wintypes . UINT ,
VirtualFree = ctypes . windll . kernel32 . VirtualFree
]
WriteProcessMemory = ctypes . windll . kernel32 . WriteProcessMemory
VirtualAllocEx = windll . kernel32 . VirtualAllocEx
GetActiveWindow = ctypes . windll . user32 . GetActiveWindow
VirtualAllocEx . restype = wintypes . LPVOID
GetLastActivePopup = ctypes . windll . user32 . GetLastActivePopup
VirtualAllocEx . argtypes = [
FindWindow = ctypes . windll . user32 . FindWindowW
wintypes . HANDLE ,
GetTopWindow = ctypes . windll . user32 . GetTopWindow
wintypes . LPVOID ,
c_size_t ,
SetCapture = ctypes . windll . user32 . SetCapture
wintypes . DWORD ,
ReleaseCapture = ctypes . windll . user32 . ReleaseCapture
wintypes . DWORD ,
]
ShowOwnedPopups = ctypes . windll . user32 . ShowOwnedPopups
VirtualFreeEx = windll . kernel32 . VirtualFreeEx
WindowFromPoint = ctypes . windll . user32 . WindowFromPoint
VirtualFreeEx . restype = wintypes . BOOL
VirtualFreeEx . argtypes = [
WideCharToMultiByte = ctypes . windll . kernel32 . WideCharToMultiByte
wintypes . HANDLE ,
GetACP = ctypes . windll . kernel32 . GetACP
wintypes . LPVOID ,
c_size_t ,
WaitForSingleObject = ctypes . windll . kernel32 . WaitForSingleObject
wintypes . DWORD ,
WaitForInputIdle = ctypes . windll . user32 . WaitForInputIdle
]
VirtualAlloc = windll . kernel32 . VirtualAlloc
IsHungAppWindow = ctypes . windll . user32 . IsHungAppWindow
VirtualAlloc . restype = wintypes . LPVOID
IsHungAppWindow . restype = win32structures . BOOL
VirtualAlloc . argtypes = [
IsHungAppWindow . argtypes = [ win32structures . HWND ]
wintypes . LPVOID ,
c_size_t ,
GetModuleFileNameEx = ctypes . windll . psapi . GetModuleFileNameExW
wintypes . DWORD ,
wintypes . DWORD ,
GetClipboardData = ctypes . windll . user32 . GetClipboardData
]
OpenClipboard = ctypes . windll . user32 . OpenClipboard
VirtualFree = windll . kernel32 . VirtualFree
EmptyClipboard = ctypes . windll . user32 . EmptyClipboard
VirtualFree . retype = wintypes . BOOL
CloseClipboard = ctypes . windll . user32 . CloseClipboard
VirtualFree . argtypes = [
CountClipboardFormats = ctypes . windll . user32 . CountClipboardFormats
wintypes . LPVOID ,
EnumClipboardFormats = ctypes . windll . user32 . EnumClipboardFormats
c_size_t ,
GetClipboardFormatName = ctypes . windll . user32 . GetClipboardFormatNameW
wintypes . DWORD ,
]
WriteProcessMemory = windll . kernel32 . WriteProcessMemory
WriteProcessMemory . restype = wintypes . BOOL
WriteProcessMemory . argtypes = [
wintypes . HANDLE ,
wintypes . LPVOID ,
wintypes . LPVOID ,
c_size_t ,
POINTER ( c_size_t ) ,
]
ReleaseCapture = windll . user32 . ReleaseCapture
ReleaseCapture . restype = wintypes . BOOL
ReleaseCapture . argtypes = [
]
WindowFromPoint = windll . user32 . WindowFromPoint
WindowFromPoint . restype = wintypes . HWND
WindowFromPoint . argtypes = [
wintypes . POINT ,
]
WaitForSingleObject = windll . kernel32 . WaitForSingleObject
WaitForSingleObject . restype = wintypes . DWORD
WaitForSingleObject . argtypes = [
wintypes . HANDLE ,
wintypes . DWORD ,
]
WaitForInputIdle = windll . user32 . WaitForInputIdle
WaitForInputIdle . restype = wintypes . DWORD
WaitForInputIdle . argtypes = [
wintypes . HANDLE ,
wintypes . DWORD ,
]
IsHungAppWindow = windll . user32 . IsHungAppWindow
IsHungAppWindow . restype = wintypes . BOOL
IsHungAppWindow . argtypes = [
wintypes . HWND ,
]
GetModuleFileNameEx = windll . psapi . GetModuleFileNameExW
GetModuleFileNameEx . restype = wintypes . DWORD
GetModuleFileNameEx . argtypes = [
wintypes . HANDLE ,
wintypes . HMODULE ,
wintypes . LPWSTR ,
wintypes . DWORD ,
]
GetClipboardData = windll . user32 . GetClipboardData
GetClipboardData . restype = wintypes . HANDLE
GetClipboardData . argtypes = [
wintypes . UINT ,
]
OpenClipboard = windll . user32 . OpenClipboard
OpenClipboard . restype = wintypes . BOOL
OpenClipboard . argtypes = [
wintypes . HWND ,
]
EmptyClipboard = windll . user32 . EmptyClipboard
EmptyClipboard . restype = wintypes . BOOL
EmptyClipboard . argtypes = [
]
CloseClipboard = windll . user32 . CloseClipboard
CloseClipboard . restype = wintypes . BOOL
CloseClipboard . argtypes = [
]
CountClipboardFormats = windll . user32 . CountClipboardFormats
CountClipboardFormats . restype = c_int
CountClipboardFormats . argtypes = [
]
EnumClipboardFormats = windll . user32 . EnumClipboardFormats
EnumClipboardFormats . restype = wintypes . UINT
EnumClipboardFormats . argtypes = [
wintypes . UINT ,
]
GetClipboardFormatName = windll . user32 . GetClipboardFormatNameW
GetClipboardFormatName . restype = c_int
GetClipboardFormatName . argtypes = [
wintypes . UINT ,
wintypes . LPWSTR ,
c_int ,
]
# DPIAware API funcs are not available on WinXP
# DPIAware API funcs are not available on WinXP
try :
try :
IsProcessDPIAware = ctypes . windll . user32 . IsProcessDPIAware
IsProcessDPIAware = windll. user32 . IsProcessDPIAware
SetProcessDPIAware = ctypes . windll . user32 . SetProcessDPIAware
SetProcessDPIAware = windll. user32 . SetProcessDPIAware
except AttributeError :
except AttributeError :
IsProcessDPIAware = None
IsProcessDPIAware = None
SetProcessDPIAware = None
SetProcessDPIAware = None
@ -230,7 +716,7 @@ except AttributeError:
# Process_Per_Monitor_DPI_Aware = 2
# Process_Per_Monitor_DPI_Aware = 2
# } Process_DPI_Awareness;
# } Process_DPI_Awareness;
try :
try :
shcore = ctypes. windll. LoadLibrary ( " Shcore.dll " )
shcore = windll. LoadLibrary ( " Shcore.dll " )
SetProcessDpiAwareness = shcore . SetProcessDpiAwareness
SetProcessDpiAwareness = shcore . SetProcessDpiAwareness
GetProcessDpiAwareness = shcore . GetProcessDpiAwareness
GetProcessDpiAwareness = shcore . GetProcessDpiAwareness
Process_DPI_Awareness = {
Process_DPI_Awareness = {
@ -252,26 +738,17 @@ elif SetProcessDPIAware:
ActionLogger ( ) . log ( " Call SetProcessDPIAware " )
ActionLogger ( ) . log ( " Call SetProcessDPIAware " )
SetProcessDPIAware ( )
SetProcessDPIAware ( )
GetQueueStatus = ctypes. windll. user32 . GetQueueStatus
GetQueueStatus = windll. user32 . GetQueueStatus
LoadString = ctypes. windll. user32 . LoadStringW
LoadString = windll. user32 . LoadStringW
#def VkKeyScanW(p1):
# # C:/PROGRA~1/MICROS~4/VC98/Include/winuser.h 4225
# return VkKeyScanW._api_(p1)
#VkKeyScan = stdcall(SHORT, 'user32', [c_wchar]) (VkKeyScanW)
#
#def MapVirtualKeyExW(p1, p2, p3):
#def MapVirtualKeyExW(p1, p2, p3):
# # C:/PROGRA~1/MICROS~4/VC98/Include/winuser.h 4376
# # C:/PROGRA~1/MICROS~4/VC98/Include/winuser.h 4376
# return MapVirtualKeyExW._api_(p1, p2, p3)
# return MapVirtualKeyExW._api_(p1, p2, p3)
#MapVirtualKeyEx = stdcall(
#MapVirtualKeyEx = stdcall(
# UINT, 'user32', [c_uint, c_uint, c_long]) (MapVirtualKeyExW)
# UINT, 'user32', [c_uint, c_uint, c_long]) (MapVirtualKeyExW)
#
#
#def MapVirtualKeyW(p1, p2):
# # C:/PROGRA~1/MICROS~4/VC98/Include/winuser.h 4355
# return MapVirtualKeyW._api_(p1, p2)
#MapVirtualKey = stdcall(UINT, 'user32', [c_uint, c_uint]) (MapVirtualKeyW)
#====================================================================
#====================================================================
@ -297,7 +774,7 @@ def LoWord(value):
def WaitGuiThreadIdle ( handle ) :
def WaitGuiThreadIdle ( handle ) :
""" Wait until the thread of the specified handle is ready """
""" Wait until the thread of the specified handle is ready """
process_id = wintypes . DWORD ( 0 )
process_id = wintypes . DWORD ( 0 )
GetWindowThreadProcessId ( handle , ctypes. POINTER ( wintypes . DWORD ) ( process_id ) )
GetWindowThreadProcessId ( handle , byref ( process_id ) )
# ask the control if it has finished processing the message
# ask the control if it has finished processing the message
hprocess = OpenProcess (
hprocess = OpenProcess (
@ -327,10 +804,10 @@ def GetDpiAwarenessByPid(pid):
return dpi_awareness
return dpi_awareness
try :
try :
dpi_awareness = c types. c _int( )
dpi_awareness = c _int( )
hRes = GetProcessDpiAwareness (
hRes = GetProcessDpiAwareness (
hProcess ,
hProcess ,
ctypes. byref( dpi_awareness ) )
byref( dpi_awareness ) )
CloseHandle ( hProcess )
CloseHandle ( hProcess )
if hRes == 0 :
if hRes == 0 :
return dpi_awareness . value
return dpi_awareness . value