VRuby/Win32 Question

I am trying to bring a VRuby app to be the front most window. I try the
following but it doesn’t work. Any ideas of what to try next would be
appreciated:

bringWindowToTop = Win32API.new(“user32”, “BringWindowToTop”, [“L”],
“L”)
bringWindowToTop.Call(self.hWnd)

I have also tried [“P”] for the argument with no effect. When I inspect
self.hWnd it is a Fixnum with a large number in it. I used Spy++ to
check the window handle and it matched. I also thought of trying hParent
but that didn’t work as hParent is zero.

Thanks in advance,

Steve Tuckner

I am trying to bring a VRuby app to be the front most window. I try the
following but it doesn’t work. Any ideas of what to try next would be
appreciated:

bringWindowToTop = Win32API.new(“user32”, “BringWindowToTop”, [“L”], “L”)
bringWindowToTop.Call(self.hWnd)

I have also tried [“P”] for the argument with no effect. When I inspect
self.hWnd it is a Fixnum with a large number in it. I used Spy++ to check
the window handle and it > matched. I also thought of trying hParent but
that didn’t work as hParent is zero.

I suppose you want to code something similar to the “window always on top”
setting
available in various applications.

For this, use SetWindowPos() in place of BringWindowToTop().
Try to convert the following C code to Ruby (using Win32API):

SetWindowPosl(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE)

To disable the “always on top” feature:

SetWindowPosl(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE)

(see

for more details about this function)

Eric Landuyt

Ok that was a good suggestion…but it didn’t work.

If I set it to HWND_TOPMOST, then it becomes the top most window on top of
everything else even when deactivated. That is not what I wanted but got
what MSDN Library says:

 Places the window above all non-topmost windows. The window
 maintains its topmost position even when it is deactivated

If I set it to HWND_NOTOPMOST or HWND_TOP then nothing happens.

But after more investigation, what I needed was SetForegroundWindow(hWnd).
MSDN says:

The SetForegroundWindow function puts the thread that created the specified
window into the foreground and activates the window. Keyboard input is
directed to the window, and various visual cues are changed for the user.
The system assigns a slightly higher priority to the thread that created the
foreground window than it does to other threads.

And it seems to work just fine.

Thanks for your input. I only looked at SetForegroundWindow because it was
linked off of SetWindowPos (which I didn’t think was relavent but was kind
of).

Steve Tuckner

···

-----Original Message-----
From: Eric Landuyt [mailto:rix@advalvas.be]
Sent: Thursday, September 25, 2003 12:03 PM
To: ruby-talk@ruby-lang.org
Subject: Re: VRuby/Win32 Question

I am trying to bring a VRuby app to be the front most window. I try
the
following but it doesn’t work. Any ideas of what to try next would be
appreciated:

bringWindowToTop = Win32API.new(“user32”, “BringWindowToTop”, [“L”],
“L”)
bringWindowToTop.Call(self.hWnd)

I have also tried [“P”] for the argument with no effect. When I
inspect
self.hWnd it is a Fixnum with a large number in it. I used Spy++ to
check
the window handle and it > matched. I also thought of trying
hParent but
that didn’t work as hParent is zero.

I suppose you want to code something similar to the “window always on
top”
setting
available in various applications.

For this, use SetWindowPos() in place of BringWindowToTop().
Try to convert the following C code to Ruby (using Win32API):

SetWindowPosl(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE)

To disable the “always on top” feature:

SetWindowPosl(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOSIZE|SWP_NOMOVE)

(see
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/winui/W
inUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFuncti
ons/SetWindowPos.asp
for more details about this function)

Eric Landuyt