Win32 API General Help

I am trying to utilize the win32API to to get the resolution of the display, it seems that this can be achieved via something along the lines of this:"user32.dll", "GetActiveWindow", "", "L").call"user32.dll", "MonitorFromWindow",["I","P"],"L") hwnd,"MONITOR_DEFAULTTONEAREST"

however, this is returning 0.

I’m sure I have the syntax totally messed up, as I have no experience using the Windows API.

Any advice/direction would be greatly appreciated!

Try getting handle to the Desktop window, and then call GetWindowRectangle on it.

Dan, Do you know how this method is affected by multiple monitors? with dissimilar monitor orientations?

Not sure. I think the Desktop window might be the Primary display but I haven’t used this in awhile.
I just thought it might be a quick and dirty alternative.

Do you really need the x and y screen resolution ? … and which one of the displays ?


this was actually a perfect solution, so for that I thank you,

but what I was hoping for was for someone to try to explain the utilization of the WindowsAPI in Ruby, because to me, it is very confusing

The Windows API is a C API. The Ruby Win32API class is meant for those who are comfortable with C data types and function calls.

Teaching C (or any language) programming in any forum is beyond scope. There are books (and online tutorials) that will do a better job.

Now, The Ruby Win32API class has long been deprecated, and is now just a wrapper using newer libraries. First, it was making calls using the Ruby DL library. Now, Ruby 2.0, it will make calls using the Ruby Fiddle library (which is a Ruby wrapper around the C FFI library.)

So, you might as well just use one of those instead, rather than the Win32API class. (BTW, it is not even listed in the Ruby 2.0+ libraries any more, and is no longer a binary. It’s just a simple script that translates arguments into the format for calling the other newer libraies I mention above.)