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.
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.
Related
How can I disable OS-level keyboard shortcuts (e.g. Alt-Tab, Ctrl-Alt-Left/Right, etc.) on a [Ubuntu] Linux machine? I'm developing a full-screen Java Swing app and don't want the user to be able to task switch away from the program arbitrarily. It's not enough to toggle the "always on top" flag; users mustn't be allowed to switch workspaces, migrate focus or any other such things. The machine must function normally before and after the application is executed. Google says that this will require JNI or JNA but I'm looking for a bit more hand-holding.
There's no point in trying to do this in your application because any of these changes are going to need to be handled by X11 and/or the window manager since those are what respond to the commands. Assuming that you have control of the platform, choose a window manager which supports a kiosk mode. Then use the window manager's settings to start your application and enter kiosk mode.
Options for window managers which can do this include KDE or twm-kiosk.
(And if you don't have control of the platform, you're not likely to be able to have your application intercept things like ctrl-alt-backspace anyway.)
Edit:
In response to a scaled-down version of the question in which he's willing to let things like ctl-alt-backspace go and just wants most of the keys including alt-tab or other similar application switching key combinations, the following should work:
You should be able to do this using XLib's XGrabKeyboard method through JNI. This Java/XLib JNI keypress capture tutorial should be a good starting point. However, it uses XGrabKey which just passively listens for keys and does not prevent other applications from receiving them. You'll instead want to use XGrabKeyboard which actively snags all of the normal keyboard events (which, if the premise of this StackOverflow question is correct, includes the task switching keys).
Note that as a side-effect, key capture in Swing will also probably stop working because your Swing windows are going to be separate from the window you create in C. As such, you will probably have to use your JNI interface to get key presses to your program when needed. (Although I would definitely advise testing it first before writing the code.) You might be able to avoid this if you can get the window using Java AWT Native Interface to get the window ID. (Note that Swing is built on top of AWT, so this will work for Swing.) However, I'm not sure how to do this. It looks like you might be able to navigate the window tree by getting the root window from the Display and going from there to find your Window, but it's all kind of weird. It would be nice if the AWT NI just told you the window ID, but it doesn't look like it does that.
As this warning Reminder: XGrabKeyboard is not a security interface notes, this doesn't make it impossible for other programs to see the keys, but it seems likely that window managers will not be using XQueryKeyMap so it is likely to prevent task switching.
I have an application in java in which I have start and stop buttons in swing. I want to make a windows service which automatically clicks on start button. Is it possible and if it's possible how to do it?
You must find a way to identify the main window of your swing application from the Windows service (common usage is the title bar)
Then, you search in subwindows how to identify the Start button (generally the id, but you could use text)
All that must be done only once, using the Windows SDK tools and/or you knowing from the GUI application
Now the service :
searches the top-level windows for the right one
searches the relevant button
gets it position
uses SendInput API function to simulate a MOUSEEVENTF_LEFTDOWN and MOUSEEVENTF_LEFTUP event over the button
The last part could be done in Java (with Robot), but the others will need to use Windows API
I have an application written on Java running on the machine (Linux/Windows). I want to make this application run like a background application so that it does not interrupt while using other applications in the system. Now I want to popup a screen and show some buttons (to do some tasks based on the selection) when a QR Code is scanned using a scanned attached to the USB port. When this scanning happens my Java application that initiates the popup screen is running in the system tray.
--Edit--
I have used key listeners to identify the bar code scanning and pull out information from database based on what is scanned. But while scanning my application, was open. So I attached the action listeners in the AWT level so that the key strokes/scanning is caught and taken care off. But now in the current case I wont be having any windows active. SO I NEED TO CAPTURE THE SCANNED INPUT INTERNALLY WHEN THE APPLICATION IS MINIMIZED IN THE SYSTEM TRAY.
I think the only avenue open to you is capturing system-wide keyboard events. There is a library that handles that for Java: jnativehook. But how you're going to detect which events are coming specifically from your HID device, I'm not sure.
There is also the JavaHIDAPI, an amateur-level project whose "hello, world" test example failed with IOException on my machine. The good part is, all the code is there, including the native C for Windows.
Finally, I found this, a very good tutorial on how to talk to HID's on Windows.
You can see if Headless Mode works or start up VNC on your host.
Is there any option which i can use to Control Window State of another App. from a Java Application .
Like if i need to minimize or maximize another app. window on Ubuntu Enviroment (if it's matter's im using Gnome Window Manager).
Bests
Two bad options:
1) use java.awt.Robot to click the appropriate coordinates where the window is. (You have to hard code these)
2) use jni
I am working on a Java application which has to launch a different application. If I launch the second application using Runtime.getRuntime().exec(), it becomes the active process and its window comes before my application's window. What I really want to do is launch the process in "hidden" mode so that its taskbar entry does not appear and its window is initially invisible or behind my application window. Then my application would make it visible or move it to the front when it is good and ready. Is this possible or am I asking for too much?
This is for a demo. So I am not worried about security issues.
Edit: Daniel's answer has given me an idea. What if I use Powershell to invoke the application instead of CMD.EXE? Will that let me start the app without the window and then bring the window back? I will be using to launch java to launch PowerShell to launch app, but what the heck!
You don't say what this other application is, but I'm assuming that it's one that you have no control over (i.e. you can't give it a parameter option to start up in a minimized mode or similar.) Rather than hide the application you're launching, can you just use the toFront() method on your window after the other application has launched to bring your window in front of the other? And then minimize your window when you want to reveal the other one?
I'm the first to admit it's a bit of a bodged solution, but it might work depending on what you're after.
You cannot provide these parameters, BUT you can use the "start" command (try it in cmd), which supports these parameters. Eventually you have to call it with a cmd.exe shell, but this will work!