By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

get Handle to an Application/Window, not a Process

P: n/a
Hi,

I need to do osme handlings with an Internet Explorer Window. The problem
is: when the user has one ore more Internet Explorers opened, this is
(sometimes) indicated in the Task Manager as one process and not 2 or more.
When trying to get all the IE-windowd with the "For Each p In
Process.GetProcessesByName("IEXPLORE")"-function, I only get 1 process
returned, which has as "p.MainWindowTitle" the MainWindowTitle of one of the
open IE-windows.

Like that I'm not able to work with that IE-window I need. Does anybody how
to get arroudn this problem? Is there a way to go directly by the
Windows/Applications and not the Processes?

Thanks,

Pieter
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi DraguVaso,

Explorers (window and internet) create only one process. They spawn threads
for each individual GUI. If I'm not mistaken office products work the same
way. Process.MainWindowHandle enumerates all top-level windwos and returns
the first which is created by the given process. So it returns one of the
provess top-level widnows whichever is enumerated first.

I'm pretty sure if there is no managed solution for your problem so you
need to go ahead and use PInvoke.
Probably you have several solutions but I'll give you two of them:
1. Use EnumWindows (as Process.MainWindowHandle does) and filter IE windows
using GetWindowThreadProcessId API
2. Get all process' threads (Process.Threads property) and then call
EnumTreadWindows to narrow down the number of windows to enumerate

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:OS**************@TK2MSFTNGP12.phx.gbl...
Hi,

I need to do osme handlings with an Internet Explorer Window. The problem
is: when the user has one ore more Internet Explorers opened, this is
(sometimes) indicated in the Task Manager as one process and not 2 or more. When trying to get all the IE-windowd with the "For Each p In
Process.GetProcessesByName("IEXPLORE")"-function, I only get 1 process
returned, which has as "p.MainWindowTitle" the MainWindowTitle of one of the open IE-windows.

Like that I'm not able to work with that IE-window I need. Does anybody how to get arroudn this problem? Is there a way to go directly by the
Windows/Applications and not the Processes?

Thanks,

Pieter

Nov 20 '05 #2

P: n/a
Thanks,

I just found another solution that gives me more possiblity's (checking on
the URL):

Public Shared Function ProcessTelematique2() As Integer
'Add SHDocVW.dll in the References to use this function
Dim IEWin As SHDocVw.InternetExplorer
Dim winShell = New SHDocVw.ShellWindows
For Each IEWin In winShell
MessageSilent(IEWin.LocationURL())
If (LCase(Left(IEWin.LocationURL(), 33)) =
"http://intranet.ctlmbe.fr/beinet/") Then
Return IEWin.HWND
Exit Function
End If
Next
Return 0
End Function

Thanks anyways,

Pieter

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi DraguVaso,

Explorers (window and internet) create only one process. They spawn threads for each individual GUI. If I'm not mistaken office products work the same
way. Process.MainWindowHandle enumerates all top-level windwos and returns
the first which is created by the given process. So it returns one of the
provess top-level widnows whichever is enumerated first.

I'm pretty sure if there is no managed solution for your problem so you
need to go ahead and use PInvoke.
Probably you have several solutions but I'll give you two of them:
1. Use EnumWindows (as Process.MainWindowHandle does) and filter IE windows using GetWindowThreadProcessId API
2. Get all process' threads (Process.Threads property) and then call
EnumTreadWindows to narrow down the number of windows to enumerate

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:OS**************@TK2MSFTNGP12.phx.gbl...
Hi,

I need to do osme handlings with an Internet Explorer Window. The problem is: when the user has one ore more Internet Explorers opened, this is
(sometimes) indicated in the Task Manager as one process and not 2 or

more.
When trying to get all the IE-windowd with the "For Each p In
Process.GetProcessesByName("IEXPLORE")"-function, I only get 1 process
returned, which has as "p.MainWindowTitle" the MainWindowTitle of one of

the
open IE-windows.

Like that I'm not able to work with that IE-window I need. Does anybody

how
to get arroudn this problem? Is there a way to go directly by the
Windows/Applications and not the Processes?

Thanks,

Pieter


Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.