471,344 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

Why MainWindowHandle is zero?

Question: why Process.MainWindowHandle is zero?

--------------------------------------------------------------------------
From document of Process.MainWindowHandle Property:

Property Value
The system-generated window handle of the main window of the associated
process.
Exceptions
Exception TypeCondition
InvalidOperationExceptionThe MainWindowHandle is not defined because the
process has exited.
NotSupportedExceptionYou are attempting to retrieve the MainWindowHandle for
a process that is running on a remote computer.

Remarks
You can get the MainWindowHandle property only for processes that are
running on the local computer. The MainWindowHandle property is a value that
uniquely identifies the window that is associated with the process.
A process has a main window associated with it only if the process has a
graphical interface. If the associated process does not have a main window,
the MainWindowHandle value is zero. If you have just started a process and
want to use its main window handle, consider using the WaitForInputIdle
method to allow the process to finish starting, ensuring that the main
window handle has been created. Otherwise, an exception will be thrown.
--------------------------------------------------------------------------

I am trying to use GetProcessesByName("xxxx.exe") and then get the main
window's handle via Process.MainWindowHandle; however, the return value is
zero.
1) the process is not in a remote computer;
2) the code works well if I change the process name to another one; e.g.
winmine.exe (the small game: mine sweeper :) )
3) the process xxxx.exe has finished starting. It is a kind of media player
and starts very fast. In fact, to testify that it has a main window handle,
I have tried to use Spy++ to find it and get its main window's handle and
title normally. Then I call SendMessage(hWnd, WM_GETTEXT, xxx, xxx) and get
its title.

1) Why I can NOT get the main window's handle via Process.MainWindowHandle?
2) What you will do to accomplish this? I am trying EnumWindows()

Any response is highly appreciated. Thanks
Jul 21 '05 #1
0 3004

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Moty Michaely | last post: by
reply views Thread by Michiel | last post: by
reply views Thread by Luke | last post: by
23 posts views Thread by Hallvard B Furuseth | last post: by
reply views Thread by siddharthkhare | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.