On Nov 26, 6:10 am, Danny Hiemstra <dannyhiems... / gmail.com> wrote:
> Hi,
>
> Is there a way to detect if a specified program e.g. firefox.exe is
> active / on top?

require 'sys/proctable'
require 'win32/api'
include Win32
include Sys

GetForegroundWindow = API.new('GetForegroundWindow', 'V', 'L',
'user32')
GetWindowThreadProcessId = API.new('GetWindowThreadProcessId', 'LP',
'L', 'user32')

pid = [0].pack('L')
hwnd = GetForegroundWindow.call
GetWindowThreadProcessId.call(hwnd, pid)
pid = pid.unpack('L')[0]

p ProcTable.ps(pid).comm

Regards,

Dan