在 Java 中从其他应用程序操作窗口 [英] Manipulating windows from other applications in Java
问题描述
我想用 Java 编写 Windows 7 窗口管理器,但存在一些问题.首先,如何操作不属于我自己的应用程序的窗口的大小和位置?换句话说,我如何操作其他应用程序的窗口?
I want to write a Windows 7 Window Manager in Java, but there are some issues. First of all, how do i manipulate the size and position of a window that doesn't belong to my own application? In other words, how can I manipulate the windows of other applications?
而且,关于我的第一个问题,是否可以获得所有当前窗口的列表?
And, related to my first question, is it possible to get a list of all current windows?
最后一个问题:Java 适合这项任务还是我应该看看 C#?
And, the last question: is Java suited for this task or should I take a look at C#?
推荐答案
第一:Java 可能不是最适合此任务的语言.您需要调用本机 Windows API,因此 C/C++ 将是一个自然的选择.您可以将 Java 与 JNI 一起使用,但可能不值得麻烦.我不知道 C#/Managed C++,所以不能说些什么.
First: Java is probably not the best suited language for this task. You need to call the native Windows API, so C/C++ would be a natural fit. You can use Java with JNI, but is probably not worth the hassle. I dont know about C#/Managed C++, so cant say something about it.
获取当前 Windows 的列表:http://support.microsoft.com/kb/183009
Getting a List of current Windows: http://support.microsoft.com/kb/183009
更改窗口位置:
设置窗口位置
设置窗口位置
Changing Window Positions:
SetWindowPos
SetWindowPlacement
您可能还需要在窗口发生变化时获得通知.看看例如SetWindowsHookEx,尤其是 CBTHook.
You may also need to get informed whenever a window changes. Look at e.g. SetWindowsHookEx, especially the CBTHook.
上次我尝试时,总是允许更改其他进程的窗口.如果在 windows7 下不再允许这样做,您可以随时安装全局钩子并从进程内部更改窗口...
Last Time i tried, it was always allowed to change windows of other processes. If this isnt allowed anymore under windows7, you can always install a global hook and change the windows from INSIDE the process...
这篇关于在 Java 中从其他应用程序操作窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!