Make a Window "stay on top" First you need the handle of the Window. Call this JNI function with Window Title. JNIEXPORT jint JNICALL Java_JavaHowTo_getHwnd(JNIEnv *env, jclass obj, jstring title){ HWND hwnd = NULL; const char *str = NULL; str = (*env)->GetStringUTFChars(env, title, 0); hwnd = FindWindow(NULL,str); (*env)->ReleaseStringUTFChars(env, title, str); return (jint) hwnd; } Then you pass the handle to this function JNIEXPORT void JNICALL Java_JavaHowTo_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; }
First you need the handle of the Window. Call this JNI function with Window Title. JNIEXPORT jint JNICALL Java_JavaHowTo_getHwnd(JNIEnv *env, jclass obj, jstring title){
HWND hwnd = NULL;
const char *str = NULL; str = (*env)->GetStringUTFChars(env, title, 0);
hwnd = FindWindow(NULL,str);
(*env)->ReleaseStringUTFChars(env, title, str);
return (jint) hwnd;
}
Then you pass the handle to this function JNIEXPORT void JNICALL Java_JavaHowTo_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;
}
int h = Toolkit.getDefaultToolkit().getScreenSize().height;
this.setSize(w,h);
void init(){
m_thread = new Thread(this);
m_thread.start();
}
public void run(){
//...
while(true){
this.toFront() ;
//...
}
//...
}
}