[Win32utils-devel] Fwd: Win32 - api
Daniel Berger
djberg96 at gmail.com
Fri Nov 18 11:40:30 EST 2011
Forwarding this one to the list.
---------- Forwarded message ----------
From: Anton Synytsia <anton.synytsia at yahoo.com>
Date: Fri, Nov 11, 2011 at 10:14 PM
Subject: Win32 - api
To: "djberg96 at gmail.com" <djberg96 at gmail.com>
First of all, thanks for win32-api!!! :) I have been using it for a
quite of time and found a little, but important bug.
The pointers in callbacks doesn't return the full structure to a pointer:
#######Script#######
#require 'Sketchup.rb' #if only have sketchup
require 'win32/api.rb'
require 'windows/api.rb'
module HookProc
include Windows
API.auto_namespace='HookProc'
API.auto_constant=true
API.new('SetWindowsHookEx', 'IKII', 'I', 'User32')
#http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx
API.new('UnhookWindowsHookEx', 'I', 'I', 'User32')
#http://msdn.microsoft.com/en-us/library/ms644993(v=VS.85).aspx
API.new('GetCurrentThreadId', 'V', 'I', 'Kernel32')
#http://msdn.microsoft.com/en-us/library/ms683183(VS.85).aspx
API.new('GetModuleHandle', 'V', 'I', 'Kernel32')
#http://msdn.microsoft.com/en-us/library/ms683199(v=VS.85).aspx
API.new('CallWindowProc', 'PILII', 'I', 'User32')
#http://msdn.microsoft.com/en-us/library/ms633571(v=VS.85).aspx
class LowLevelMouseProc
def initialize(&block)
@hhk=0
@mouse_procLL=Win32::API::Callback.new("ILP", 'I'){|nCode, wParam,
lParam| #http://msdn.microsoft.com/en-us/library/ms644986(v=VS.85).aspx
@onLowLevelMouseInput.call(nCode, wParam, lParam)
}
@onLowLevelMouseInput=block
end
def onLowLevelMouseInput(&block)
@onLowLevelMouseInput=block
0 #Return Value: 0 - process the message, 1 or other digit - remove
the mouse message from the module handle, WARNING will act like mouse
off
end
def hook()
@hhk=HookProc::SetWindowsHookEx.call(14, @mouse_procLL,
GetModuleHandle.call, 0)
end
def unhook()
HookProc::UnhookWindowsHookEx.call(@hhk)
end
end #LowLevelMouseProc
end #HookProc
myLowLevelMouseProc=HookProc::LowLevelMouseProc.new{|nCode, wParam, lParam|
print("\nnCode: #{nCode}, wParam: #{wParam}, lParam: #{lParam.inspect}")
0 #Return Value: 0 - process the message, 1 or other digit - remove
the mouse message from the module handle - WARNING will act like mouse
off
}
#myLowLevelMouseProc.hook
#myLowLevelMouseProc.unhook
=begin Only Use that if have Sketchup and erase the above 2 filled lines
unless file_loaded?(__FILE__)
state=false
submenu=UI.menu("Plugins").add_submenu("HookProc")
item=submenu.add_item("LowLevelMouseProc"){
if state
myLowLevelMouseProc.unhook
state=false
else
myLowLevelMouseProc.hook
state=true
end
}
submenu.set_validation_proc(item){if state then MF_CHECKED else
MF_UNCHECKED end}
file_loaded(__FILE__)
end
=end
#######Script#######
As stated in above script, lParam should return the pointer to
MSLLHOOKSTRUCT(link:
http://msdn.microsoft.com/en-us/library/ms644970(v=VS.85).aspx)
structure. Instead for the result lParam only is filled with some
parts of MSLLHOOKSTRUCT. The parts are x coordinate and sometimes y
coordinate. To check I have test it on Borland Delphi 6 and it
returned the whole pointer, but on ruby win32-api it doesn't. I don't
know the bug that makes it and so reported it to u to please fix and
update it. I would help on anything I could, Thanks.
Here is some thing I think:
"If some part of the string is nil, then the pointer is assumed to be
nil at the rest of the script, so that's why it only shows-up only
part of pointer."
More information about the win32utils-devel
mailing list