Fensterausrichtung mit VBA
marspoki
Ich möchte gerne mit Hilfe von VBA ein Programmfenster z.B. Outlook an eine ganz bestimmt Stelle am Bildschirm verschieben.
Mit dem Editor funktioniert der Unten aufgeführte Code wunderbar. Warum nicht mit Outlook oder anderen Programmen?
Habe natürlich die Zeilen verändert gehabt.
Vielen Dank
beste grüße
Masrpoki
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