# Getting Screen Resolution in Windows with Ruby

**URL:** <https://www.ruby-forum.com/t/getting-screen-resolution-in-windows-with-ruby/80436>\
**Category:** Ruby\
**Created:** [December 26, 2006, 6:48pm UTC](https://www.ruby-forum.com/t/getting-screen-resolution-in-windows-with-ruby/80436 "2006-12-26T18:48:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [December 26, 2006, 6:48pm UTC](https://www.ruby-forum.com/t/getting-screen-resolution-in-windows-with-ruby/80436/1 "2006-12-26T18:48:04Z")

</div>

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

Cheers

---

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [December 26, 2006, 7:12pm UTC](https://www.ruby-forum.com/t/getting-screen-resolution-in-windows-with-ruby/80436/2 "2006-12-26T19:12:10Z")

</div>

On 12/26/06, Felipe N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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:

> **[GetSystemMetrics function (winuser.h) - Win32 apps](https://learn.microsoft.com/en-US/windows/win32/api/winuser/nf-winuser-getsystemmetrics)**
>
> Retrieves the specified system metric or system configuration setting.

---

<div class="post-metadata">

**Author:** ![Felipe\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Felipe\_N](https://www.ruby-forum.com/u/Felipe_N)\
**Post date:** [December 26, 2006, 7:52pm UTC](https://www.ruby-forum.com/t/getting-screen-resolution-in-windows-with-ruby/80436/3 "2006-12-26T19:52:17Z")

</div>

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}”
