VB.NET-Quellcode
- Public Class Form1
- 'Fenster auf neue Position setzen
- Private Declare Function SetWindowPos Lib "user32.dll" ( _
- ByVal hwnd As Int32, _
- ByVal hWndInsertAfter As Int32, _
- ByVal x As Int32, _ '-----------------Fenster Position
- ByVal y As Int32, _ '-----------------Fenster Position
- ByVal cx As Int32, _ '------------------Fenstergröße
- ByVal cy As Int32, _ '-----------------Fenstergröße
- ByVal wFlags As Int32) As Int32
- Private Const HWND_NOTOPMOST As Int32 = -2
- Private Const SWP_SHOWWINDOW As Int32 = &H40
- 'Fenster position ermitteln/auslesen
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
- Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As IntPtr, ByRef lpRect As RECT) As Integer
- Private Structure RECT
- Public Left As Int32
- Public Top As Int32
- Public Right As Int32
- Public Bottom As Int32
- End Structure
- Private NotepadHandle As Integer
- 'Fenster position ermitteln/auslesen
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim NotepadRect As RECT
- NotepadHandle = FindWindow("Notepad", vbNullString)
- MsgBox(NotepadHandle)
- GetWindowRect(NotepadHandle, NotepadRect)
- MsgBox("Top = " & NotepadRect.Top & _
- vbCrLf & "Bottom = " & NotepadRect.Bottom & _
- vbCrLf & "Left = " & NotepadRect.Left & _
- vbCrLf & "Right = " & NotepadRect.Right)
- End Sub
- 'Fenster position und größe neu setzen
- Private Sub Funktion NeuPos ( intX As Integer, intY As Integer, intCX As Integer, intCY As Integer)
- 'Werte inteX, intY neue Fensterposition
- 'Werte intCX, intCY neue Fenstergröße
- SetWindowPos(NotepadHandle, HWND_NOTOPMOST, intX, intY, intCX, intCY, SWP_SHOWWINDOW)
- End Sub
- End Class
Viel spaß !
Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „Alex2000“ ()