当前位置:编程学习 > VB >>

VB如何做到鼠标移动到窗体上 窗体从屏幕右边出现????

http://topic.csdn.net/t/20040616/18/3097782.html这个网页二楼的代码只能靠上

我希望窗体从右边出现。。。

本人是菜鸟 跪求代码·_·
.....自己改改吧,不要这么懒好不好 改了一下
Private Declare Function GetCursorPos Lib "user32 " (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32 " (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function PtInRect Lib "user32 " (lpRect As RECT, ByVal ptx As Long, ByVal pty As Long) 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 MoveWindow Lib "user32 " (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Const HWND_TOPMOST = -1
 
Private Type POINTAPI
 X As Long
 Y As Long
End Type
Private Type RECT
 Left As Long
 Top As Long
 Right As Long
 Bottom As Long
End Type

Dim Is_Move_B As Boolean
Dim Is_Movestar_B As Boolean
Dim MyRect As RECT
Dim MyPoint As POINTAPI
Dim Movex As Long, Movey As Long
Dim Max As Long


Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
 Timer1.Interval = 50
 Label1.Top = 0
 Label1.Left = 0
 Label1.Width = Form1.Width
    
 Form1.Left = Screen.Width - 30
 Max = Form1.Width
 GetWindowRect Form1.hwnd, MyRect
End Sub

Private Sub Form_Paint()
  '使窗体始终置于最右面
  If PtInRect(MyRect, MyPoint.X, MyPoint.Y) = 0 And Me.Top < 30 Then
     SetWindowPos Me.hwnd, HWND_TOPMOST, (Screen.Width - Form1.Width) / Screen.TwipsPerPixelX, Me.Top / Screen.TwipsPerPixelY, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, &H20
  End If
End Sub

Private Sub Timer1_Timer()
  GetWindowRect Form1.hwnd, MyRect
  GetCursorPos MyPoint
  If Form1.Left > Screen.Width - Form1.Width Then
    Form1.Left = Screen.Width - 30
    Form1.Width = 30
    Exit Sub
  End If
  '  如果鼠标移动到窗体中,则显示窗体
  If (PtInRect(MyRect, MyPoint.X, MyPoint.Y) And Form1.Width = 30) Then
    Form1.Width = Max
    Form1.Left = Screen.Width - Form1.Width
    
    '判断鼠标指针是否位于窗体拖动区
    If MyPoint.X - MyRect.Left <= 10 Or Is_Movestar_B Then
      Screen.MousePointer = 15
      Is_Move_B = True
    Else
      Screen.MousePointer = 0
      Is_Move_B = False
    End If
  Else '  显示一部分窗体标志窗体在屏幕顶部的位置
    If Not Is_Movestar_B And Me.Left >= Screen.Width - 30 Then
      Form1.Left = Screen.Width - 30
      Form1.Width = 30
    End If
  End If
End Sub
'  开始移动
Private Sub label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Is_Move_B Then
    Movex = MyPoint.X - MyRect.Left
    Movey = MyPoint.Y - MyRect.Top
    Is_Movestar_B = True
  End If
End Sub

'  移动窗体
Private Sub label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Is_Movestar_B Then
    MoveWindow Form1.hwnd, MyPoint.X - Movex, MyPoint.Y - Movey, MyRect.Right - MyRect.Left, MyRect.Bottom - MyRect.Top, -1
  End If
End Sub

'  结束移动
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Is_Movestar_B = False
End Sub

靠上和靠上有什么区别?位置而已。。。多少动动脑筋了。 没看出区别
引用 4 楼 veron_04 的回复:
靠上和靠上有什么区别?位置而已。。。多少动动脑筋了。
引用 5 楼 dbcontrols 的回复:
没看出区别

引用 4 楼 veron_04 的回复:
靠上和靠上有什么区别?位置而已。。。多少动动脑筋了。

哈哈,+1 哈哈,激动了 看代码的来了.. 什么意思?看不懂。
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,