Keep window on top

D

dr

Hi,

do anyone know a tool which makes it possible to keep a specific
window on top all the time (like the option in Winamp)? The window is
a Java application run on Windows (mostly 2000). It must not be in
focus all the time.

Thanks!

/dr
 
L

Larry Barowski

dr said:
Hi,

do anyone know a tool which makes it possible to keep a specific
window on top all the time (like the option in Winamp)? The window is
a Java application run on Windows (mostly 2000). It must not be in
focus all the time.


Use JNI to do this every time you create a new top-level window
(not tested from JNI):

EnumWindows(enumWins, getpid());

static BOOL CALLBACK enumWins(HWND hwnd, LPARAM lParam) {
DWORD pid;
if(GetWindowThreadProcessId(hwnd, &pid) &&
(pid == (unsigned long)lParam)) {
LONG ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
if((ex_style & WS_EX_TOPMOST) == 0) {
HANDLE parent = (HANDLE)GetWindowLong(hwnd,
GWL_HWNDPARENT);
if(parent == 0)
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE | SWP_NOACTIVATE |
SWP_ASYNCWINDOWPOS);
}
}
return TRUE;
}

You can also use various "tricks" to get the window handle of a
new window directly, but I'm not sure if there is a VM-independent
way to do that.

If you can't modify the code, you'll have to launch the Java app
from a Windows app which collects the pid, and occasionally calls
enumWins() while waiting for the Java app to finish.

-Larry Barowski
 
R

Robert Olofsson

: do anyone know a tool which makes it possible to keep a specific
: window on top all the time (like the option in Winamp)? The window is
: a Java application run on Windows (mostly 2000). It must not be in
: focus all the time.

It can be done, but you have to use JNI so that mean you will have to
write C-code. It also mean that you will have to do an install on each
client to put the .dll in the right place.

Before doing this I would ask the mananger if they truly want this. I
know that I truly _hate_ programs that think they know better than me
where I want my windows. So will you tell me the name of this product
so I can make sure I never buy it? ;-)

If I want a window on top I tell my window manager to do that. I am
not aware of any tool in window that will accomplish that though.

Also some people run windows with virtual desktops (under X virtual
desktops are common), how should "always on top" handle that? (another
thing for the window manager to handle under X). You should at least
try it if you sell this application.

/robo
 
A

Andrew Thompson

| : do anyone know a tool which makes it possible to keep a
specific
| : window on top all the time (like the option in Winamp)?
....
| Before doing this I would ask the mananger if they truly want
this. I
| know that I truly _hate_ programs that think they know better
than me
| where I want my windows. So will you tell me the name of this
product
| so I can make sure I never buy it? ;-)

Agree completely. I was tempted to ask
what happens when both WinAmp _and_
another app think they are so important
they must be 'always on top'.

Fortunately, as the OP mentioned, WinAmp
has the _option_ to be 'always on top',
which defaults to false (AIU).
I have my WinAmp default to false, and do
not tolerate software that takes that option
away from me.

[ Even my DVD player software is not
'always on top' ..it's at the front (and full
screen) when and if I need it to be so.. ]
 
M

mromarkhan

Peace be unto you.
Try something like,
"C:\Program Files\Java\jdk1.5.0\bin\javac" -source 1.5 TigerToFront.java
"C:\Program Files\Java\jdk1.5.0\bin\java.exe" -version:1.5 TigerToFront

<code>
import javax.swing.*;
public class TigerToFront extends JFrame
{
public TigerToFront()
{
this.setSize(512,342);
this.setVisible(true);
this.setAlwaysOnTop(true);
}
public static void main(String [] s)
{
new TigerToFront();

}

}
</code>

Have a good day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top