Forum: Ruby Getting Screen Resolution in Windows with Ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
542c2bd335b44f5ae8a2448cbafdc9e0?d=identicon&s=25 Felipe Navas (Guest)
on 2006-12-26 18:48
(Received via mailing list)
Hi, somebody knows how i can get Screen Resolution in Windows with Ruby
?
Anything stable please! And WinXp, Win98, Win95 compatible.

Cheers
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-12-26 19:12
(Received via mailing list)
On 12/26/06, Felipe Navas <felipenavas@gmail.com> 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
542c2bd335b44f5ae8a2448cbafdc9e0?d=identicon&s=25 Felipe Navas (Guest)
on 2006-12-26 19:52
(Received via mailing list)
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}"
This topic is locked and can not be replied to.