Heesob Park
5/6/2009 2:44:00 PM
Hi,
2009/5/6 Phil Smy <phil@philsmy.com>:
> I am trying to write a desktop application in Ruby. We need to find out
> what monitors are attached to the XP machine this will run on.
> I looked at how SWT does this and it is accomplished via calling
> EnumDisplayMonitors (windows api).
>
> I cannot figure out how to call this from within Ruby using Win32API.
> EnumDisplayMonitors's api is this:
> BOOL EnumDisplayMonitors(
> =C2=A0HDC hdc,
> =C2=A0LPCRECT lprcClip,
> =C2=A0MONITORENUMPROC lpfnEnum,
> =C2=A0LPARAM dwData
> );
>
> How can I supply a proc? Is what I want to do even possible?
>
> Any help would be appreciated. All this kind of stuff is not very
> clearly documented for the novice and I can't find any relevant samples.
As you know, Win32API doesn't support callback.
Try with Ruby/DL or win32-api gem.
Here is a win32-api sample:
require 'win32/api'
EnumDisplayMonitors =3D Win32::API.new('EnumDisplayMonitors', 'LPKL',
'B', 'user32')
GetMonitorInfo =3D Win32::API.new('GetMonitorInfo', 'LP', 'B', 'user32')
MyInfoEnumProc =3D Win32::API::Callback.new('LLPL','L') {
|hMonitor,hdcMonitor,lprcMonitor,dwData|
lpmi =3D [72].pack('L') + 0.chr * 68
GetMonitorInfo.call(hMonitor,lpmi)
info =3D lpmi.unpack('L10Z*')
puts "Name:#{info[10]}, Width:#{info[3]}, Height:#{info[4]} "
1
}
EnumDisplayMonitors.call(0, nil, MyInfoEnumProc, 0)
Regards,
Park Heesob