AW: Fenster verschieben mit VBA
14.09.2009 17:53:27
Nepumuk
Hallo,
ein Beispiel in dem das Editorfenster nach oben links (Pos. 0, 0) verschoben wird:
Option Explicit
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Private Declare Function MoveWindow Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByRef lpRect As RECT) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const GC_CLASSNAMENOTEPAD = "Notepad"
Public Sub test()
Dim hWnd As Long, lngReturn As Long
Dim udtRECT As RECT
Dim strClassName As String
AppActivate "Unbenannt - Editor", True
hWnd = GetForegroundWindow
If hWnd <> 0 Then
strClassName = Space(256)
lngReturn = GetClassName(hWnd, strClassName, 256)
If Left$(strClassName, lngReturn) = GC_CLASSNAMENOTEPAD Then
Call GetWindowRect(hWnd, udtRECT)
With udtRECT
Call MoveWindow(hWnd, 0, 0, .Right - .Left, .Bottom - .Top, -1)
End With
End If
End If
End Sub
Gruß
Nepumuk