waldgnarf
Goto Top

VB.Net firefox URL in den Zwischenspeicher

Hallo, ich habe gelesen das die Adressenleiste von Firefox kein Handle hat, und wollte es mit SendKeys versuchen die URL in den Zwischenspeicher zu kopieren.
Das Fenster wird zwar gefunden und ist dann im Vordergrund aber bei SendKeys Anweisung wird das Firefoxfenster inaktiviert.

Imports System.Threading

Public Class COPIER
    Dim MOZILL As String = "- Mozilla Firefox"  
    Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Int32) As Int32  
    Public Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean  
    Public Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam As Int32) As Boolean
    Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Int32) As Int32  
    Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Int32  
    Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Int32) As Int32  
    Public Declare Function GetParent Lib "user32.dll" (ByVal intptr As IntPtr) As IntPtr  
    Public Const GWL_HWNDPARENT As Int32 = -8
    Private NEWILI As List(Of String)
    Public Declare Function GetConsoleTitle Lib "kernel32" Alias "GetConsoleTitleA" (ByVal lpConsoleTitle As String, ByVal nSize As Integer) As Integer  
    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  
    Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer  
    Declare Auto Function FindWindow Lib "USER32.DLL" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr  
    Declare Auto Function SetForegroundWindow Lib "USER32.DLL" (ByVal hWnd As IntPtr) As Boolean  

    Private Sub COPIER_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Minimized

        NEWILI = New List(Of String)
        EnumWindows(AddressOf ENVIPR, CInt(True))

        For Each FENSTE As String In NEWILI
            If InStr(FENSTE, MOZILL) > 0 Then
                MOZILL = FENSTE
                Exit For
            End If
        Next
        ShowWindow(FindWindow(vbNullString, MOZILL), 1)
        SetForegroundWindow(FindWindow(vbNullString, MOZILL))

        Thread.Sleep(900)

        SendKeys.Send("^L")  
        SendKeys.Send("^C")  
    End Sub

    Private Function ENVIPR(ByVal hwnd As IntPtr, ByVal lParam As Int32) As Boolean
        If GetParent(hwnd) = IntPtr.Zero Then
            If GetWindowLong(hwnd, GWL_HWNDPARENT) = 0 Then
                Dim str As String = String.Empty.PadLeft(GetWindowTextLength(hwnd) + 1)
                GetWindowText(hwnd, str, str.Length)
                If Not String.IsNullOrEmpty(str.Substring(0, str.Length - 1)) Then NEWILI.Add(str.Substring(0, str.Length - 1))
            End If
        End If
        ENVIPR = True
    End Function
 
End Class

Gibt es eine Möglichkeit an die URL zu kommen?

Gruß waldgnarf

Content-Key: 130433

Url: https://administrator.de/contentid/130433

Printed on: April 23, 2024 at 11:04 o'clock

Member: TsukiSan
TsukiSan Nov 29, 2009 at 10:10:45 (UTC)
Goto Top
Hallo waldgnarf,

das ist zwar VB5/6 aber es gibt dir eventuell einen Hinweis für VB.Net

Gruss und schönen Advent

Tsuki
Member: waldgnarf
waldgnarf Nov 29, 2009 at 16:28:11 (UTC)
Goto Top
Hallo, ich geh das jetzt anders an, hab mir einen Webbrowser gemacht.
Jetzt steh ich allerdings wieder vor ein anderes Problem.
Ich habe Tabs in denen Webbrowser generiert werden die zu URLs navigieren, syncron zum ersten Webbrowser.
Also wenn der im ersten Tab befindliche Webbrowser1 durch clicken auf einen Link weiter navigiert öffnet sich ein neuer Tab2+Webbrowser2 und navigiert zur Webbrowser1 URL und so weiter.

Jetzt hab ich massig Tabs+Webbrowser mit unterschiedlichen URLs :D und will nun die URLs der Tabs+Webbrowser einzeln ausgeben, aber wie weiss ich nicht.

Private Sub BURLSL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BURLSL.Click

        For Each BROTAB In TABCON.TabCount.ToString
            MsgBox(NEWWEB(A).Url.AbsoluteUri)
        Next
        
    End Sub

    Private Sub WBMAIN_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WBMAIN.Navigated
        For A = 0 To TABCON.TabCount
        Next

        NEWTAB(A) = New TabPage
        NEWWEB(A) = New WebBrowser

        TABCON.Controls.Add(NEWTAB(A))
        NEWTAB(A).Name = "NEWTAB" & A  
        NEWTAB(A).Text = "NEWTAB" & A  


        NEWTAB(A).Controls.Add(NEWWEB(A))
        NEWWEB(A).Dock = DockStyle.Fill
        NEWWEB(A).Navigate(WBMAIN.Url.AbsoluteUri)

'URLLIS = URLLIS & NEWWEB(A).Url.AbsoluteUri & vbNewLine   -----------MsgBox(URLLIS ) in BURLSL_Click gibt auch ein fehler  

    End Sub

Gruß waldgnarf
Member: waldgnarf
waldgnarf Nov 29, 2009 at 22:56:16 (UTC)
Goto Top
Habe es mit : URLLIS = URLLIS & e.Url.AbsoluteUri & vbNewLine
hin bekommen.

Gruß waldgnarf