永发信息网

VB怎样获得鼠标点击窗体时的坐标!

答案:2  悬赏:70  手机版
解决时间 2021-01-27 23:36
VB怎样获得鼠标点击窗体时的坐标?在一定的坐标范围内响应某事件要怎么弄?
最佳答案
用hook绝对没问题
不过窗体本身就有MouseMove
在里面你就可以知道你的鼠标的位置了嘛。
如果是你自己的直接用MouseMove
其他程序的窗体就只能用hook了~!!
全部回答
新出炉的底层鼠标钩子(low level mouse hook) '==================窗体代码================= private sub form_load() hhook = setwindowshookex(wh_mouse_ll, addressof mousehookproc, app.hinstance, 0) if hhook <> 0 then msgbox "已钩住鼠标事件,请按本窗体右上方的x按钮关闭窗体,不要使用vb调试工具栏的“结束”按钮,以免vb崩溃" end if end sub private sub form_unload(cancel as integer) unhookwindowshookex hhook end sub '=============模块代码================== public const wh_mouse = 7 '本地钩子 public const wh_mouse_ll = 14 '全局钩子 public declare function setwindowshookex lib "user32" alias "setwindowshookexa" (byval idhook as long, byval lpfn as long, byval hmod as long, byval dwthreadid as long) as long public declare function callnexthookex lib "user32" (byval hhook as long, byval ncode as long, byval wparam as long, lparam as any) as long public declare function unhookwindowshookex lib "user32" (byval hhook as long) as long public declare sub copymemory lib "kernel32" alias "rtlmovememory" (destination as any, source as any, byval length as long) public const wm_lbuttondown = &h201 '窗口中按下鼠标左键 public const wm_lbuttonup = &h202 '窗口中松开鼠标左键 public const wm_mousemove = &h200 '窗口中移动鼠标 public const wm_rbuttondown = &h204 '窗口中按下鼠标右键 public const wm_rbuttonup = &h205 '窗口中松开鼠标右键 public const wm_mousewheel = &h20a '鼠标滚轮 public const wm_nclbuttondown = &ha1 '窗口标题栏中按下鼠标左键 public const wm_nclbuttonup = &ha2 '窗口标题栏中左开鼠标左键 public const wm_ncmousemove = &ha0 '窗口标题栏中移动鼠标 public const wm_ncrbuttondown = &ha4 '窗口标题栏中按下鼠标右键 public const wm_ncrbuttonup = &ha5 '窗口标题栏中松开鼠标右键 public hhook as long public type pointapi x as long y as long end type type msllhookstruct pt as pointapi '相对于屏幕左上角的坐标x,y mousedata as long '鼠标数据 flags as long '标记 time as long '时间戳 dwextrainfo as long '其他信息 end type type mousehookstruct pt as pointapi '相对于屏幕左上角的坐标x,y hwnd as long '鼠标光标下窗口的句柄 whittestcode as long '鼠标光标在窗口中的位置,标题栏、左边框、右边框,下边框。。。 dwextrainfo as long '其他信息,通常为0 end type dim omousehookstruct as msllhookstruct public function mousehookproc(byval idhook as long, byval wparam as long, byval lparam as long) as long copymemory omousehookstruct, byval lparam, len(omousehookstruct) debug.print "当前鼠标位置-x:" & omousehookstruct.pt.x & "; y:" & omousehookstruct.pt.y select case wparam case wm_lbuttondown, wm_nclbuttondown debug.print "左键按下" case wm_lbuttonup, wm_nclbuttonup debug.print "左键弹起" case wm_rbuttondown, wm_ncrbuttondown debug.print "右键按下" case wm_rbuttonup, wm_ncrbuttonup debug.print "右键弹起" case wm_mousemove, wm_ncmousemove debug.print "鼠标移动" case wm_mousewheel debug.print "鼠标滚轮" end select mousehookproc = callnexthookex(hhook, idhook, wparam, byval lparam) end function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
巨阙是什么意思呢?
聚友台球会馆地址在什么地方,想过去办事
都酿的意思是什么啊?知道的请说下!
以下()是编制施工进度计划的一部分根据。A.技
用一句话来形容讲信誉的人
七一年出生的猪为什么和老婆常吵架
泰迪狗便血是怎么回事
脂韦的意思是什么啊?知道的请说下!
求个超级纯净无捆绑XP系统
东方台球厅地址有知道的么?有点事想过去
超能陆战队的几个背景音乐
【美国动画片】着两部英语动画片在美国动画片
创业台球会馆地址在哪,我要去那里办事
区冶的意思是什么啊?知道的请说下!
分析图文资料,完成下列各题。(22分)材料一
推荐资讯
挟日的意思是什么啊?知道的请说下!
恰克飞鸟被翻唱的歌曲有哪些呢?
男孩叫徐紫轩好吗?
中国邮政(红星路邮政所)(群英路2号中国邮政)
韩霜瑜伽怎么去啊,我要去那办事
雪纺衫怎么恢复压出来的褶,洗多少次也不平啊
为什么研究有固定转动轴物体的平衡条件时,轴
求大神指导,以下四种元件分别是什么,什么作
邮政银行网上小额贷款
潮人美甲地址在哪,我要去那里办事
南山三壮士的意思是什么啊?知道的请说下!
我天书奇谈男侠一转80级要学龙破斩
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?