home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 77 / IOPROG_77.ISO / tips / Visual Basic / AutoComplete / Auto Complete / AutoCompleteForm.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2003-12-19  |  4.7 KB  |  128 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Autocomplete-form per IE"
  5.    ClientHeight    =   4560
  6.    ClientLeft      =   1275
  7.    ClientTop       =   1725
  8.    ClientWidth     =   4695
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   4560
  13.    ScaleWidth      =   4695
  14.    Begin VB.CommandButton cmdPasswords 
  15.       Caption         =   "Esegui &scansione delle finestre aperte"
  16.       Height          =   495
  17.       Left            =   120
  18.       TabIndex        =   1
  19.       Top             =   3960
  20.       Width           =   4455
  21.    End
  22.    Begin VB.TextBox txtPasswords 
  23.       Height          =   3735
  24.       Left            =   120
  25.       Locked          =   -1  'True
  26.       MultiLine       =   -1  'True
  27.       ScrollBars      =   3  'Both
  28.       TabIndex        =   0
  29.       Top             =   120
  30.       Width           =   4455
  31.    End
  32. Attribute VB_Name = "frmMain"
  33. Attribute VB_GlobalNameSpace = False
  34. Attribute VB_Creatable = False
  35. Attribute VB_PredeclaredId = True
  36. Attribute VB_Exposed = False
  37. Option Explicit
  38. Private winTitolo As String
  39. 'Verifico se l'oggetto passatomi e' un campo di tipo password
  40. Private Function IsPasswordBox(Elemento As Object) As Boolean
  41.     On Error GoTo err_password
  42.     If LCase(Elemento.getAttribute("Type")) = "password" Then
  43.         IsPasswordBox = True
  44.     Else
  45.         IsPasswordBox = False
  46.     End If
  47.     Exit Function
  48. err_password:
  49.     IsPasswordBox = False
  50. End Function
  51. 'Verifico se il campo e' una text box
  52. Private Function IsTextBox(Elemento As Object) As Boolean
  53.     On Error GoTo err_text
  54.     If LCase(Elemento.getAttribute("Type")) = "text" Then
  55.         IsTextBox = True
  56.     Else
  57.         IsTextBox = False
  58.     End If
  59.     Exit Function
  60. err_text:
  61.     IsTextBox = False
  62. End Function
  63. Private Function CercaCampi(Documento As Object) As Boolean
  64.     Dim Elemento As Object
  65.     Dim numOggetti As Long
  66.     Dim indiceOggetti As Long
  67.     Dim Trovato As Boolean
  68.     Dim ok As Integer
  69.     'Prendo il numero degli oggetti nel documento
  70.     numOggetti = Documento.All.length
  71.     txtPasswords.Text = txtPasswords.Text & "Titolo: " & winTitolo & vbCrLf & vbCrLf
  72.     'Scorro gli elementi fino a trovarne uno di tipo password o text
  73.     For indiceOggetti = 0 To numOggetti - 1
  74.         DoEvents
  75.         Set Elemento = Documento.All.Item(indiceOggetti)
  76.         'Verifico se e' una password-box e la riempio con la parola pluto
  77.         If IsPasswordBox(Elemento) Then
  78.             'Il false serve per rendere case-insensitive la ricerca dell'attributo value
  79.             ok = Elemento.setAttribute("Value", "pluto", False)
  80.             txtPasswords.Text = txtPasswords.Text & "Password: " & Elemento.getAttribute("Value") & vbCrLf & vbCrLf
  81.             Trovato = True
  82.         End If
  83.         'Verifico se e' una text-box e la riempio con la parola paperino
  84.         If IsTextBox(Elemento) Then
  85.             'Il false serve per rendere case-insensitive la ricerca dell'attributo value
  86.             ok = Elemento.setAttribute("Value", "paperino", False)
  87.             txtPasswords.Text = txtPasswords.Text & "User: " & Elemento.getAttribute("Value") & vbCrLf & vbCrLf
  88.             Trovato = True
  89.         End If
  90.     Next
  91.     numOggetti = Documento.frames.length
  92.     'Eseguo la verifica anche su eventuali frame nella pagina
  93.     For indiceOggetti = 0 To numOggetti - 1
  94.         'Esegui la ricerca anche in questi frame
  95.         If CercaCampi(Documento.frames.Item(indiceOggetti).document) Then Trovato = True
  96.     Next
  97.     CercaCampi = Trovato
  98. End Function
  99. Private Sub Scansiona()
  100.     Dim objShellWins As New SHDocVw.ShellWindows
  101.     Dim objExplorer As SHDocVw.InternetExplorer
  102.     Dim Documentoument As HTMLDocument
  103.     Dim Trovato As Boolean
  104.     Dim Eseguito As Boolean
  105.     txtPasswords = "Aspetta......." & vbCrLf & vbCrLf
  106.     Screen.MousePointer = vbHourglass
  107.     'Scorri tutte le fineste aperte
  108.     For Each objExplorer In objShellWins
  109.         If TypeOf objExplorer.document Is HTMLDocument Then
  110.             Set Documentoument = objExplorer.document
  111.             'Salva il titolo cosi' da poterle riconoscere
  112.             winTitolo = Documentoument.Title
  113.             'Comincia la ricerca nel documento
  114.             Eseguito = CercaCampi(Documentoument)
  115.             If Eseguito Then Trovato = True
  116.         End If
  117.     Next
  118.     If Not Trovato Then
  119.         txtPasswords.Text = txtPasswords.Text & "User e password non presenti." & vbCrLf & vbCrLf
  120.     Else
  121.         txtPasswords.Text = txtPasswords.Text & "OK. Grazie." & vbCrLf
  122.     End If
  123.     Screen.MousePointer = vbDefault
  124. End Sub
  125. Private Sub cmdPasswords_Click()
  126.     Scansiona
  127. End Sub
  128.