Hallo zusammen
Kann mir jemand sagen, wie ich es bewerkstelligen kann, dass ein neues Fenster genau an der Position, wo ich einen Button gedrückt habe, positioniert wird?
TIA & Gruss
Martin Bucher, Zürich
Hallo zusammen
Kann mir jemand sagen, wie ich es bewerkstelligen kann, dass ein neues Fenster genau an der Position, wo ich einen Button gedrückt habe, positioniert wird?
TIA & Gruss
Martin Bucher, Zürich
Das geht etwa so:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type Rect
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type WINDOWPLACEMENT
length As Long
Flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As Rect
End Type
Private Const FrameWidth = 3, CaptionHeight = 19, TwipsPerPix = 12
Private Declare Function SetWindowPlacement Lib "User32" \_
(ByVal HWnd As Long, lpWndPl As WINDOWPLACEMENT) As Long
Private Declare Function GetWindowPlacement Lib "User32" \_
(ByVal HWnd As Long, lpWndPl As WINDOWPLACEMENT) As Long
Private Sub ButtonMove\_Click()
Dim WPl As WINDOWPLACEMENT, MeWPl As WINDOWPLACEMENT
Dim HWnd As Long, lRet As Long
DoCmd.OpenForm "frmButton"
HWnd = Forms("frmButton").HWnd
WPl.length = Len(WPl)
MeWPl.length = Len(MeWPl)
lRet = GetWindowPlacement(Me.HWnd, MeWPl)
lRet = GetWindowPlacement(HWnd, WPl)
With WPl.rcNormalPosition
.top = MeWPl.rcNormalPosition.top + Me!ButtonMove.top \ TwipsPerPix + CaptionHeight + FrameWidth
.left = MeWPl.rcNormalPosition.left + Me!ButtonMove.left \ TwipsPerPix + FrameWidth
.bottom = .top + Me!ButtonMove.Height \ TwipsPerPix + FrameWidth
.right = .left + Me!ButtonMove.Width \ TwipsPerPix + FrameWidth
End With
lRet = SetWindowPlacement(HWnd, WPl)
End Sub
Reinhard
[Bei dieser Antwort wurde das Vollzitat nachträglich automatisiert entfernt]
Hallo Reinhard
Vielen Dank für Deine Antwort.
Damit die Sache funktioniert, sollte ich auch noch die Funktion „GetWindowPlacement“ haben. Würdest Du mir die noch posten?
TIA & Gruss
Martin Bucher, Zürich
Steht da doch!? Aber ich schreib sie gerne nochmal:
Private Declare Function GetWindowPlacement Lib „User32“ (ByVal HWnd As Long, lpWndPl As WINDOWPLACEMENT) As Long
Reinhard
Noch ein kleiner Nachschlag: Genau genommen muss man die Fenstergrösse in meinem Beispiel mit der gewählten Bildschirm-Fontgröße skalieren, also so:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type Rect
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type WINDOWPLACEMENT
length As Long
Flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As Rect
End Type
Private Const FrameWidth = 3, CaptionHeight = 19, TwipsPerPix = 12
Private Declare Function SetWindowPlacement Lib "User32" \_
(ByVal HWnd As Long, lpWndPl As WINDOWPLACEMENT) As Long
Private Declare Function GetWindowPlacement Lib "User32" \_
(ByVal HWnd As Long, lpWndPl As WINDOWPLACEMENT) As Long
Const SM\_CXSCREEN = 0
Const SM\_CYSCREEN = 1
Const LOGPIXELSX = 88 ' Logical pixels/inch in X
Const LOGPIXELSY = 90 ' Logical pixels/inch in Y
Private Sub ButtonMove\_Click()
Dim WPl As WINDOWPLACEMENT, MeWPl As WINDOWPLACEMENT
Dim HWnd As Long, lRet As Long, lFak As Long, HDC As Long
DoCmd.OpenForm "frmButton"
HDC = GetDC(Me.HWnd)
lFak = 1440 \ GetDeviceCaps(HDC, LOGPIXELSX)
HWnd = Forms("frmButton").HWnd
WPl.length = Len(WPl)
MeWPl.length = Len(MeWPl)
lRet = GetWindowPlacement(Me.HWnd, MeWPl)
lRet = GetWindowPlacement(HWnd, WPl)
With WPl.rcNormalPosition
.top = MeWPl.rcNormalPosition.top + Me!ButtonMove.top \ TwipsPerPix + CaptionHeight + FrameWidth
.left = MeWPl.rcNormalPosition.left + Me!ButtonMove.left \ TwipsPerPix + FrameWidth
.bottom = .top + Me!ButtonMove.Height \ lFak + FrameWidth
.right = .left + Me!ButtonMove.Width \ lFak + FrameWidth
End With
lRet = SetWindowPlacement(HWnd, WPl)
End Sub
Das ist aber nur wichtig, wenn das Fenster EXAKT die Größe der Schaltfläche haben soll…
Reinhard
Lieber Reinhard
Vielen Dank für den Nachschlag. Ich habe mich vielleicht falsch ausgedrückt:
Das Fenster habe ich ja bereits designt und soll genau so gross geöffnet werden, wie es eben vorliegt. Lediglich die Position des Fensters soll in der Nähe des Buttons (bzw. des Mauszeigers) sein.
Es geht darum, dass ich in einer Liste pro Zeile eine Zusatzinformation auf Knopfdruck anbieten möchte.
TIA & Gruss und einen guten Rutsch (falls wir uns nicht mehr lesen)
Martin Bucher, Zürich