L
Luke
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
--------------------------------------------------------------------------
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