创建另一个进程的 HWND 的子窗口?(例如屏幕保护程序预览) [英] Create child Window of another process's HWND? (e.g. screensaver preview)

查看:19
本文介绍了创建另一个进程的 HWND 的子窗口?(例如屏幕保护程序预览)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Java 编写屏幕保护程序.它主要用于 Windows,但我更喜欢它的便携性和实用性.

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

根据 http://support.microsoft.com/kb/182383,当使用命令行参数 /p HWND 调用屏幕保护程序,屏幕保护程序应将屏幕保护程序预览为 window 的子项".大概这就是屏幕保护程序在屏幕保护程序设置"对话框中进行小预览的方式.

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.

那么,在 Java 中,您如何创建属于其他人的窗口的子窗口的 JFrame 或 JComponent 呢?我看过在JPanel中嵌入HWND(窗口句柄)这是一种相反的问题:开发人员控制父窗口并希望嵌入子窗口.就我而言,我控制了一个我想要嵌入到非我的"父组件中的子组件.我可以使用 JNA 来做到这一点吗?

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?

除了 Java 代码之外,我宁愿不必维护 C 代码.(所以 JNI 不是首选.)我知道 JDIC 应该满足这种需求,但我读过 JDIC 基本上已经死了.

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.

我运行的是 Windows 7,FWIW.

I'm running Windows 7, FWIW.

推荐答案

你需要调用一个 win32 api.该 api 在 C 中.您需要使用互操作层来执行此操作.我认为每个选项都会很糟糕.

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.

对于Java,我认为是JNI.有关如何执行此操作,请参阅此.

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

您还需要将该值传递给 SetParent.

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.

这篇关于创建另一个进程的 HWND 的子窗口?(例如屏幕保护程序预览)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆