Herfried ,
I am now having problems getting the EnumParentProc function to call the
GetWindowRect function. I am getting a null object reference when the
GetWindowRect function is called. I have run the code in debug mode and
found that the RECT object is created, and the hWnd is being passed in from
the Win API. I have tried to modify the code so that the values being passed
are integers or integer pointers and tried all different combinations but
this did not seem to effect the output. I am trying to create a module
within my project to handle the window positions which updates its
information when the WindowsLocate function is called. I have included my
code here. Any help would be appreciated.
Regards, David
Module mWindowLocations
Private Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam
As IntPtr) As Boolean
<System.Runtime.InteropServices.DllImport("user32", SetLastError:=True)> _
Private Function EnumWindows(ByVal ewp As EnumWindowsProc, ByVal lParam As
IntPtr) As Boolean
End Function
Private mWindows As New Collection
Private Structure RECT
Dim Left As Long
Dim Top As Long
Dim Right As Long
Dim Bottom As Long
End Structure
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As IntPtr,
ByVal lpRect As RECT) As Long
Private ewp As EnumWindowsProc = New EnumWindowsProc(AddressOf
EnumParentProc)
Public Sub WindowsLocate()
Do While mWindows.Count > 0
mWindows.Remove(1)
Loop
' *** Place this code wherever you want to enumerate the windows. ***
Dim retval As Long ' return value
' Use the above callback function to list all of the enumerated windows.
Note that lParam is
' set to 0 because we don't need to pass any additional information to the
function.
retval = EnumWindows(ewp, IntPtr.Zero)
End Sub
' Display the title bar text of all top-level windows. This
' task is given to the callback function, which will receive each handle
individually.
' Note that if the window has no title bar text, it will not be displayed
(for clarity's sake).
' *** Place this code in a module. This is the callback function. ***
' This function displays the title bar text of the window identified by
hwnd.
Private Function EnumParentProc(ByVal hWnd As IntPtr, ByVal lParam As
IntPtr) As Boolean
Dim R As RECT
GetWindowRect(hWnd, R)
mWindows.Add(R)
EnumParentProc = True ' return value of 1 means continue enumeration
End Function
End Module