views:

78

answers:

1

I have a java application that will run on Windows 7 (using Swing, App #1) that runs as full screen (but not in exclusive mode). I have another application (App #2) that displays a GUI to configure an external device over a serial port that I do not have the source to and cannot change at all.

I want to embed App #2 inside of App #1 so that it looks like it is part of the parent java application (hiding the file --> exit button and hiding the minimize, maximize, and close buttons).

If this kind of integration is not possible inside the Java application, I would be fine with opening the process using Java and just monitoring it to keep it open . It would need to keep the window set to "always on top" because App #1 is fullscreen and hide as much of the external MS Windows UI as possible to trick the user into thinking it isn't an external application. Is there some kind of method whether using JNI or something else to manage another processes window (screen location, title bar, minimize, maximize, close button visibility) and process state from inside my Java application?

I will be happy to provide more information if needed.

+2  A: 

The following scheme is language independent, I've managed to embed IE window into a Ruby application this way:

  • First of all, change the style of the external application window (you can use JNA for calling WinAPI):

    style = GetWindowLongPtr(APP_HWND, GWL_STYLE);

    style |= WS_CHILD;

    style &= ~WS_CAPTION;

    style &= ~WS_POPUP;

    SetWindowLongPtr(HWND, GWL_STYLE, style);

  • Define parent-child relationship between windows:

    SetParent(APP_HWND, JAVA_HWND);

  • Listen to Move/Resize events of your Java window, and apply new positions on a child window.

spektom
I've never used the Windows API's before or JNA. How would I get the hWnd pointer of an application I opened using ProcessBuilder? .Here is a reference I found on SO, but it talks about passing a component which I don't think I have because its an external application.http://stackoverflow.com/questions/386792/in-java-swing-how-do-you-get-a-win32-window-handle-hwnd-reference-to-a-window
Austyn Mahoney
Here are some examples of using JNA for detecting a window handle in Java: http://forums.sun.com/thread.jspa?threadID=5423994In general, you call WinAPI's method `EnumWindows`, which returns all existing windows. Then you find the relevant one by window title (`GetWindowText` method)
spektom