AW: 2. Userform bei MouseMove anzeigen
17.11.2021 16:19:11
Nepumuk
Hallo Chris,
für die Frames 1-8 so:
Private Sub Frame1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
With UserForm2
.LeftPos = False
.Show
End With
End Sub
für die Frames 9-n so:
Private Sub Frame9_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
With UserForm2
.LeftPos = True
.Show
End With
End Sub
Im UserForm2 setzt du die Eigenschaft "StartUpPosition" auf 0-Manuell und kopiere folgernden Code in dessen Modul:
Option Explicit
Private Declare PtrSafe Function GetCursorPos Lib "user32.dll" ( _
ByRef lpPoint As POINTAPI) As Long
Private Declare PtrSafe Function GetDesktopWindow Lib "user32.dll" () As LongPtr
Private Declare PtrSafe Function GetDC Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal hdc As LongPtr) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" ( _
ByVal hdc As LongPtr, _
ByVal nIndex As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Const LOGPIXELS_X As Long = 88&
Private Const LOGPIXELS_Y As Long = 90&
Private mblnLeftPos As Boolean
Private Sub UserForm_Activate()
Dim udtCursorPos As POINTAPI
Dim sngConversionX As Single, sngConversionY As Single
sngConversionX = GetResolution(LOGPIXELS_X)
sngConversionY = GetResolution(LOGPIXELS_Y)
Call GetCursorPos(udtCursorPos)
If LeftPos Then
Left = udtCursorPos.X * sngConversionX - Width
Else
Left = udtCursorPos.X * sngConversionX
End If
Top = udtCursorPos.Y * sngConversionY
End Sub
Private Function GetResolution(ByVal pvlngLogPixel As Long) As Single
Dim lngptrhWndDesk As LongPtr, lngptrhDCDesk As LongPtr
Dim lnglogPixel As Long
lngptrhWndDesk = GetDesktopWindow()
lngptrhDCDesk = GetDC(lngptrhWndDesk)
lnglogPixel = GetDeviceCaps(lngptrhDCDesk, pvlngLogPixel)
Call ReleaseDC(lngptrhWndDesk, lngptrhDCDesk)
GetResolution = 72 / lnglogPixel
End Function
Friend Property Get LeftPos() As Boolean
LeftPos = mblnLeftPos
End Property
Friend Property Let LeftPos(ByVal pvblnLeftPos As Boolean)
mblnLeftPos = pvblnLeftPos
End Property
Gruß
Nepumuk