def GetHwndIcon(hWnd): """ Get a wx.Icon from a window through its hwnd window handle """ hIcon = DWORD() res = SendMessageTimeout(hWnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, byref(hIcon)) if res == 0: hIcon.value = 0 if hIcon.value < 10: hIcon.value = GetClassLong(hWnd, GCL_HICONSM) if hIcon.value == 0: res = SendMessageTimeout(hWnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, byref(hIcon)) if res == 0: hIcon.value = 0 if hIcon.value < 10: hIcon.value = GetClassLong(hWnd, GCL_HICON) if hIcon.value != 0: icon = wx.NullIcon value = hIcon.value # ugly fix for "OverflowError: long int too large to convert to int" if value & 0x80000000: value = -((value ^ 0xffffffff) + 1) icon.SetHandle(value) icon.SetSize((16, 16)) return icon else: return None
def PySendMessageTimeout(hWnd, msg, wParam=0, lParam=0, flags=SMTO_BLOCK | SMTO_ABORTIFHUNG, timeout=2000): resultData = DWORD() res = SendMessageTimeout(hWnd, msg, wParam, lParam, flags, timeout, byref(resultData)) if not res: raise WinError() return resultData.value