#!ruby # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2022/08/17 03:50:52 +0900> # # win32api sample. use GetWindowRect # # Windows10 x64 21H2 + Ruby 1.8.7 p330 i386-mswin32 require "Win32API" if ARGV.size != 1 fn = File.basename(__FILE__) puts "Usage:\n ruby #{fn} WINDOWHANDLE" exit end hwnd = ARGV[0].to_i puts "Window Handle = #{hwnd}" get_window_rect = Win32API.new("user32", "GetWindowRect", "lp", "i") buf = "\0" * 256 get_window_rect.call(hwnd, buf) x0, y0, x1, y1 = buf.unpack("l4") w = x1 - x0 h = y1 - y0 puts "(x0, y0) = (#{x0}, #{y0})" puts "(x1, y1) = (#{x1}, #{y1})" puts "(w, h) = #{w}, #{h}"