求助 VB程序的一个简单问题 鼠标移动问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 11:44:42
IF鼠标移动 THEN 退出当前窗体
和屏幕保护差不多的
这个程序怎么写

在窗体的MouseMove事件里编写如下代码:
dim x0,y0 as integer
if (x0=0 and y0=0) or (abs(x0-x)<5 and abs(y0-y)<5) then
x0=x
y0=y
else
unload me
end if

可以在MouseMove事件中(窗体等所有控件都要) 这个是当鼠标移动就触发 但是不好 因为即使你鼠标不一动也会触发 所以你这样:

'模块里面API函数声明
Type POINTAPI
x As Long
y As Long
End Type
public z As POINTAPI
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public oldX As Long,oldY As long,nowX as long,nowY as long

之后在所有控件的MouseMove事件中加入:

if oldX = 0 and oldY = 0 then '刚刚初始化 还没有鼠标移动 所以为0
GetCursorPos z
oldX = z.x
oldY = z.y
nowx = z.x
nowy = z.y
else
oldx = nowx
oldy = nowy
nowx = z.x
nowy = z.y
end if

if oldx <> nowx or oldy <> nowy then unload me

1楼的代码更像屏幕保护的