ich hab da mal wieder ein Problem, bei dem ich nicht weiter komme.
Ich möchte eine Userform an der Position öffnen, an der der Mauszeiger ist.
Das habe ich bereits:
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, ByVal hWndInsertAfter As LongPtr, _
ByVal X As Long, ByVal Y As Long, ByVal cx As LongPtr, _
ByVal cy As Long, ByVal wFlags As Long) As LongPtr
Private Declare PtrSafe Function GetCursorPos Lib "user32" ( _
lpPoint As POINTAPI) As LongPtr
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOOWNERZORDER = &H200
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Type POINTAPI
X As Long
Y As Long
End Type
Und:
Private Sub UserForm_Activate()
Dim Mausposition As POINTAPI
Dim hwnd&
hwnd = FindWindow(vbNullString, Me.Caption)
GetCursorPos Mausposition
SetWindowPos hwnd, 0, Mausposition.X, Mausposition.Y, 0, 0, _
SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_FRAMECHANGED Or SWP_NOSIZE
Die Userform wird über einen Comandbutton aufgerufen. Da der Button in einer Hauptuserform mehrmals an verschiedenen Stellen zur Datumsübergabe benutzt wird, möcht eich das auch die secundäre Userform sich in der nähe des gedrückten Buttons öffnen. Hier denke ich ist die Mausposition die beste Wahl. Aber leider bekomme ich den Fehler das FindWindow falsch deklariert ist bzw der Typ falsch ist.
Ich musste den mit PtrSafe und LongPtr umstellen damit er auf 32/64bit Systemen läuft.
Wo liegt denn der Fehler den ich nicht sehe? :D
Vielen DAnk