win32api find display size

D

daz

Michael Hale wrote in message:




require 'Win32API'

SM_CXSCREEN, SM_CYSCREEN = 0, 1
GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')

x = GetSystemMetrics.call(SM_CXSCREEN)
y = GetSystemMetrics.call(SM_CYSCREEN)

p [x, y] #=> [1280, 1024]


daz
 
N

Nathaniel Talbott

Your message showed up as all blank for me... which I've found my
messages do too if I post from Apple Mail with signing enabled. In any
case, I have the following code to get the desktop size, which may or
may not be what you want, as it excludes the space taken up by the task
bar:

require 'dl/import'
require 'dl/struct'

module User32
extend DL::Importable

typealias "BOOL", "int"
typealias "UINT", "unsigned int"
typealias "PVOID", "void *"
typealias "LONG", "long"
typealias "HWND", "void *"

RECT = struct [
"LONG left",
"LONG top",
"LONG right",
"LONG bottom"
]

dlload "user32.dll"
extern "BOOL SystemParametersInfo(UINT, UINT, PVOID, UINT)"

SPI_GETWORKAREA = 48

def self.get_work_area
rect = RECT::malloc
if(systemParametersInfo(SPI_GETWORKAREA, 0, rect.to_ptr, 0) != 0)
[rect.left, rect.top, rect.right - rect.left, rect.bottom -
rect.top]
else
raise "System call failed"
end
end
end

HTH,


Nathaniel
Terralien, Inc.

<:((><
 
M

Michael Hale

Thanks Nathaniel. Your code works perfectly, even inside exerb!

Your message showed up as all blank for me... which I've found my
messages do too if I post from Apple Mail with signing enabled. In any
case, I have the following code to get the desktop size, which may or
may not be what you want, as it excludes the space taken up by the
task bar:

require 'dl/import'
require 'dl/struct'

module User32
extend DL::Importable

typealias "BOOL", "int"
typealias "UINT", "unsigned int"
typealias "PVOID", "void *"
typealias "LONG", "long"
typealias "HWND", "void *"

RECT = struct [
"LONG left",
"LONG top",
"LONG right",
"LONG bottom"
]

dlload "user32.dll"
extern "BOOL SystemParametersInfo(UINT, UINT, PVOID, UINT)"

SPI_GETWORKAREA = 48

def self.get_work_area
rect = RECT::malloc
if(systemParametersInfo(SPI_GETWORKAREA, 0, rect.to_ptr, 0) != 0)
[rect.left, rect.top, rect.right - rect.left, rect.bottom -
rect.top]
else
raise "System call failed"
end
end
end

HTH,


Nathaniel
Terralien, Inc.

<:((><
 
J

Josef 'Jupp' Schugt

Hi!

* Michael Hale:
FAQ suggestion:

Don't write subject-only mails. Ask your question in the mail body.

Josef 'Jupp' Schugt
 

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

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,370
Latest member
desertedtyro29

Latest Threads

Top