简体   繁体   中英

Change process' window size in Java

I have a Java program that launches another Java application via ProcessBuilder. My program also retains a Process object after launching the other application.

ProcessBuilder launcher = new ProcessBuilder(argArray);
Process processHandle = launcher.start();

In my program, I have 'user preferences' where the user can specify the on-screen size and location of the other application that is being started. I need my program to be able to change the size and location of the other application's window in pixels, preferably without utilizing P/Invoke, as this is meant to be a cross-platform application. Does anyone know how to change a Process' window size and location programmatically in Java?

You can't do this with pure Java, but if you write a JNI DLL you can do it via SetWindowPos in Windows.

Check the API: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx

You can get the HWND of the remote process via a combination of calls to EnumWindows and GetWindowThreadProcessId .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM