如何使用Java在屏幕上移动Windows窗口? [英] How to use Java to move Windows windows around on screen?

查看:1046
本文介绍了如何使用Java在屏幕上移动Windows窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在考虑用GUI创建一个窗口管理器,可能是用Java编写的。但是,我正在努力找出移动不属于我的程序的窗口的最佳方法。

I've been contemplating making a window manager with a GUI, probably in Java. However, I'm struggling to figure out the best way to move windows not owned by my program.

到目前为止,似乎我应该使用JNI与Windows API进行交互,但我没有找到任何有用的示例。

So far, it would seem I should use JNI to interface with the Windows API, but I haven't found any helpful examples.

有谁知道怎么做?

谢谢!

PS。我不一定与Java绑在一起,如果有更好的语言可以做到这一点。

PS. I'm not necessarily tied to Java, if there is a better language to do this in.

推荐答案

如果目的是为了有一个快速的窗口管理器你最好用C ++或C#,甚至Delphi。

If the purpose is to have a fast window manager you are certainly better off with C++ or C#, or maybe even Delphi.

但如果你最熟悉Java,那就可以了。

But if you are most familiar with Java it can be done.

如果选择(老化)JNI,则必须使用Java应用程序将使用的C或Delphi编写DLL。您应该使用 JNA 来访问Windows的窗口处理API函数。

If you choose the (aging) JNI you would have to write a DLL in C or Delphi that you Java application will use. You should use JNA instead to access the Windows' window handling API functions.

您将使用的一些功能是:

Some of the functions you would use are:

    HWND WINAPI GetWindow(HWND hWnd, UINT uCmd);
    HWND WINAPI FindWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName);
    BOOL WINAPI EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam);
    HWND WINAPI WindowFromPoint(POINT Point);
    BOOL WINAPI MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint);

获得窗口句柄(HWND)后,您可以使用该窗口执行任何操作。

Once you get the window handle (HWND) you can do whatever you like with that window.

MSDN上的EnumWindows函数引用

这篇关于如何使用Java在屏幕上移动Windows窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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