| 赞 | 23 |
| VIP | |
| 好人卡 | |
| 积分 | 31 |
| 经验 | |
| 最后登录 | 2026-8-4 |
| 在线时间 | 1054 小时 |
- 梦石
- 0
- 星屑
- 3069
- 在线时间
- 1054 小时
- 注册时间
- 2011-8-16
- 回帖
- 223
|
发表于 2019-1-15 23:39:30
|
显示全部楼层
限制鼠标的活动范围可用 ClipCursor 函数。我随意写了一下,经测试可以正常运行,但是只要移动窗口或使窗口失去焦点,限制就会失效,必须再次调用函数。我暂时没想到好的解决方法。
[pre lang="ruby"]# 取得窗口句柄
HWND = Win32API.new('user32', 'GetActiveWindow', nil, 'l').call
# 取得客户区矩形
client_rect = "\0" * 16
Win32API.new('user32', 'GetClientRect', 'lp', 'i').call(HWND, client_rect)
ary = client_rect.unpack('llll')
point_ul = ary[0..1].pack('ll')
point_lr = ary[2..3].pack('ll')
CTS = Win32API.new('user32', 'ClientToScreen', 'lp', 'i')
CTS.call(HWND, point_ul)
CTS.call(HWND, point_lr)
client_rect = (point_ul.unpack('ll') + point_lr.unpack('ll')).pack('llll')
# 限制鼠标
Win32API.new('user32', 'ClipCursor', 'p', 'l').call(client_rect)
# 解除限制
Win32API.new('user32', 'ClipCursor', 'p', 'l').call(nil)[/pre] |
评分
-
查看全部评分
|