OVH Cloud OVH Cloud

Delegate vb.net

2 réponses
Avatar
Sebastien
bonjour,



j'ai un petit probleme pour convertire les api que j'utilisais sous vb6 vers
vb.net

j'ai changé mes long en integer, mais il me souleve quand meme un probleme
dans cette fonction pour fair une enumeration, il me dit Integer n'es pa un
type delegate... chaque fosi que j'utilise un adresseof sur une api.

est ce que qq connais la maniere de declarer ou coder ces lignes ?

je vous en remerci,

bonne journée,

Sebastien

'---------------------------------

'Add this code to a form

Private Sub EnumLesObject()

'KPD-Team 2000

'URL: http://www.allapi.net/

'E-Mail: KPDTeam@Allapi.net

'Set the form's graphics mode to persistent

'call the Enumwindows-function

EnumWindows(AddressOf EnumWindowsProc, 0&)

End Sub

'Add this code to a module

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Int32, ByVal
lParam As Int32) 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

Public Function EnumWindowsProc(ByVal hwnd As Object, ByVal lParam As
Object) As Boolean

Dim sSave As String, Ret As Integer

Ret = GetWindowTextLength(hwnd)

sSave = Space(Ret)

GetWindowText(hwnd, sSave, Ret + 1)

Console.WriteLine(Str$(hwnd) + " " + sSave)

'continue enumeration

EnumWindowsProc = True

End Function

'---------------------------------

2 réponses

Avatar
Eric Vernié [MS]
Bonjour Sebastien,

voici comment procéder :

1) tu créez le delegate comme ceci
Public Delegate Function Rappel( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr) As Boolean

2) Tu declare EnumWindows avec comme 1er paramètre le delegate "Rappel"

Public Declare Function EnumWindows Lib "user32" ( _
ByVal lpEnumFunc As Rappel, _
ByVal lParam As IntPtr) As Boolean

3) Tu crées la méthode de rappel avec la signature du delegate

Private Function MaMethode( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr) As Boolean

'Ajoutes ton code ici
Return True
End Function

4) tu appels enumwindows comme ceci.
EnumWindows(AddressOf MaMethode, 0&)

Bon Weekend

Eric Vernié
Microsoft France






"Sebastien" a écrit dans le message de news:
420225c5$0$17081$
bonjour,



j'ai un petit probleme pour convertire les api que j'utilisais sous vb6
vers vb.net

j'ai changé mes long en integer, mais il me souleve quand meme un probleme
dans cette fonction pour fair une enumeration, il me dit Integer n'es pa
un type delegate... chaque fosi que j'utilise un adresseof sur une api.

est ce que qq connais la maniere de declarer ou coder ces lignes ?

je vous en remerci,

bonne journée,

Sebastien

'---------------------------------

'Add this code to a form

Private Sub EnumLesObject()

'KPD-Team 2000

'URL: http://www.allapi.net/

'E-Mail:

'Set the form's graphics mode to persistent

'call the Enumwindows-function

EnumWindows(AddressOf EnumWindowsProc, 0&)

End Sub

'Add this code to a module

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Int32,
ByVal lParam As Int32) 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

Public Function EnumWindowsProc(ByVal hwnd As Object, ByVal lParam As
Object) As Boolean

Dim sSave As String, Ret As Integer

Ret = GetWindowTextLength(hwnd)

sSave = Space(Ret)

GetWindowText(hwnd, sSave, Ret + 1)

Console.WriteLine(Str$(hwnd) + " " + sSave)

'continue enumeration

EnumWindowsProc = True

End Function

'---------------------------------




Avatar
Sebastien
merci, merci !!!!!!
++
seb

"Eric Vernié [MS]" a écrit dans le message de
news:
Bonjour Sebastien,

voici comment procéder :

1) tu créez le delegate comme ceci
Public Delegate Function Rappel( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr) As Boolean

2) Tu declare EnumWindows avec comme 1er paramètre le delegate "Rappel"

Public Declare Function EnumWindows Lib "user32" ( _
ByVal lpEnumFunc As Rappel, _
ByVal lParam As IntPtr) As Boolean

3) Tu crées la méthode de rappel avec la signature du delegate

Private Function MaMethode( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr) As Boolean

'Ajoutes ton code ici
Return True
End Function

4) tu appels enumwindows comme ceci.
EnumWindows(AddressOf MaMethode, 0&)

Bon Weekend

Eric Vernié
Microsoft France






"Sebastien" a écrit dans le message de news:
420225c5$0$17081$
bonjour,



j'ai un petit probleme pour convertire les api que j'utilisais sous vb6
vers vb.net

j'ai changé mes long en integer, mais il me souleve quand meme un
probleme dans cette fonction pour fair une enumeration, il me dit Integer
n'es pa un type delegate... chaque fosi que j'utilise un adresseof sur
une api.

est ce que qq connais la maniere de declarer ou coder ces lignes ?

je vous en remerci,

bonne journée,

Sebastien

'---------------------------------

'Add this code to a form

Private Sub EnumLesObject()

'KPD-Team 2000

'URL: http://www.allapi.net/

'E-Mail:

'Set the form's graphics mode to persistent

'call the Enumwindows-function

EnumWindows(AddressOf EnumWindowsProc, 0&)

End Sub

'Add this code to a module

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Int32,
ByVal lParam As Int32) 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

Public Function EnumWindowsProc(ByVal hwnd As Object, ByVal lParam As
Object) As Boolean

Dim sSave As String, Ret As Integer

Ret = GetWindowTextLength(hwnd)

sSave = Space(Ret)

GetWindowText(hwnd, sSave, Ret + 1)

Console.WriteLine(Str$(hwnd) + " " + sSave)

'continue enumeration

EnumWindowsProc = True

End Function

'---------------------------------