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
     
    Felipe Navas, Dec 26, 2006
    #1
    1. Advertisements

  2. 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. Advertisements

  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}"
     
    Felipe Navas, Dec 26, 2006
    #3
  4. Felipe Navas

    jojohns1 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])
     
    jojohns1, May 5, 2014
    #4
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.