Results 1 to 3 of 3

Thread: [RESOLVED] try to convert this to vb.net need help

  1. #1

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Resolved [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&
    Live life to the fullest!!

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: try to convert this to vb.net need help

    vb Code:
    1. Public Class Form1
    2.  
    3.     <Runtime.InteropServices.DllImport("user32", SetLastError:=True)> _
    4.     Public Shared Function EnumWindows( _
    5.     ByVal lpEnumFunc As EnumWindowsDelegate, _
    6.     ByVal lParam As IntPtr) As Boolean
    7.     End Function
    8.  
    9.     Delegate Function EnumWindowsDelegate(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Boolean
    10.  
    11.     Dim CallBack As New EnumWindowsDelegate(AddressOf EnumWindowsProc)
    12.  
    13.     Public Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
    14.         '...
    15.         '...
    16.         '...
    17.         EnumWindowsProc = True
    18.     End Function
    19.  
    20.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    21.         EnumWindows(CallBack, IntPtr.Zero)
    22.     End Sub
    23.  
    24. 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.

  3. #3

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: try to convert this to vb.net need help

    thank you!!! VBDT that works great!!!!
    Live life to the fullest!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width