ok Andrea, adesso non ci sono errori e il codice completo che ho usato mischiando la prima parte della mia idea con la tua, è questo . . ma nella Label1 di controllo vedo solo il titolo della finestra del browser e non l'indirizzo . . perchè l'urlHandle resta sempre = 0
Questo 'Chrome_AutocompleteEditView' . . .è proprio quello che dobbiamo cercare?
codice:Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Const WM_GETTEXTLENGTH As Integer = &HE Private Const WM_GETTEXT As Integer = &HD Dim title As String Dim handle As Long, length As Long Private Sub Timer1_Timer() ' intervallo impostato nelle proprietà a 300 millisecondi handle = GetForegroundWindow length = GetWindowTextLength(handle) title = String(length, Chr$(0)) GetWindowText handle, title, length + 1 If InStr(title, "Google Chrome") > 0 Then Label1 = title + ">>" + getChromeUrl(handle) End Sub Public Function getChromeUrl(winHandle As Long) As String Const nChars As Integer = 256 Dim browserUrl As String Dim urlHandle As Integer Dim b As String Dim length As Integer browserUrl = "" length = SendMessage(urlHandle, WM_GETTEXTLENGTH, 0, 0) urlHandle = FindWindowEx(winHandle, 0, "Chrome_AutocompleteEditView", "") ' l' urlHandle non trova mai nulla <<<<<<<<<<<<<<<<<<<<<< If length > 0 Then b = String(nChars, " ") SendMessage urlHandle, WM_GETTEXT, nChars, b browserUrl = b End If getChromeUrl = browserUrl End Function

Rispondi quotando