导航

移动窗体到鼠标附近(vb6)

Posted on 2007-03-22 16:01  pegger  阅读(271)  评论(0编辑  收藏  举报
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As LongByVal x As LongByVal y As LongByVal nWidth As LongByVal nHeight As LongByVal bRepaint As LongAs Long
Private Type RECT
    
left As Long
    top 
As Long
    
right As Long
    bottom 
As Long
End Type

Private Type POINTAPI
    x 
As Long
    y 
As Long
End Type
Private CursorPoint As POINTAPI
Private DialogRect As RECT

'移动窗体到鼠标附近
Public Sub MoveDialogToCursor(ByRef MoveForm As Form)
    GetCursorPos CursorPoint
    GetClientRect MoveForm.hwnd, DialogRect
    MoveWindow MoveForm.hwnd, CursorPoint.x 
+ 10, CursorPoint.y + 10, DialogRect.right - DialogRect.left, DialogRect.bottom - DialogRect.top, 0
    
    
If MoveForm.left + MoveForm.Width > Screen.Width - 10 Then
        MoveForm.left 
= Screen.Width - MoveForm.Width - 10
    
End If
    
    
If MoveForm.top + MoveForm.Height > Screen.Height - 10 Then
        MoveForm.top 
= Screen.Height - MoveForm.Height - 10
    
End If
    
    GetClientRect MoveForm.hwnd, DialogRect
    
If DialogRect.right < CursorPoint.x And DialogRect.bottom < CursorPoint.y Then
        MoveWindow MoveForm.hwnd, CursorPoint.x 
- (DialogRect.right - DialogRect.left) - 10, CursorPoint.y - (DialogRect.bottom - DialogRect.top) - 10, DialogRect.right - DialogRect.left, DialogRect.bottom - DialogRect.top, 0
    
End If
End Sub

河南恒友科贸有限公司 
电话 :0371-53733453    传真:0371-65388972
地址:郑州市郑花路8号 E-mail:hengyousoft@QQ.com