Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
638 views
in Technique[技术] by (71.8m points)

winapi - How to use Java to move Windows windows around on screen?

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.

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

Does anyone know how to do this?

Thanks!

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

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);

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

EnumWindows function reference at MSDN


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...