Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

How can I get all the window handlers that belongs to a process?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tarh ik - 23 Dec 2004 14:49 GMT
    Hi!!!

    By any chance, do you know how can I get all the window handlers that
belongs to a process?

    I'm trying to send some messages to the winproc that has focus, so I
can automate a data capture process. So far, I can access the Process by
using the Process class, and I can identify and send messages to the main
window. However, the main window is seldom the one that has focus. I saw with
the Microsoft's Spy++ that there are many Window handlers (one for each
control). If I can create a collection of their handlers, I will be able to
send messages to each one, automating the data capture process.

    Any help is greatelly appreciated!!!

    Tarh ik
Shariq Khan - 23 Dec 2004 15:33 GMT
Use this class:

Imports System.Diagnostics

Public Class Win32Windows

   Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As
EnumWindowsDelegate, _
       ByVal lParam As Integer) As Integer
   Private Delegate Function EnumWindowsDelegate(ByVal Handle As IntPtr,
ByVal iParam As Integer) As Boolean
   Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hWnd As Integer, _
                   ByRef lpdwProcessId As Integer) As Integer

   Public Sub New(ByVal ProcessID As Integer)
       EnumWindows(AddressOf EnumWindowProc, ProcessID)
   End Sub

   Private ReadOnly m_oWindowList As New ArrayList

   Private Function EnumWindowProc(ByVal Handle As IntPtr, ByVal iParam As
Integer) As Boolean
       Dim hWnd As Integer = Handle.ToInt32()
       Dim iProcessID As Integer
       Dim iThreadID As Integer = GetWindowThreadProcessId(hWnd,
iProcessID)

       If iProcessID = iParam Then
           m_oWindowList.Add(Handle.ToInt32())
       End If

       Return True
   End Function

   Public ReadOnly Property WindowList() As IList
       Get
           Return m_oWindowList
       End Get
   End Property
End Class

Example:
       Dim list As New Win32Windows(Process.GetCurrentProcess().Id)
       For Each iHandle As Integer In list.WindowList
           Console.WriteLine(iHandle.ToString())
       Next

Hope this helps!

Shariq Khan
shariq@shariqkhan.com

>     Hi!!!
>
[quoted text clipped - 14 lines]
>
>     Tarh ik
Tarh ik - 24 Dec 2004 17:23 GMT
    Thanks Shariq!!!

    The code that you gave me works great!!!! It has actually routed me to
the right path. I'm still getting only one handle, though, which is the
handler of the main window. However, I'm going to use your code to extract
all the handles of the child windows (I read somewhere that there is a
similar function for child windows... let's see...)

     Thank you very much for your help!!!!!

     Tarh ik

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.