Is there any way to draw an invisible overlay on top of the screen (meaning in front of all windows and everything else) in C++ and/or Java?
It doesn't need to support 3D graphics or anything fancy, I just need to be able to draw
lines/pixels on it.
There are some other solutions that I found on the internet, but they all either
1) don't allow mouse clicks to go through them (onto the windows or other stuff under it) or
2) are only for Windows (I need something that works on Windows and Linux, but Mac support would also be nice).
One easy way could be create a transparent window which fits on the entire screen size, and lock it at the top of the z-order stack.
Thats what I usually do when write screensavers.
Related
My goal is to make a simple GUI which almost look like this attached screenshot.
But while using Awt, Swing i have never found yet such combo/buttons nor i have found something like transparent window which showing my desktop background.
I am very desperate to make something similar, but i am not sure which framework i can use?
Can i do this above UI, with GWT? or is there something else?
Java has always supported translucent windows on Mac (from at least OS X 10.4 but probably way before that too).
However on Windows you need at least Java 1.6.0_10 to be able to do translucent windows directly from Java.
If for whatever reason you're stuck with an older Java you can use JNA. They've got examples as to how to create translucent windows on OS X, Windows and Linux and these examples work even on older JVMs.
As I type this JNA is located here:
https://github.com/twall/jna
Here's the code for their alpha/translucent example (where you can drag a picture with an alpha channel, like a PNG with an alpha channel and then choose the opacity):
https://github.com/twall/jna/tree/master/contrib/alphamaskdemo/com/sun/jna/contrib/demo
Now what you want to do can be done but there are gotchas: you need to be careful about several things. For example mouse events: if you want catch them or not when they happen on an area that is "fully transparent" (if you want to catch them, you can cheat and make your translucent window nearly --but not fully-- transparent).
What you want to do is a bit like a HUD: there are definitely HUDs done in Java but as far as I know they weren't build using GUI builder tools. You'll probably have to code it manually (or at least some part of it manually).
See this: How to Create Translucent and Shaped Windows
I want to make a transparent overlay for a foreign project to show live video. Sample of overlay is given in the image link below. In image you can see a overlay at right bottom corner showing face of a person, I also want to achieve same functionality using JMF to show face and then display the face in overlay using swing.
Sample Overley Imahe: http://www.ovostudios.com/images/vidsamsolo.jpg
Can someone help achieving this functionality?
If you're just starting the project and haven't actually got the JMF part up and running yet, then you might want to take a look at some alternatives before committing to it.
If you want to go ahead with Swing, to get the general overlay behaviour you want, you'll need to make use of Frame.setUndecorated() to turn off window borders and buttons, and Window.setAlwaysOnTop() to make sure the window stays on top of other windows. For the transparency, see this tutorial. However, I'm not sure whether transparency and video will work nicely together, so good luck!
You might also want to write a custom focus handler for the window so that it cannot be focused, although it is probably impossible for the overlay to be properly 'phantom' whereby clicks just pass through the overlay to the underlying desktop. That kind of behaviour might only be possible by using low-level graphics techniques i.e. by not creating a window at all, but by drawing directly onto the screen. That might require a native library.
Is it possible to simply paint() (or use some other function) to the screen in Java? As in draw over everything else on some coordinates of the screen itself, not inside some window.
If not, is it possible to make an invisible window that takes up the entire screen and use its glass pane to do it? Would complications arise from doing this? (Such as not being able to click on other applications)
Are there any other ways?
Thanks.
Edit: I'm not trying to do full screen with this, by the way.
When you paint() in Java, you're painting only within the confines of the size and location of what is being paint()ed.
If you're looking to do full screen stuff, there are tutorials for that:
http://download.oracle.com/javase/tutorial/extra/fullscreen/index.html
In theory, you can create an transparent undecorated maximized JFrame. This will allow you to "paint" over the desktop. Problems are obvious: if an application stays behind this window, it will not receive any mouse events.
Months ago, I made an evil cheat to draw directly on Windows Explorer's Desktop: mixing some .NET coding with JNI and Sun's internal classes - that's surreal, but works.
Is it possible to get image contents of an obstructed window without bringing it to the front? Also, is it possible to send mouse clicks to a specific locations of such window? I want to do this in Java, using JNA, running Windows XP (if it is possible, would it also work on Windows 7?). If that can be done, would you mind telling me what functions will be needed and where can I read about it, because I have never worked with JNA yet. Thank you.
I'm trying to create a java desktop application that holds desktop icons. The app will be a menu/panel that is invisible until you hover your cursor near the top of the screen, at which point the menu full of desktop icons will drop down. To add new icons to the menu one must simply drag icons from the desktop into the menu and they should snap to grid. As I am an intermediate level programmer but I havn't ever done a GUI app before in any language, I was wondering if someone could help me out, both with how to approach the problem and on the packages and methods I should be using. Also, I'm thinking of doing this with NetBeans unless you have any other suggestions.
Thanks,
Andrew
As an alternative to Chad's option, you could also do this by creating a frame and using Java's transparent window capability to make the frame transparent (or translucent, if you want a hint that it's there), and using mouse entered/exited events to return the frame to its normal "solid" opacity.
Personally I'd try this solution just because I'd rather use event-based notification than polling the mouse position, but I expect it's more work than the other alternative.
As to drag and drop, I haven't used it extensively enough in Java to give any solutions, but it's not immediately obvious (from a cursory internet search) of how to handle native desktop drag and drops. I'd suggest starting with some dnd tutorials within an application so that you really understand Java's drag and drop API and capabilities.
You can use java.awt.MouseInfo to get the location of the mouse at any point in time, even if you don't have any windows open.
So, you could start a java program, then in your main loop poll the mouse location. If it's in the 'top', then you can open a window.
You can use the easiest thing to do would be to use JButtons or JLabels with images to represent the desktop icons. Just load the image you want to use and stick that on as a label.
I'd start by going through swing tutorial and writing a few simple GUI programs to get the hang of it.
But the MouseInfo thing is what you need to tell when the mouse is at the top of the screen.