我在窗口上放了个Command1控件.
  我想要的效果是:
  1.当鼠标放在Command1上时让他响应一个事件.怎么做.(在MouseMove里写代码的除外.)
  2.当鼠标离开Command1时同样让他响应一个事件.怎么做.(在窗口的MouseMove里写代码的除外.)
  我听说是用API函数扑捉句柄可以实现.有那为大哥实现过的告诉我下.小弟急用.
  要是嫌分不够就说一声我加.

解决方案 »

  1.   

    Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim MouseEnter As Boolean '鼠标进入的标志位
    MouseEnter = (0 <= X) And (X <= Command1.Width) And (0 <= Y) And (Y <= Command1.Height) '计算鼠标的移动是否在Command1里面
    If MouseEnter Then '鼠标已经进入
    Me.Caption = "Mouse In Button!"
    SetCapture Command1.hWnd
    Else '鼠标已经离开
    Me.Caption = "Mouse Out!"
    ReleaseCapture
    End If
    End Sub