Position eines Fensters ermitteln

  • VB.NET

Es gibt 13 Antworten in diesem Thema. Der letzte Beitrag () ist von BlackRazor.

    Position eines Fensters ermitteln

    Hi,
    also ich habe ein programm, dass eine externe anwendung ausführt..gibt es eine möglichkeit, die position des fensters zu ermitteln?
    Oder das fenster des gestarteten programmen von anfang an an einer bestimmten stelle anzeigen, dann hätte man ja die position auch.
    Ich hoffe, mir kann da jemand helfen..
    mfg blackrazor
    Ich will auf eine bestimmte stelle in dem programm klicken ^^
    Dachte mir, dass ich halt die position des fensters ermittel, die koordinaten von diesem punkt aus addiere und auf das ergebnis die maus bewege und klicke.

    Bin inzwischen schon bei GetWindowRect gelandet...aber hab leider schon wieder das nächste problem :(

    VB.NET-Quellcode

    1. Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
    2. Public Structure RECT
    3. Public Left As Long
    4. Public Top As Long
    5. Public Right As Long
    6. Public Bottom As Long
    7. End Structure
    8. Dim r As RECT
    9. Public Function runProc(ByVal filename As String)
    10. Dim procId As Integer
    11. Dim proc As Diagnostics.Process
    12. proc = Diagnostics.Process.Start(filename)
    13. procId = proc.Id
    14. GetWindowRect(procId, r)
    15. MsgBox("Left=" & vbTab & r.Left & vbCr & _
    16. "Top=" & vbTab & r.Top & vbCr & _
    17. "Height=" & vbTab & r.Bottom - r.Top & vbCr & _
    18. "Width=" & vbTab & r.Right - r.Left)
    19. End Function


    Jetzt bekomm ich aber immer die Meldung "Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist."

    Kann mir da vllt nochmal jemand helfen?^^
    Ahh ok, dann weiß ich bescheid.
    Danke für deine hilfe ;)

    edit: hm...es geht immernoch nicht :S Immernoch der selbe fehler

    VB.NET-Quellcode

    1. Dim hwnd = FindWindow(vbNullString, "Rechner")
    2. GetWindowRect(hwnd, r)

    (hab das jetzt einfach mal miit der calc.exe versucht)
    Ist doch richtig, oder? ^^

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „BlackRazor“ ()

    Versuchs mal so:

    VB.NET-Quellcode

    1. Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
    2. Public Structure RECT
    3. Public Left As Long
    4. Public Top As Long
    5. Public Right As Long
    6. Public Bottom As Long
    7. End Structure
    8. Private r As New RECT ' schlüsselwort New!
    9. Public Function runProc(ByVal filename As String)
    10. GetWindowRect(Me.Handle, r)
    11. MsgBox("Left=" & vbTab & r.Left & vbCr & _
    12. "Top=" & vbTab & r.Top & vbCr & _
    13. "Height=" & vbTab & r.Bottom - r.Top & vbCr & _
    14. "Width=" & vbTab & r.Right - r.Left)
    15. End Function
    Hab endlich den fehler gefunden:

    VB.NET-Quellcode

    1. Declare Auto Function GetWindowRect Lib "User32" (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Int32
    2. Public Structure RECT
    3. Public Left As Int32
    4. Public Top As Int32
    5. Public Right As Int32
    6. Public Bottom As Int32
    7. End Structure

    Das Auto und Int32 scheint alles zu beheben...