I am occasionally getting back negative HWND values from EnumChildWindows. They 
appear to round trip properly, for example win32gui.GetClassName(-1901131990) 
appears to function properly. Not exactly a bug but is somewhat unexpected.

I had grabbed this code from the net somewhere to get the currently focused 
window which returns HWND as an unsigned long:
class GUITHREADINFO(ctypes.Structure):
    _fields_ = [
    ("cbSize", ctypes.c_ulong),
    ("flags", ctypes.c_ulong),
    ("hwndActive", ctypes.c_ulong),
    ("hwndFocus", ctypes.c_ulong),
    ("hwndCapture", ctypes.c_ulong),
    ("hwndMenuOwner", ctypes.c_ulong),
    ("hwndMoveSize", ctypes.c_ulong),
    ("hwndCaret", ctypes.c_ulong),
    ("rcCaret", RECT)
    ]

def getFocusedWindow():
    guiThreadInfo = GUITHREADINFO(cbSize=ctypes.sizeof(GUITHREADINFO))
    user32.GetGUIThreadInfo(0, ctypes.byref(guiThreadInfo))
    return guiThreadInfo.hwndFocus

My code would fail occasionally and I'd wonder why but never got into debugging 
it until one day it was failing constantly. After much head scratching the 
simple fix for me was to change the focus-finding-code to use ctypes.c_long so 
the result is not unsigned from both HWND sources.

Not sure it is worth trying to fix in Pythonwin but figured I should  post 
about it.

This is on pywin32 build 217 on Python 2.7.2, Windows 7 32bit.

Kelly Kranabetter
Programmer/Support Analyst
Tolko Industries
(250)398-3980

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to