views:

427

answers:

2

Hi,

I'm playing with a JFrame in Java. I want it to be the topmost window i.e. always on top. The setAlwaysOnTop() works fine, but as soon as I start a movie or a game-window in a full-screen mode then it fails to stay on top.

I played around with JNI and handles. My C code for JNI is using SetWindowPos() and this seems to be working OK until I start a full-screen app. Here's a sample:

JNIEXPORT void JNICALL Java_Frame1_setWindowAlwaysOnTop
(JNIEnv *env, jclass obj, jint hwnd, jboolean flag)
{
  if (flag)
    SetWindowPos((HWND) hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
  else
    SetWindowPos((HWND) hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
  return;
}

I've been googling for some time now and all I established is that the full-screen runs in an exclusive mode and "suspend the windowing system so that drawing can be done directly to the screen".

Can anyone suggest a workaround? BTW. my C is not that brilliant, so go easy..

Thanks! Damo

+1  A: 

"How do I create a window that is never covered by any other windows, not even other topmost windows?"

Imagine if this were possible and imagine if two programs did this. Program A creates a window that is "super-topmost" and so does Program B. Now the user drags the two windows so that they overlap. What happens? You've created yourself a logical impossibility. One of those two windows must be above the other, contradicting the imaginary "super-topmost" feature

From : http://blogs.msdn.com/oldnewthing/archive/2005/06/07/426294.aspx :)

mathieu
A very good point! But what I'm after is not a "super-topmost" feature, but a one-off override of the topmost. For example my game window starts in the full-screen. I want my code to detect the event and to override the topmost of the full-screen window. But if then the game-window refreshes again and becomes the topmost - that's ok. What I mean is I'm not sure that there's a way to do it. I certainly don't want the 2 windows to be super windows, but just to be able to temporarily override the f-screen. BTW isn't it the same as when you execute SetWindowPos() on 1 window and then on other?
damo_inc
+1  A: 

"Topmost" only makes sense in a windowed environment.

Full-screen games and movies usually switch the mode to full-screen exclusive mode. That means that single application has pretty much total control over video - it can change the resolution, be the only application displayed, etc.

A windowed application, even in "topmost", isn't going to be displayed when another application has full screen exclusive mode, because there's no windowing concept available anymore.

Nate
I'm afraid you're right. http://java.sun.com/docs/books/tutorial/extra/fullscreen/exclusivemode.htmlThanks!
damo_inc