win32gui.EnumWindows problem in Python 2.2

Mark Hammond mhammond at skippinet.com.au
Thu Dec 19 18:59:14 EST 2002


griffin wrote:
> "Mark Hammond" <mhammond at skippinet.com.au> wrote in message
> news:oJbM9.2945$W51.6599 at news-server.bigpond.net.au...
> 
>>I am surprised this ever worked as you describe.  The MS docs state:
>>"""
>>If EnumWindowsProc returns zero, the return value is also zero.
>>"""
>>
>>which means that EnumWindows will always raise that exception if your
>>handler returns 0.  I haven't a Python 2.0 handy, but 2.1 certainly does.
>>
>>Just catch and ignore the exception if exception[0]==0.
> 
> 
> I guess I don't understand why this would raise an exception.  I'm looking
> at the Win32gui documentation which says:
> "Enumerates all top-level windows on the screen by passing the handle to
> each window, in turn, to an application-defined callback function.
> EnumWindows continues until the last top-level window is enumerated or the
> callback function returns FALSE"
> 
> is there some exception-raising convention that is implicit here that I
> don't know about?  (I'm pretty new to Win32.)
> 
> But who cares, I'll do as you say!  :-)

EnumWindows is a BOOL function.  If any BOOL functions return FALSE, the 
win32api functions generally raise an exception.

As I mentioned, the docs for EnumWindows say:

"If EnumWindowsProc returns zero, the return value is also zero."

Thus, if your callback function returns FALSE to end the enumeration, 
EnumWindows itself will return zero (FALSE).  Thus, we raise an 
exception - but when we look for the error number (GetLastError()), we 
get back 0 - no error - ie, there was no error as such, but the function 
did return FALSE, indicating we cut the enumeration short.

Hope that makes more sense.

Mark.




More information about the Python-list mailing list