[blue]Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_ITEMFROMPOINT = &H1A9
Private Const GW_OWNER = 4
Private Const GWL_HWNDPARENT = (-8)
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_EX_TOOLWINDOW = &H80&
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Sub Command1_Click()
Dim CurrentStyle As Long
Dim lStyle As Long
Dim X As Long
Dim Y As Long
Dim myControl As Control
Set myControl = List1
Form3.ScaleMode = vbPixels
X = Text1.Left
Y = Text1.Top + Text1.Height
myControl.Width = Text1.Width
TranslateCoords Form3, X, Y
lStyle = GetWindowLong(myControl.hwnd, GWL_EXSTYLE)
lStyle = lStyle Or WS_EX_TOOLWINDOW
lStyle = lStyle And Not (WS_EX_APPWINDOW)
SetWindowLong myControl.hwnd, GWL_EXSTYLE, lStyle
SetParent myControl.hwnd, 0& 'GetDesktopWindow()
Call SetWindowPos(myControl.hwnd, HWND_TOPMOST, X, Y, 1000, 1000, SWP_SHOWWINDOW Or SWP_NOSIZE)
myControl.Visible = True
myControl.ZOrder
End Sub
Private Sub Command2_Click()
SetParent List1.hwnd, Form3.hwnd
List1.Move Text1.Left, Text1.Top + Text1.Height
End Sub
Private Sub Form_Load()
List1.AddItem "this"
List1.AddItem "is"
List1.AddItem "a"
List1.AddItem "simple"
List1.AddItem "example"
List1.Visible = False
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lXPoint As Long
Dim lYPoint As Long
Dim lIndex As Long
lXPoint = CLng(X / Screen.TwipsPerPixelX)
lYPoint = CLng(Y / Screen.TwipsPerPixelY)
With List1
' get selected item from list
lIndex = SendMessage(.hwnd, LB_ITEMFROMPOINT, 0, ByVal ((lYPoint * 65536) + lXPoint))
If (lIndex >= 0) And (lIndex <= .ListCount) Then
Text2.Text = .List(lIndex)
Else
Text2.Text = ""
End If
End With
End Sub[/blue]