Board logo

标题: 能用VB实现类似QQ的吸附屏幕的功能 [打印本页]

作者: 毛主席    时间: 2008-2-28 09:25     标题: 能用VB实现类似QQ的吸附屏幕的功能

能用VB实现类似QQ的吸附屏幕的功能

建立新的form,加入一个timer,interval设为100,
Option Explicit
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
Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE '加载窗口是指定窗口在最顶层
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
GetCursorPos p
If Me.Top <= 0 Then 'form1 is not hide and form1's top is 0
'hide form
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 'mouse is not over form1
Me.Top = 0 - Me.Height + 50
End If
'show form
If p.X > Me.Left / 15 And p.X < Me.Left / 15 + Me.Width / 15 And p.Y < 3 Then 'mouse is over form
Me.Top = 0
End If
End If
If Me.Left <= 0 Then ''form1 is not hide form1's left is 0
'hide form
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 'mouse is not over form1
Me.Left = 0 - Me.Width + 50
End If
'show form
If p.X < 3 And p.Y > Me.Top / 15 And p.Y < Me.Height / 15 + Me.Top / 15 Then 'mouse is over form
Me.Left = 0
End If
End If
If Me.Left >= Screen.Width - Me.Width Then
'hide form
If p.Y > Me.Height / 15 + Me.Top / 15 Or p.Y < Me.Top / 15 Or p.X < Me.Left / 15 Then 'mouse is not over form1
Me.Left = Screen.Width - 50
End If
'show form
If p.X > Screen.Width / 15 - 3 And p.Y > Me.Top / 15 And p.Y < Me.Height / 15 + Me.Top / 15 Then 'mouse is over form
Me.Left = Screen.Width - Me.Width
End If
End If
End Sub




欢迎光临 ::电驴基地:: (https://www.cmule.com/) Powered by Discuz! 6.0.0