2
votes

I'm writing a screensaver in Java. It's primarily for Windows, though I'd prefer it to be as portable as practical.

According to http://support.microsoft.com/kb/182383, when a screensaver is invoked with command line args /p HWND, the screensaver should "Preview Screen Saver as child of window ." Presumably this is how screensavers should their little preview in the Screen Saver Settings dialog.

So how, in Java, do you create a JFrame or JComponent that's a child of a window that belongs to somebody else? I've looked at Embed HWND (Window Handle) in a JPanel which is sort of the reverse question: The developer controls the parent window and wants to embed a child window. In my case, I control a child component that I want into embed into a parent that is not "mine". Can I use JNA to do that?

I'd rather not have to maintain C code in addition to Java code. (So JNI is not preferred.) I understand that JDIC was supposed to meet this kind of need, but I've read that JDIC is essentially dead.

I'm running Windows 7, FWIW.

2
not an expert in this domain, but would think this is not possible because your java app would have to take over a windows process - and that seems wrong from a security perspective.dbrin
@DmitryB: I'd like to hear more about that. It's clearly possible for some programs to do (all compliant screensavers do)... yet not for a Java program?LarsH
@DmitryB: see e.g. harding.edu/fmccown/screensaver/screensaver.html for a C# implementation that does this: SetParent(this.Handle, PreviewWndHandle);LarsH
hmmm yeah ... Java is not "any of the .NET programming languages" as per tutorial :) I had to use JNA library to talk to a dll - it was tough. every method had to be exported just so and all of the variables had to line up.dbrin
@DmitryB: the fact that Java is not "any of the .NET programming languages" is a valid point, but it simply means that that tutorial does not say you can do it in Java. It does not mean the tutorial says you cannot do it in Java. And (my point was) the fact that you can do it in .NET suggests that it is not "wrong from a security perspective" in Windows. But I would be happy to see further details showing that SetParent() is somehow "special", and is not possible in pure Java.LarsH

2 Answers

0
votes

Have a look at Jdic, it has an SDK for screensavers, so at least you may study their code..

0
votes

You need to call a win32 api. That api is in C. You'll need to the interop layer to do this. I think every option will be gross.

For Java, I think that is JNI. See this on how to do it.

You will also need to pass that value to SetParent.

The screen saver runs at the same security rights as the screensaver dialog so this isn't a security issue.