calling winapi for EnumDisplayMonitors

Discussion in 'Ruby' started by Phil Smy, May 6, 2009.

  1. Phil Smy

    Phil Smy Guest

    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(
    HDC hdc,
    LPCRECT lprcClip,
    MONITORENUMPROC lpfnEnum,
    LPARAM 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.
    --
    Posted via http://www.ruby-forum.com/.
     
    Phil Smy, May 6, 2009
    #1
    1. Advertising

  2. Phil Smy

    Heesob Park Guest

    Hi,

    2009/5/6 Phil Smy <>:
    > 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
     
    Heesob Park, May 6, 2009
    #2
    1. Advertising

  3. Phil Smy

    Roger Pack Guest

    Phil Smy wrote:
    > 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).


    Ruby wmi is also quite nice (dunno if it helps here though).
    http://betterlogic.com/roger/?p=1291
    --
    Posted via http://www.ruby-forum.com/.
     
    Roger Pack, May 6, 2009
    #3
  4. Phil Smy

    Phil Smy Guest

    Hi Park,
    In short - you rule!
    Thanks - this does exactly what we need. I guess I need to do some
    reading up on win32-api to understand HOW it does it, but this is a
    great start.
    Much appreciated.

    Heesob Park wrote:
    > Here is a win32-api sample:
    >
    > require 'win32/api'
    >
    > EnumDisplayMonitors = Win32::API.new('EnumDisplayMonitors', 'LPKL',
    > 'B', 'user32')
    > GetMonitorInfo = Win32::API.new('GetMonitorInfo', 'LP', 'B', 'user32')
    >
    > MyInfoEnumProc = Win32::API::Callback.new('LLPL','L') {
    > |hMonitor,hdcMonitor,lprcMonitor,dwData|
    > lpmi = [72].pack('L') + 0.chr * 68
    > GetMonitorInfo.call(hMonitor,lpmi)
    > info = lpmi.unpack('L10Z*')
    > puts "Name:#{info[10]}, Width:#{info[3]}, Height:#{info[4]} "
    > 1
    > }
    >
    > EnumDisplayMonitors.call(0, nil, MyInfoEnumProc, 0)
    >
    >
    > Regards,
    > Park Heesob


    --
    Posted via http://www.ruby-forum.com/.
     
    Phil Smy, May 7, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edwin Knoppert

    Supress error/warning of winapi in class?

    Edwin Knoppert, Dec 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    963
    Edwin Knoppert
    Dec 13, 2005
  2. Gutek
    Replies:
    1
    Views:
    654
    Phlip
    Oct 26, 2003
  3. Przemys³aw Dmochowski
    Replies:
    2
    Views:
    936
    Walter
    Jan 13, 2004
  4. Mike Wahler

    Re: [winapi][command at]

    Mike Wahler, Jun 15, 2005, in forum: C++
    Replies:
    0
    Views:
    382
    Mike Wahler
    Jun 15, 2005
  5. tw
    Replies:
    3
    Views:
    573
Loading...

Share This Page