473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 3131

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
by: Zhiqiang Ye | last post by:
Hi, All I am reading FAQ of this group. I have a question about this: http://www.eskimo.com/~scs/C-faq/q7.31.html It says: " p = malloc(m * n); memset(p, 0, m * n); The zero fill is...
25
by: pm940 | last post by:
Hello. I've been reading some past discussions on the NULL vs. zero. References are always made to systems or machienes that use values other than zero to represent the NULL pointer. Although...
2
by: Moty Michaely | last post by:
Hello all, I am enumerating vb6 process from c# application by name. I need to send message to all processes that has the specified name but for this purpose I need the handle of the main...
0
by: Michiel | last post by:
Hello, When I execute the following code Process* oProc; IntPtr ipMain; HWND hWnd; oProc=Process::GetProcessById(m_IProcId); ipMain=oProc->MainWindowHandle; hWnd=(HWND)ipMain.ToPointer();
0
by: Luke | last post by:
Question: why Process.MainWindowHandle is zero? -------------------------------------------------------------------------- From document of Process.MainWindowHandle Property: Property Value...
1
by: codejunkie | last post by:
Hi, I am running a suite of tests of a WIN 32 application. Every test launches the same application, checks if the Application has a Main Window handle and then proceeds. However i am noticing...
4
by: H.S. | last post by:
Hello, I am trying out a few methods with which to test of a given number is practically zero. as an example, does the following test correctly if a given number is zero within machine...
23
by: Hallvard B Furuseth | last post by:
As far as I can tell, (x & -1) is nonzero if the integer x is negative zero. So for signed types, x == 0 does not guarantee (x & foo) == 0. Is that right? (Not that I expect to ever encounter a...
0
by: siddharthkhare | last post by:
Hi all, I am trying to launch an process in .net as follows.I want to wait till mainwindow handle is initialized. fowlloing code works some times i.e i can read the value of mainwindow handle but...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.