Java JNA FindWindow() - 查找函数'FindWindow'时出错:找不到指定的过程

时间:2014-02-22 23:30:41

标签: java jna user32

我正在尝试使用MyWindowTitle将名为JNA的窗口带到前面。

import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.platform.win32.WinDef.HWND;

public class ToFront {

public static interface User32 extends StdCallLibrary {
    final User32 instance = (User32) Native.loadLibrary ("user32", User32.class);
    HWND FindWindow(String winClass, String title); 
    boolean ShowWindow(HWND hWnd, int nCmdShow);
    boolean SetForegroundWindow(HWND hWnd);

}


public static void main(String[] args) {
    HWND hwnd = User32.instance.FindWindow(null, "MyWindowTitle"); 
    User32.instance.ShowWindow(hwnd, 9); 
    User32.instance.SetForegroundWindow(hwnd); 
}

}

我收到以下异常java.lang.UnsatisfiedLinkError: Error looking up function 'FindWindow': The specified procedure could not be found.

2 个答案:

答案 0 :(得分:2)

检查功能的拼写。您可以使用依赖性walker来查看您的dll中是否存在该函数。

Ps:当我打开user32.dll时,那些是我找到的功能

:FindWindowA,FindWindowExA,FindWindowExW,FindWindowW 

答案 1 :(得分:2)

您可以使用以下调用FindWindowEx的代码。请注意,FindFindow不会根据本文http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499(v=vs.85).aspx

搜索子窗口
import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.win32.StdCallLibrary;

public class SomeClass 
{
    public static interface User32 extends StdCallLibrary
    {
         final User32 instance = (User32) Native.loadLibrary ("user32", User32.class);
         HWND FindWindowExA(HWND hwndParent, HWND childAfter, String className, String windowName);
         HWND FindWindowA(String className, String windowName);
    }

    public static void main(String[] args)
    {
        HWND hwndShell = User32.instance.FindWindowExA(null, null, "Shell_TrayWnd", null);
        HWND hWnd = User32.instance.FindWindowExA(hwndShell, null, "Start", "Start");     
    }
}