Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread
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)


Thread View

Thread Author Date
SetForegroundWindow and FindWindowDave Jenkins2011-05-20 00:49
      RE: SetForegroundWindow and FindWindowDave Jenkins2011-05-20 16:07
      RE: SetForegroundWindow and FindWindowDan Rathbun2011-05-22 21:29
      RE: SetForegroundWindow and FindWindowDan Rathbun2011-05-22 21:48
      RE: SetForegroundWindow and FindWindowDan Rathbun2011-05-22 21:53

Post a followup to this message