Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Dan Rathbun
RE: SetForegroundWindow and FindWindow [ reply ]  
2011-05-22 21:53
BTW.. the RubyForge forum for the windows-pr project, is:

http://rubyforge.org/forum/forum.php?forum_id=319

By: Dan Rathbun
RE: SetForegroundWindow and FindWindow [ reply ]  
2011-05-22 21:48
Also...

the Win32 namespace is part of the win32-api and windows-pr projects. Functionality should be added to the project(s) thru the project's github site(s).

https://github.com/djberg96/win32-api
https://github.com/djberg96/windows-pr

BUT.. these are specific Window wrapper methods which should already be defined in the Windows::Window module.
IF not either add them there, or add the statement:

module_function()

at the top of file 'window.rb' (inside module Windows::Window,) that defines the window specific API calls, (if you wish to have library style module methods.)

If you did not download the windows-pr package, then do so, and save yourself alot of work.

http://rubygems.org/gems/windows-pr

You can always create a temporary local reference inside your own namespace that points at another namespace, such as:

lib = Windows::Window

h = lib.findWindow(0,"My Fancy Dialog")

lib.class
>> Module

By: Dan Rathbun
RE: SetForegroundWindow and FindWindow [ reply ]  
2011-05-22 21:29
call it like this from Ruby:

pw = FindWindow.call(0,@@window_name)

ie, use 0 not nil for the class argument.

Also FindWindow will only find top windows. If you need to find child windows, you must use FindWindowEx, like:

cw = FindWindowEx.call(pw,0,"Edit",0)
.. where pw is the handle of the parent window.
(In this case, it's looking for the first edit control, in a popup dialog which is the parent window.)

By: Dave Jenkins
RE: SetForegroundWindow and FindWindow [ reply ]  
2011-05-20 16:07
Oops. Cut and paste got me again: should be

def self.setForegroundWindow(hwnd)
SetForegroundWindow.call(hwnd)
end

(slinks away sheepishly...)

By: Dave Jenkins
SetForegroundWindow and FindWindow [ reply ]  
2011-05-20 00:49
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)