Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

win32gui.FindWindow problems

1,071 views
Skip to first unread message

Darrell Gallion

unread,
Nov 10, 2000, 3:00:00 AM11/10/00
to
I started a shell with:
start "dog"
Which set the title of the shell to "dog"
They tried to use FindWindow to find it.
Any idea what I'm doing wrong?
The goal it to find all windows.

Python 2.0b2 (#6, Sep 26 2000, 14:59:21) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import win32gui
>>> win32gui.FindWindow("","dog")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pywintypes.api_error: (123, 'FindWindow', 'The filename, directory name, or
volu
me label syntax is incorrect.')

Thanks
--Darrell

Dale Strickland-Clark

unread,
Nov 10, 2000, 7:38:34 PM11/10/00
to
"Darrell Gallion" <dar...@dorb.com> wrote:

I can't make it work either. It's not clear from the docs how to specify a NULL for the first arg -
which is what I think you need. I tried 0 and None but both crash Python.
--
Dale Strickland-Clark
Out-Think Ltd
Business Technology Consultants


Mark Hammond

unread,
Nov 10, 2000, 10:40:42 PM11/10/00
to
Dale Strickland-Clark wrote:

> I can't make it work either. It's not clear from the docs how to specify a NULL for the first arg -
> which is what I think you need. I tried 0 and None but both crash Python.

None as the first param is indeed passing NULL to the API - the API is
what is crashing with that NULL :-( Indeed the API documentation does
not state NULL is OK.

>>> win32gui.FindWindow("ConsoleWindowClass", "Command Prompt")
131402

The class name can be determined from spy++.

Mark.

Alex Martelli

unread,
Nov 11, 2000, 3:00:00 AM11/11/00
to
"Dale Strickland-Clark" <da...@out-think.NOSPAMco.uk> wrote in message
news:q05p0told569nfa8m...@4ax.com...
[snip]

> I can't make it work either. It's not clear from the docs how to specify a
NULL for the first arg -
> which is what I think you need. I tried 0 and None but both crash Python.

FindWindow is not documented in the Win32 API's to support NULL as
a first parameter.

EnumWindows is what I'd use to find windows of any class in C or C++,
but I don't know, offhand, if win32all exposes it...


Alex


Tim Roberts

unread,
Nov 12, 2000, 3:00:00 AM11/12/00
to
"Alex Martelli" <ale...@yahoo.com> wrote:

>"Dale Strickland-Clark" <da...@out-think.NOSPAMco.uk> wrote in message
>news:q05p0told569nfa8m...@4ax.com...
> [snip]

>> I can't make it work either. It's not clear from the docs how to specify a
>NULL for the first arg -
>> which is what I think you need. I tried 0 and None but both crash Python.
>

>FindWindow is not documented in the Win32 API's to support NULL as
>a first parameter.

I was going to give you a big "HUH?" in response to this, but I see that
the MSDN web page on FindWindow does not explicitly state that NULL is
allowed for the class name. This is a documentation failure, not an API
restriction: the MSDN web page is incomplete. NULL is a valid option for
either parameter to FindWindow, and specifies that the option is not to be
used as a criteria in the search. It has always worked, and it will
continue to work.

The page on CWnd::FindWindow says this explicitly:

http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_mfc_cwnd.3a3a.findwindow.htm

and CWnd::FindWindow is implemented as an inline call to FindWindow.
Microsoft uses the NULL first parameter in their examples; see knowledge
base article Q124103.

Dale correctly pointed out the problem; he needs to pass a NULL, not a
zero-length string. I don't know how to do this, either.
--
- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Mark Hammond

unread,
Nov 12, 2000, 11:58:24 PM11/12/00
to
Tim Roberts wrote:

> Dale correctly pointed out the problem; he needs to pass a NULL, not a
> zero-length string. I don't know how to do this, either.

And I pointed out that None does indeed pass a NULL.

A quick test showed me that it was the Win32 FindWindow function that
failed on dereferencing NULL, so I was too quick to point the finger. I
didn't look closely enough - this is a bug in win32gui. The annoying
thing is that Pythonwin uses the exact code the KB article pointed at,
so I should have known better.

Mark.

0 new messages