在 Java 应用程序中嵌入外部应用程序(或伪造它)
我有一个将在 Windows 7 上运行的 java 应用程序(使用 Swing,应用程序 #1),该应用程序以全屏方式运行(但不是以独占模式运行)。我有另一个应用程序(应用程序#2),它显示一个 GUI,用于通过串行端口配置外部设备,我没有源代码,也根本无法更改。
我想将应用程序 #2 嵌入到应用程序 #1 中,这样它看起来就像是父 java 应用程序的一部分(隐藏文件 --> 退出按钮并隐藏最小化、最大化和关闭按钮)。
如果这种集成在 Java 应用程序内部不可能实现,那么我可以使用 Java 打开该进程并监视它以使其保持打开状态。它需要将窗口设置为“始终位于顶部”,因为应用程序 #1 是全屏的,并隐藏尽可能多的外部 MS Windows UI,以欺骗用户认为它不是外部应用程序。是否有某种方法使用 JNI 或其他方法来管理另一个进程窗口(屏幕位置、标题栏、最小化、最大化、关闭按钮可见性)和我的 Java 应用程序内部的进程状态?
如果需要,我很乐意提供更多信息。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下方案是与语言无关的,我已经设法通过这种方式将 IE 窗口嵌入到 Ruby 应用程序中:
首先,更改外部应用程序窗口的样式(您可以使用 JNA 调用 WinAPI):
样式 = GetWindowLongPtr(APP_HWND, GWL_STYLE);
样式 |= WS_CHILD;
样式 &= ~WS_CAPTION;
样式 &= ~WS_POPUP;
SetWindowLongPtr(HWND, GWL_STYLE, style);
定义窗口之间的父子关系:
SetParent(APP_HWND, JAVA_HWND);
监听 Java 窗口的移动/调整大小事件,并在子窗口上应用新位置。
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.