原因是VB Form的LostFocus和Deactive只能在本程序内发生,一个简单的解决办法是增加一个几百毫秒的定时器,加入程序: Private Declare Function GetActiveWindow Lib "user32" () As LongPrivate Sub Timer1_Timer() If GetActiveWindow() <> hWnd Then End End Sub
Timer.Interval = 50 sub Timer1_OnTimer() GetCursorPos x, y ;This is API if x < scalex(Left, vbTwips, vbPixels) or x > .... ; 判断是否在Form外 end endif end sub
Private Declare Function GetActiveWindow Lib "user32" () As LongPrivate Sub Timer1_Timer()
If GetActiveWindow() <> hWnd Then End
End Sub
sub Timer1_OnTimer()
GetCursorPos x, y ;This is API
if x < scalex(Left, vbTwips, vbPixels) or x > .... ; 判断是否在Form外
end
endif
end sub