473,473 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

get Handle to an Application/Window, not a Process

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
2 6312
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil B Brubaker | last post by:
I'm trying to create my own shellexecute program named shell4OD and am having problems with handles. Here is my code ... ===== Private Declare Function ShellExecute Lib _ "shell32.dll" Alias...
4
by: | last post by:
Hi, In the Process class there is a CloseMainWindow, why is there not a BringMainWindowToForeground or similar method? What would be the best way to do this if we jsut have the process info...
12
by: Ken Brubaker | last post by:
I am using DB2 8.5 FP5 on Windows 2000 Server and have noticed what appears to be a handle leak. When I execute a DB2 connect statement in a command window, followed by a DB2 connect reset...
11
by: objectref | last post by:
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....
1
by: Sephi berry via .NET 247 | last post by:
Hi I'm having this problem of accessing the handle of a window. I retrive it by: Dim procs As Process() = Process.GetProcessesByName("ArcScene") dim intHWND1 IntPtr = procs(0).Handle and get a...
13
by: Abhishek | last post by:
Hi, how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application only even if there is any other window in front of it. I dont...
0
by: Sasie7679 | last post by:
Dear All, We have a requirement to open any document with a specific application and display it within a OCX control (Example - word, excel, adobe reader, MSPaint, Photoshop etc). We are using...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.