mfc >> how to get main window handle from processID

by YWJoaQ » Mon, 14 Aug 2006 17:50:01 GMT

hi,

I have a processId for a application, i want to to findout the application
main window handle from it. how i can do that.
I have tried using EnumWindow and GetThreadProcessID() function but that is
not giving me expected results.

the window handle retuns is not the main window handle from the
GetThreadProcessID() function, but it is one of the window attached to
process and whose parent is a desktop windo

any pointer will be helpful
Thanks in advance.


mfc >> how to get main window handle from processID

by Doug Harrison [MVP] » Mon, 14 Aug 2006 22:12:11 GMT


On Mon, 14 Aug 2006 02:50:01 -0700, abhi < XXXX@XXXXX.COM >



That could be a combobox dropdown window, because strangely enough, Windows
makes the desktop its parent. Same thing for tooltips. This allows these
windows to extend beyond their owners' borders, which ordinary child
windows cannot do. To ask the obvious, are you saying that an exhaustive
enumeration doesn't turn up any other window belonging to the process? If
so, determine the parentage of the window you want using Spy++ and get back
to us.

--
Doug Harrison
Visual C++ MVP

mfc >> how to get main window handle from processID

by YWJoaQ » Mon, 14 Aug 2006 23:47:02 GMT

Thanks Doug for you reply,

I was not enumeration whole windows at the time of post,

The window is not a combobox window,I was previously looking for a simple
API which will serve my purpose, the reason was i don;t have any other
information about the target app's main window other than its processID, now
i have Window caption for which I can GetWindowText which serves my purpose.
but again I am not satified with enumetaing all the window and compare the
window caption for main window.

Can you throw light on these.

Again thanks for your help.

Regards
A b h i

mfc >> how to get main window handle from processID

by Joseph M. Newcomer » Tue, 15 Aug 2006 00:53:28 GMT

The problem is that may applications don't have a single "top level window", e.g.,
PowerPoint, Excel, Word. The multiple-top-level-window paradigm, now available to the
Rest Of Us in VS.NET, is proving to be the preferred model Microsoft would like us to use.
So only some subset of applications will actually have a unique top-level window that
represents the "main frame" we are familiar with. And, as already pointed out, any app
can have multiple windows whose parent is NULL, independent of their role. So the problem
is a bit challenging, and I'm not sure there is any one "right" answer possible.
joe





Joseph M. Newcomer [MVP]
email: XXXX@XXXXX.COM
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Similar Threads

1. how to get the status of a process through its processID and handle - CSharp/C#

2. C# Process Handle from ProcessID

Hello!

Can somebody help me? I need to get the Process Handle for a given Process ID!
Thank you
Frank

3. Getting window position from IntPtr window handle - CSharp/C#

4. Main window handle (processes)

Hi All!

How do I get the handle of the main window (if any) for a given process via 
API?

TIA

Per Rollvang 


5. Getting main window from launched process - CSharp/C#

6. Handle to main window.

Hi to all,

is there a way to get the window handle of the main window of an application
or process ?
For example, if someone opens Microsoft Word, he gets a window so he/she can
write text.
Spy++ gives that this window is called _Wwg.

How we can get a handle to this window assuming that we do not know
beforehand the name of the process,
we just want to find the handle of every application's main window ?
(or the window that currently has the focus/caret).

Is this possible ??

Thanks a lot for any help,

objectref


7. Message Hook, getting target window handle - CSharp/C#

8. getting another window's handle from a mouse click

Hey,

I am trying to implement (using C# and .NET) a
routine that retrieves the window handle of another application's
window
by having the user click on that window.

Any help?

Thanks,
Petar