Getting Screen Resolution in Windows with Ruby

Discussion in 'Ruby' started by Felipe Navas, Dec 26, 2006.

  1. Felipe Navas

    Felipe Navas Guest

    Hi, somebody knows how i can get Screen Resolution in Windows with Ruby ?
    Anything stable please! And WinXp, Win98, Win95 compatible.

    Cheers

    --
    (.) CAMPANHA DA FITA ASCII ( http://arc.pasp.de/)
    / \ Contra formatos proprietarios
     
    Felipe Navas, Dec 26, 2006
    #1
    1. Advertising

  2. On 12/26/06, Felipe Navas <> wrote:
    > Hi, somebody knows how i can get Screen Resolution in Windows with Ruby ?
    > Anything stable please! And WinXp, Win98, Win95 compatible.
    >


    You can use the WIN32OLE library (or similar) to call the
    GetSystemMetrics() function:
    http://support.microsoft.com/kb/210603
     
    Wilson Bilkovich, Dec 26, 2006
    #2
    1. Advertising

  3. Felipe Navas

    Felipe Navas Guest

    Thanks Wilson!

    require 'dl/import'
    require 'dl/struct'

    SM_CXSCREEN = 0
    SM_CYSCREEN = 1

    user32 = DL.dlopen("user32")

    get_system_metrics = user32['GetSystemMetrics', 'ILI']
    x, tmp = get_system_metrics.call(SM_CXSCREEN,0)
    y, tmp = get_system_metrics.call(SM_CYSCREEN,0)

    puts "#{x} x #{y}"

    On 12/26/06, Wilson Bilkovich <> wrote:
    > On 12/26/06, Felipe Navas <> wrote:
    > > Hi, somebody knows how i can get Screen Resolution in Windows with Ruby ?
    > > Anything stable please! And WinXp, Win98, Win95 compatible.
    > >

    >
    > You can use the WIN32OLE library (or similar) to call the
    > GetSystemMetrics() function:
    > http://support.microsoft.com/kb/210603
    >
    >



    --
    (.) CAMPANHA DA FITA ASCII ( http://arc.pasp.de/)
    / \ Contra formatos proprietarios
     
    Felipe Navas, Dec 26, 2006
    #3
  4. Felipe Navas

    Guest

    Here's a version for ruby 1.9 (the DL library changed)

    require 'dl'

    SM_CXSCREEN = 0
    SM_CYSCREEN = 1

    user32 = DL.dlopen("user32")
    get_system_metrics = DL::CFunc.new(user32['GetSystemMetrics'], DL::TYPE_LONG)

    x = get_system_metrics.call([SM_CXSCREEN])
    y = get_system_metrics.call([SM_CYSCREEN])
     
    , May 5, 2014
    #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. Andrew FPGA
    Replies:
    0
    Views:
    985
    Andrew FPGA
    Sep 26, 2005
  2. eagle

    Getting the screen resolution

    eagle, Sep 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,909
    Marina
    Sep 9, 2005
  3. Pat
    Replies:
    5
    Views:
    547
  4. Thomas Morton

    Getting current screen resolution

    Thomas Morton, Jun 9, 2008, in forum: Python
    Replies:
    2
    Views:
    397
    Thomas Morton
    Jun 10, 2008
  5. Saturn
    Replies:
    5
    Views:
    261
    Saturn
    Nov 11, 2009
Loading...

Share This Page