From: David Mullet Date: 2008-12-28T02:37:52+09:00 Subject: Re: Win32API- GetForegroundWindows() Diego Guti wrote: >> Try changing your last parameter from 'P' to 'N': >> >> a = Win32API.new('user32', 'GetForegroundWindow', [], 'N') >> window = a.Call() >> >> David > > Thanks, now it's running :). > > Just one more question. Now i got the handle of the window, any chance > to get the name of the window?? You can use the GetWindowText API call. Pass it (1) your window handle, (2) a string buffer into which the text is to be copied, and (3) the maximum number of characters to copy to the buffer: require 'Win32API' getForegroundWindow = Win32API.new('user32', 'GetForegroundWindow', [], 'L') getWindowText = Win32API.new('user32', 'GetWindowText', ['L', 'P', 'I'], 'I') window_handle = getForegroundWindow.Call() title_buffer = ' ' * 256 getWindowText.Call(window_handle, title_buffer, 256) puts(title_buffer) David -- Posted via http://www.ruby-forum.com/.