Click here to Skip to main content
16,016,076 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Folderbrouwserdialog with textbox(for folder) Pin
Simon_Whale22-Feb-11 2:28
Simon_Whale22-Feb-11 2:28 
GeneralRe: Folderbrouwserdialog with textbox(for folder) Pin
JR21222-Feb-11 21:34
JR21222-Feb-11 21:34 
GeneralRe: Folderbrouwserdialog with textbox(for folder) Pin
Luc Pattyn23-Feb-11 2:25
sitebuilderLuc Pattyn23-Feb-11 2:25 
GeneralRe: Folderbrouwserdialog with textbox(for folder) Pin
JR21223-Feb-11 7:28
JR21223-Feb-11 7:28 
AnswerRe: Folderbrouwserdialog with textbox(for folder) Pin
DaveAuld22-Feb-11 2:50
professionalDaveAuld22-Feb-11 2:50 
AnswerRe: Folderbrouwserdialog with textbox(for folder) Pin
Alan N22-Feb-11 6:43
Alan N22-Feb-11 6:43 
GeneralRe: Folderbrouwserdialog with textbox(for folder) Pin
JR21222-Feb-11 21:36
JR21222-Feb-11 21:36 
QuestionPlaying with other process windows! [modified] Pin
FeRtoll20-Feb-11 20:59
FeRtoll20-Feb-11 20:59 
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    End Function

    <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function EnumChildWindows(ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, ByVal lParam As IntPtr) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)
    End Sub
    <DllImport("USER32.DLL")> _
    Private Shared Function GetShellWindow() As IntPtr
    End Function

    <DllImport("USER32.DLL")> _
    Private Shared Function GetWindowText(ByVal hWnd As IntPtr, ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Integer
    End Function

    <DllImport("USER32.DLL")> _
    Private Shared Function GetWindowTextLength(ByVal hWnd As IntPtr) As Integer
    End Function

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, <Out()> ByRef lpdwProcessId As UInt32) As UInt32
    End Function

    <DllImport("USER32.DLL")> _
    Private Shared Function IsWindowVisible(ByVal hWnd As IntPtr) As Boolean
    End Function

    Private Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean

    <DllImport("USER32.DLL")> _
    Private Shared Function EnumWindows(ByVal enumFunc As EnumWindowsProc, ByVal lParam As Integer) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, <Out()> ByRef lpRect As RECT) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    Public Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()
        Dim ChildrenList As New List(Of IntPtr)
        Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)
        Try
            EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))
        Finally
            If ListHandle.IsAllocated Then ListHandle.Free()
        End Try

        Return ChildrenList.ToArray
    End Function
    Private hShellWindow As IntPtr = GetShellWindow()
    Private dictWindows As New Dictionary(Of IntPtr, String)
    Private currentProcessID As Integer
    Public Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
    Private Shared Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
        Dim ChildrenList As List(Of IntPtr) = GCHandle.FromIntPtr(Parameter).Target
        If ChildrenList Is Nothing Then Throw New Exception("GCHandle Target could not be cast as List(Of IntPtr)")
        ChildrenList.Add(Handle)
        Return True
    End Function
    Public Function GetOpenWindowsFromPID(ByVal processID As Integer) As IDictionary(Of IntPtr, String)
        dictWindows.Clear()
        currentProcessID = processID
        EnumWindows(AddressOf enumWindowsInternal, 0)
        Return dictWindows
    End Function
    Private Function enumWindowsInternal(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean
        If (hWnd <> hShellWindow) Then
            Dim windowPid As UInt32
            If Not IsWindowVisible(hWnd) Then
                Return True
            End If
            Dim length As Integer = GetWindowTextLength(hWnd)
            If (length = 0) Then
                Return True
            End If
            GetWindowThreadProcessId(hWnd, windowPid)
            If (windowPid <> currentProcessID) Then
                Return True
            End If
            Dim stringBuilder As New StringBuilder(length)
            GetWindowText(hWnd, stringBuilder, (length + 1))
            dictWindows.Add(hWnd, stringBuilder.ToString)
        End If
        Return True
    End Function
    Private Const WM_CHAR = &H102


What i need is to get all windows of an process...
I do it like this:
For Each P As Process In Process.GetProcessesByName("Notepad")
            Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(P.Id)
            For Each kvp As KeyValuePair(Of IntPtr, String) In windows

            Next
        Next


But now i am missing handles of that windows.

Could someone explain me a little!?
I want to know how to get all child windows (id,title,handle) of an process.
FeRtoll Software.net
------------
E-Mail me
WebPage
modified on Monday, February 21, 2011 3:09 AM

AnswerMessage Removed Pin
22-Feb-11 3:28
professionalАslam Iqbal22-Feb-11 3:28 
GeneralRe: Playing with other process windows! Pin
FeRtoll22-Feb-11 6:03
FeRtoll22-Feb-11 6:03 
QuestionHow to add "syntax help" to own code Pin
David Crow19-Feb-11 16:09
David Crow19-Feb-11 16:09 
AnswerRe: How to add "syntax help" to own code Pin
Luc Pattyn19-Feb-11 17:13
sitebuilderLuc Pattyn19-Feb-11 17:13 
GeneralRe: How to add "syntax help" to own code Pin
Dalek Dave20-Feb-11 0:03
professionalDalek Dave20-Feb-11 0:03 
AnswerRe: How to add "syntax help" to own code Pin
Luc Pattyn20-Feb-11 2:12
sitebuilderLuc Pattyn20-Feb-11 2:12 
GeneralRe: How to add "syntax help" to own code Pin
Eddy Vluggen20-Feb-11 2:24
professionalEddy Vluggen20-Feb-11 2:24 
GeneralRe: How to add "syntax help" to own code Pin
Kschuler22-Feb-11 9:57
Kschuler22-Feb-11 9:57 
GeneralRe: How to add "syntax help" to own code Pin
Luc Pattyn22-Feb-11 10:10
sitebuilderLuc Pattyn22-Feb-11 10:10 
QuestionApproach advice Pin
Simon_Whale18-Feb-11 1:01
Simon_Whale18-Feb-11 1:01 
AnswerRe: Approach advice Pin
Geoff Williams18-Feb-11 3:18
Geoff Williams18-Feb-11 3:18 
GeneralRe: Approach advice Pin
Simon_Whale18-Feb-11 3:33
Simon_Whale18-Feb-11 3:33 
AnswerRe: Approach advice Pin
RobCroll18-Feb-11 3:20
RobCroll18-Feb-11 3:20 
GeneralRe: Approach advice Pin
Simon_Whale18-Feb-11 3:31
Simon_Whale18-Feb-11 3:31 
QuestionJust a link required Pin
Dalek Dave17-Feb-11 12:55
professionalDalek Dave17-Feb-11 12:55 
AnswerRe: Just a link required Pin
Luc Pattyn17-Feb-11 13:16
sitebuilderLuc Pattyn17-Feb-11 13:16 
GeneralRe: Just a link required Pin
Dalek Dave17-Feb-11 21:14
professionalDalek Dave17-Feb-11 21:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.