English 中文(简体)
如何扫描打开窗口
原标题:How to scan open windows
  • 时间:2012-05-28 05:14:36
  •  标签:
  • java
  • window

能否用 java 扫描所有打开的窗口, 并找到指定的窗口 。 Say notepad? 例如, 我想要笔记本在前面和中间打开并准备, 它打开, 当我运行我的程序时, 它会扫描所有打开的窗口, 并将笔记本往前移动 。

问题回答

I have extensive experience on Windows system. And I know that Windows system specific requirements are properly met in Windows Management Instrumentation (WMI). I have used WMI successfully like what you’re doing but I never did it with Java. Here’s a link at WMI explanations. Please tell me which ones you tried and state your conclusion.

相信我,一旦你知道如何用爪哇访问WMI,你几乎可以在窗口系统中做任何事情。当然,如果我承担这样的要求,我会使用C#和.NET。但爪哇是你的选择

JNA可以做到这一点。

import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;


// https://github.com/twall/jna#readme
//    you need 2 jars : jna-3.5.1.jar and platform-3.5.1.jar

public class ActivateNotepad {

    public static void main(String[] args) {
            HWND hwnd = User32.INSTANCE.FindWindow("Notepad", null);
            if (hwnd == null) {
                System.out.println("No Notepad instance detected");
            }
            else{
                System.out.println("Notepad instance found.");
                User32.INSTANCE.SetForegroundWindow(hwnd);  
            }
        }
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签