希望判断鼠标移出Treeview,原来打算从周围控件的mousemove来处理一下算了,结果旁边有个没有mousemove事件Webbrowser,所以能够告诉我得知鼠标移出Treeview的判断方法或得知鼠标在Webbrowser上移动的方法或其他任何可能的替代较为详细的方法(比如用一个图片框得到Webbrowser的设备场景图像临时代替一下Webbrowser等等)就行,谢谢了!

解决方案 »

  1.   

    在计时器里面加如下代码
    Private Sub Timer1_Timer()
        Dim P As POINTAPI, h As Long
        
        ’获取鼠标当前位置的坐标,以屏幕为坐标系
        GetCursorPos P    ’获取当前鼠标所在点所属窗口的句柄
        h = WindowFromPoint(lX, lY)
       
        if h<>TreeView1.hWnd then
             msgbox "bye"
        end if
    End Sub
      

  2.   

    h = WindowFromPoint(lX, lY)
    应为
    h = WindowFromPoint(P.X, P.Y)
      

  3.   

    Option Explicit
    Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate m_fCaptured As BooleanPrivate Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim obj As TreeView
        Set obj = TreeView1
        If m_fCaptured Then
            With obj
                If x < 0 Or y < 0 Or x > .Width Or y > .Height Then
                    Debug.Print "out"
                    ReleaseCapture
                    m_fCaptured = False
                End If
            End With
        Else
            SetCapture obj.hwnd
            m_fCaptured = True
        End If
    End Sub
      

  4.   

    当然,最好再加一句obj.Parent.ScaleMode=vbTwips
      

  5.   

    kissoflife(明月高楼休独倚,酒入愁肠,化作相思泪!)的方法也可以!
      

  6.   

    ——不过得自己声明API和定义变量类型哦