Project1
标题: PeekMessage获取鼠标滚轮状态的问题 [打印本页]
作者: 心雪 时间: 2011-8-17 15:03
标题: PeekMessage获取鼠标滚轮状态的问题
本帖最后由 心雪 于 2011-8-17 15:19 编辑
- #==============================================================================
- # ■ Kernel
- #------------------------------------------------------------------------------
- # 该模块中定义了可供所有类使用的方法。Object 类中包含了该模块。
- #==============================================================================
- module Kernel
- #--------------------------------------------------------------------------
- # ● 需要的 Windows API 函数
- #--------------------------------------------------------------------------
- GetWindowThreadProcessId = Win32API.new("user32", "GetWindowThreadProcessId", "LP", "L")
- GetWindow = Win32API.new("user32", "GetWindow", "LL", "L")
- GetClassName = Win32API.new("user32", "GetClassName", "LPL", "L")
- GetWindowText = Win32API.new("user32", "GetWindowText", "LPL", "L")
- GetCurrentThreadId = Win32API.new("kernel32", "GetCurrentThreadId", "V", "L")
- GetForegroundWindow = Win32API.new("user32", "GetForegroundWindow", "V", "L")
- #--------------------------------------------------------------------------
- # ● 获取窗口句柄
- #--------------------------------------------------------------------------
- def get_window_handle
- # 获取调用线程(RM 的主线程)的进程标识
- threadID = GetCurrentThreadId.call
- # 获取 Z 次序中最靠前的窗口
- hWnd = GetWindow.call(GetForegroundWindow.call, 0)
- # 枚举所有窗口
- while hWnd != 0
- # 如果创建该窗口的线程标识匹配本线程标识
- if threadID == GetWindowThreadProcessId.call(hWnd, 0)
- # 分配一个 11 个字节的缓冲区
- className = " " * 11
- # 获取该窗口的类名
- GetClassName.call(hWnd, className, 12)
- # 如果匹配 RGSS Player 则跳出循环
- break if className == "RGSS Player"
- end
- # 获取下一个窗口
- hWnd = GetWindow.call(hWnd, 2)
- end
- return hWnd
- end
- end
- $peekmessage = Win32API.new("user32","PeekMessageA","pllll","l")
- module Input
- class << self
- alias old_update update
- def update
- old_update
- point = [0,0].pack("ll")
- a = [0,0,0,0,0,point].pack("l5a*")
- if $peekmessage.call(a,get_window_handle,522,522,1) != 0
- arr = a.unpack("l5a*")
- @wheel = arr[2]
- else
- @wheel = 0
- end
- end
- def wheel
- if @wheel.nil?
- return 0
- else
- return @wheel
- end
- end
- end
- end
复制代码 代码如上,现在的问题是……只有当鼠标坐标发生改变的时候,滚轮消息才能被处理……否则的话无效……这到底是啥米诡异情况= =
利用PeekMessage处理滚轮消息的VB范例:
http://djrm.blogbus.com/logs/53774033.html