下面是一个悬浮窗体的代码,希望改进一下:
1,启动后该窗体是停在中间,改为启动后直接靠边.
2,将靠向右边的悬浮窗体改为靠向左边(即改个方向放置悬浮窗体).
3,将鼠标靠近窗体,移动速度太快,不够平滑.
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub command1_click()
Dim i As Long
For i = Left To Screen.Width - 100 Step 10
Left = i
DoEvents
Next
Timer1 = True
End Sub
Private Sub Timer1_Timer()
Dim i As Long
Dim iPos As POINTAPI
GetCursorPos iPos
i = WindowFromPoint(iPos.x, iPos.y)
If i = hwnd Then
Move Screen.Width - Width, Top
ElseIf GetParent(i) = hwnd Or GetParent(GetParent(i)) = hwnd Then Move Screen.Width - Width, Top: Exit Sub
Else: Move Screen.Width - 100, Top
End If
End Sub