| Message: 96495 |
 |
BY: Dave Jenkins (djprog) DATE: 2011-05-20 00:49 SUBJECT: SetForegroundWindow and FindWindow Trying to get these to work, it runs, but doesn't work. FindWindow is returning a windows handle that, according to Greatis Windowse, does not exist. I would deeply appreciate any help you can offer. here is the code:
require 'win32/api'
include Win32
module Win32
FindWindow = Win32::API.new('FindWindowA', ['P', 'P'], 'L','user32')
SetActiveWindow = Win32::API.new('SetActiveWindow', ['L'], 'L','user32')
SetForegroundWindow = Win32::API.new('SetForegroundWindow', ['L'], 'L','user32')
def self.findWindow(lpClassName, lpWindowName)
h = FindWindow.call(lpClassName, lpWindowName)
raise "FindWindow failed" if h == 0
h
end
def self.setActiveWindow(hwnd)
SetActiveWindow.call(hwnd)
end
def self.setForegroundWindow(hwnd)
SetActiveWindow.call(hwnd)
end
end
h = Win32.findWindow(nil, 'Tradestation Network Logon')
puts "handle = " + h.to_s
Win32.setForegroundWindow(h) | |