本文介绍了java JNA - 查找部分窗口标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过标题获取一个窗口然后激活它。问题是 FoundWindow 方法搜索所有标题。
我想通过其部分标题获得一个窗口。

I want to get a window by its title and then activate it. The problem is that the FoundWindow method searches on the all title.I would like to get a window by its partial title.

import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
public class IsRunning {

public static void main(String[] args) {
    HWND hwnd = User32.INSTANCE.FindWindow
           (null, "Untitled - Notepad"); // window title
    if (hwnd == null) {
        System.out.println("Notepad window is not running");
    }
    else{
        User32.INSTANCE.ShowWindow(hwnd, 9 );        // SW_RESTORE
        User32.INSTANCE.SetForegroundWindow(hwnd);   // bring to front
        }
    }
}

字符串Untitled - Notepad,我想只搜索无题。

Instead of the string "Untitled - Notepad", I would like to search by "Untitled" only.

推荐答案

看看这个回答的java中的窗口句柄。然后,您可以根据自己的需要过滤它们。

Have a look on this answer "how to get list of all window handles in java using jna". You can then filter them on your own needs.

这篇关于java JNA - 查找部分窗口标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 03:14