Newsgroup: it.comp.lang.visual-basic
Titolo: Aiuto

Salve chi mi aiuta con questa funzione non mi funziona e non capisco perchč
?
Grazie in Anticipo
Public lstEnumRef As ListBox
Private Sub Form_Activate()
f = EnumWindows(AddressOf EnumWndproc, c)
    lbresult = "Window count:" & c
End Sub
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long,
lParam As Any) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal
hwnd As Long, ByVal lpstring As String, ByVal nMaxCount As Long) As Long
'********************
'**********************
Function EnumWndproc(ByVal hwnd As Long, lParam As Long) As Long    '
Incrementa il contatore
    lParam = lParam + 1
    ' Prende il titolo della finestra e lo inserisce nella listBox
    Dim s As String
    s = WindowTextFromWnd(hwnd)
    If s <> sempety Then
        lstEnumRef.AddItem.s
        lstEnumRef.ItemData(lstEnumRef.NewIndex) = hwnd
    End If
    'Restituisce True per continuare ad enumerare
    EnumWndproc = True
End Function
Function WindowTextFromWnd(ByVal hwnd As Long) As String
    Dim c As Integer, s As String
    c = GetWindowTextLength(hwnd)
    If c <= 0 Then Exit Function
    c = String$(c, 0)
    c = GetWindowText(hwnd, s, c + 1)
    WindowTextFromWnd = s
End Function
Function GetWindowTextLength(ByVal hwnd As Long) As Long
   Dim sTemp As String, sTitle As String, c As Integer
    sTemp = String$(255, 0)
    c = GetWindowText(hwnd, sTemp, 256)
    sTitle = Left$(sTemp, c)
End Function
--
Fulvio

 ?
Ho corretto qualche istruzione nel recupero del testo: in pratica la
lunghezza era sempre 0, e quindi non inseriva nulla nella listbox.
Inserisci nella form una ListBox, cosě da controllare i risultati (ma va
bene anche quello in memoria).
Provala ora:
==FORM==
Private Sub Form_Activate()
Dim c As Long, f As Long
f = EnumWindows(AddressOf EnumWndproc, c)
Me.Caption = "Window count:" & c
End Sub
==BAS==
'Public lstEnumRef As ListBox
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long,
lParam As Any) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpstring As String, ByVal nMaxCount As Long) As
Long
Function EnumWndproc(ByVal hwnd As Long, lParam As Long) As Long    '
'Incrementa il contatore
    lParam = lParam + 1
    ' Prende il titolo della finestra e lo inserisce nella listBox
    Dim s As String
    s = WindowTextFromWnd(hwnd)
    If s <> "" Then
        Form1.lstEnumRef.AddItem s
        Form1.lstEnumRef.ItemData(Form1.lstEnumRef.NewIndex) = hwnd
    End If
    'Restituisce True per continuare ad enumerare
    EnumWndproc = True
End Function
Function WindowTextFromWnd(ByVal hwnd As Long) As String
    Dim c As Integer, s As String
    c = GetWindowTextLength(hwnd)
    If c <= 0 Then Exit Function
    s = String$(c, 0)
    c = GetWindowText(hwnd, s, c + 1)
    WindowTextFromWnd = s
End Function
Function GetWindowTextLength(ByVal hwnd As Long) As Long
   Dim sTemp As String, sTitle As String, c As Integer
    sTemp = String$(255, 0)
    c = GetWindowText(hwnd, sTemp, 256)
    sTitle = Left$(sTemp, c)
    GetWindowTextLength = Len(sTitle)
End Function
==END==
Michele
--
Per l'e-mail togli "xxx".
Home page: 
http://spazioweb.inwind.it/fochinet

esiste un api per sapere quanto è lungo la caption
ti riporto il codice corretto
'IN MODULE1.BAS
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As
Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As
Long
  Dim slength As Long, buffer As String
  Dim retval As Long
  Static winnum As Integer
  winnum = winnum + 1
  slength = GetWindowTextLength(hwnd) + 1
  If slength > 1 Then
    buffer = Space(slength)
    retval = GetWindowText(hwnd, buffer, slength)
    Debug.Print "Window #"; winnum; " : ";
    Debug.Print Left(buffer, slength - 1)
  End If
  EnumWindowsProc = 1
End Function
'IN FORM1.BAS
Private Sub Form_Load()
    Dim retval As Long
    retval = EnumWindows(AddressOf EnumWindowsProc, 0)
End Sub
'END CODE
questo codice naturalment piazza tutto nell0immediate window (debug) basta
sostituire debug.print con list1.additem come facevi tu.
per contare le finestre basto contare  gli item in list1
ciao
potresti adattare anche il tuo codice
L2K

Cosa significa number cruncing? Come posso tradurlo? Grazie!