Position von Fremde Fenster ermitteln und setzen

    • VB.NET

    Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von NscMike.

      Position von Fremde Fenster ermitteln und setzen

      VB.NET-Quellcode

      1. Public Class Form1
      2. 'Fenster auf neue Position setzen
      3. Private Declare Function SetWindowPos Lib "user32.dll" ( _
      4. ByVal hwnd As Int32, _
      5. ByVal hWndInsertAfter As Int32, _
      6. ByVal x As Int32, _ '-----------------Fenster Position
      7. ByVal y As Int32, _ '-----------------Fenster Position
      8. ByVal cx As Int32, _ '------------------Fenstergröße
      9. ByVal cy As Int32, _ '-----------------Fenstergröße
      10. ByVal wFlags As Int32) As Int32
      11. Private Const HWND_NOTOPMOST As Int32 = -2
      12. Private Const SWP_SHOWWINDOW As Int32 = &H40
      13. 'Fenster position ermitteln/auslesen
      14. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
      15. Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As IntPtr, ByRef lpRect As RECT) As Integer
      16. Private Structure RECT
      17. Public Left As Int32
      18. Public Top As Int32
      19. Public Right As Int32
      20. Public Bottom As Int32
      21. End Structure
      22. Private NotepadHandle As Integer
      23. 'Fenster position ermitteln/auslesen
      24. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      25. Dim NotepadRect As RECT
      26. NotepadHandle = FindWindow("Notepad", vbNullString)
      27. MsgBox(NotepadHandle)
      28. GetWindowRect(NotepadHandle, NotepadRect)
      29. MsgBox("Top = " & NotepadRect.Top & _
      30. vbCrLf & "Bottom = " & NotepadRect.Bottom & _
      31. vbCrLf & "Left = " & NotepadRect.Left & _
      32. vbCrLf & "Right = " & NotepadRect.Right)
      33. End Sub
      34. 'Fenster position und größe neu setzen
      35. Private Sub Funktion NeuPos ( intX As Integer, intY As Integer, intCX As Integer, intCY As Integer)
      36. 'Werte inteX, intY neue Fensterposition
      37. 'Werte intCX, intCY neue Fenstergröße
      38. SetWindowPos(NotepadHandle, HWND_NOTOPMOST, intX, intY, intCX, intCY, SWP_SHOWWINDOW)
      39. End Sub
      40. End Class



      Viel spaß ! :thumbup:

      Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „Alex2000“ ()

      hier eine aktualisierte Version:

      VB.NET-Quellcode

      1. 'Fenster auf neue Position setzen
      2. Private Declare Function SetWindowPos Lib "user32.dll" ( _
      3. ByVal hwnd As Int32, _
      4. ByVal hWndInsertAfter As Int32, _
      5. ByVal x As Int32, _
      6. ByVal y As Int32, _
      7. ByVal cx As Int32, _
      8. ByVal cy As Int32, _
      9. ByVal wFlags As Int32) As Int32
      10. Private Const HWND_NOTOPMOST As Int32 = -2
      11. Private Const SWP_SHOWWINDOW As Int32 = &H40
      12. 'Fenster position ermitteln/auslesen
      13. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
      14. Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As IntPtr, ByRef lpRect As RECT) As Integer
      15. Private Structure RECT
      16. Public Left As Int32
      17. Public Top As Int32
      18. Public Right As Int32
      19. Public Bottom As Int32
      20. End Structure
      21. Private NotepadHandle As Integer
      22. 'Fenster position ermitteln/auslesen
      23. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      24. Dim NotepadRect As RECT
      25. NotepadHandle = FindWindow("Notepad", vbNullString)
      26. MsgBox(NotepadHandle)
      27. GetWindowRect(NotepadHandle, NotepadRect)
      28. MsgBox("Top = " & NotepadRect.Top & _
      29. vbCrLf & "Bottom = " & NotepadRect.Bottom & _
      30. vbCrLf & "Left = " & NotepadRect.Left & _
      31. vbCrLf & "Right = " & NotepadRect.Right)
      32. End Sub
      33. 'Fenster position und größe neu setzen
      34. Private Sub NeuePos(ByVal intX As Integer, ByVal intY As Integer, ByVal intCX As Integer, ByVal intCY As Integer)
      35. 'Werte inteX, intY neue Fensterposition
      36. 'Werte intCX, intCY neue Fenstergröße
      37. SetWindowPos(NotepadHandle, HWND_NOTOPMOST, intX, intY, intCX, intCY, SWP_SHOWWINDOW)
      38. End Sub
      Für ein Mindestmaß an Rechtschreibung, Interpunktion und Majuskeln!
      ich habe die Kommentare gelöscht:

      Brainfuck-Quellcode

      1. ByVal x As Int32, _ '-----------------Fenster Position
      2. ByVal y As Int32, _ '-----------------Fenster Position
      3. ByVal cx As Int32, _ '------------------Fenstergröße
      4. ByVal cy As Int32, _ '-----------------Fenstergröße


      und das "Funktion" entfernt aus:

      Quellcode

      1. Private Sub Funktion NeuPos ( intX As Integer[...]



      mehr wars glaube ich nicht
      Für ein Mindestmaß an Rechtschreibung, Interpunktion und Majuskeln!