Getting Screen Resolution in Windows with Ruby

F

Felipe Navas

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

Cheers
 
F

Felipe Navas

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}"
 
J

jojohns1

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])
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,560
Members
45,035
Latest member
HoTaKeDai

Latest Threads

Top