vb要如何实现QQ靠边隐藏效果呢,高手们肯定有许多方法,下面是我收藏整理的代码,其中用了一个计时器(Timer)
声明部分:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim p As POINTAPI
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 Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
计时器代码(timer的interval可根据需要设置,我设的是500):
On Error Resume Next
GetCursorPos p
If Me.Top <= 0 Then '位于屏幕顶部时
If p.y > Me.Height / 15 + Me.Top / 15 Or p.x > Me.Width / 15 + Me.Left / 15 Or p.x < Me.Left / 15 Then
Me.Top = 0 - Me.Height + 50
End If
If p.x > Me.Left / 15 And p.x < Me.Left / 15 + Me.Width / 15 And p.y < 3 Then
Me.Top = 0
End If
End If
If Me.Left <= 0 Then '位于屏幕左边时
If p.y > Me.Height / 15 + Me.Top / 15 Or p.y < Me.Top / 15 Or p.x > Me.Width / 15 + Me.Left / 15 Then
Me.Left = 0 - Me.Width + 50
End If
If p.x < 3 And p.y > Me.Top / 15 And p.y < Me.Height / 15 + Me.Top / 15 Then
Me.Left = 0
End If
End If
If Me.Left >= Screen.Width - Me.Width Then '位于屏幕右边
If p.y > Me.Height / 15 + Me.Top / 15 Or p.y < Me.Top / 15 Or p.x < Me.Left / 15 Then
Me.Left = Screen.Width - 50
End If
If p.x > Screen.Width / 15 - 3 And p.y > Me.Top / 15 And p.y < Me.Height / 15 + Me.Top / 15 Then
Me.Left = Screen.Width - Me.Width
End If
End If
If Me.Top >= Screen.Height - Me.Height Then '位于屏幕底部时,底部可省
If p.y > Me.Height / 15 + Me.Top / 15 Or p.x > Me.Width / 15 + Me.Left / 15 Or p.x < Me.Left / 15 Then
Me.Top = Screen.Height + 50
End If
If p.x > Me.Left / 15 And p.x < Me.Left / 15 + Me.Width / 15 And p.y > Screen.Height / 15 - 3 Then
Me.Top = Screen.Height - Me.Height
End If
End If