Create child Window of another process's HWND? (e.g. screensaver preview)

霸气de小男生 提交于 2019-12-11 02:39:10

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/9855743/create-child-window-of-another-processs-hwnd-e-g-screensaver-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!