[RESOLVED] try to convert this to vb.net need help
I have this in a module
Code:
Option Explicit On
Module Module2
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Integer) As Integer
Delegate Function SubClassProcDelegate(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Function EnumWindowsProc(ByVal hWnd As Integer, ByVal lParam As Integer) As Boolean
Dim sWindowText As String
Dim Ret As Long
Ret = GetWindowTextLength(hWnd)
sWindowText = Space(Ret)
GetWindowText(hWnd, sWindowText, Ret + 1)
If Ret > 0 Then
If sWindowText Like "notpad*" Then
' Debug.Print sWindowText
MessageBox "Found it"
End If
End If
EnumWindowsProc = True
End Function
End Module
and this in a button click
EnumWindows(AddressOf EnumWindowsProc, 0)
I keep get this
'UPGRADE_WARNING: Add a delegate for AddressOf EnumWindowsProc Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
so I add this to the Module
Code:
Delegate Function SubClassProcDelegate(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
but that didn't seem to help
here the vb6 code before I change it
Code:
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim sWindowText As String
Dim Ret As Long
Ret = GetWindowTextLength(hWnd)
sWindowText = Space(Ret)
GetWindowText hWnd, sWindowText, Ret + 1
If Ret > 0 Then
If sWindowText Like "notpad*" Then
' Debug.Print sWindowText
MsgBox "found it"
End If
End If
EnumWindowsProc = True
End Function
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
Re: try to convert this to vb.net need help
vb Code:
Public Class Form1
<Runtime.InteropServices.DllImport("user32", SetLastError:=True)> _
Public Shared Function EnumWindows( _
ByVal lpEnumFunc As EnumWindowsDelegate, _
ByVal lParam As IntPtr) As Boolean
End Function
Delegate Function EnumWindowsDelegate(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Boolean
Dim CallBack As New EnumWindowsDelegate(AddressOf EnumWindowsProc)
Public Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
'...
'...
'...
EnumWindowsProc = True
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
EnumWindows(CallBack, IntPtr.Zero)
End Sub
End Class
IParam type can be any basic type not just IntPtr. If you need to pass a value lets say string type than change its type from IntPtr to string in every definition and signature.
Re: try to convert this to vb.net need help
thank you!!! VBDT that works great!!!!