Thomas Risi Softwareentwicklung
Addins - Datenbanklösungen - Komponenten - RTDServer - WebServices
UserForm an Cursor-Position öffnen
In diesem Beispiel wird eine VBA-UserForm an der aktuellen Position des Cursors geöffnet.
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetCursorPos Lib "user32" ( _
lpPoint As POINTAPI) As Long
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
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
End Sub
© 2001 -
by Thomas Risi