java JNA - find partial window title

♀尐吖头ヾ 提交于 2019-12-04 05:20:22

问题


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
        }
    }
}

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


回答1:


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.



来源:https://stackoverflow.com/questions/27839666/java-jna-find-partial-window-title

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!