Bridj不再适用于Windows任务栏加载

时间:2019-05-12 19:50:04

标签: java windows loading taskbar bridj

我一直在使用代码使Java应用程序的任务栏图标具有Windows 7+应用程序固有的加载栏功能。我使用的代码如下:

import lombok.val;
import org.bridj.Pointer;
import org.bridj.cpp.com.COMRuntime;
import org.bridj.cpp.com.shell.ITaskbarList3;

import java.awt.*;

import static org.apache.commons.lang3.SystemUtils.*;
import static org.bridj.Pointer.pointerToAddress;
import static org.bridj.jawt.JAWTUtils.getNativePeerHandle;

public class WindowsTaskBarProgress
{
    private ITaskbarList3 taskBarList3;
    private Pointer<Integer> pointer;
    private long maximum;

    public WindowsTaskBarProgress(Component component) throws ClassNotFoundException
    {
        if (isSupportedPlatform())
        {
            taskBarList3 = COMRuntime.newInstance(ITaskbarList3.class);
            val nativePeerHandle = getNativePeerHandle(component); // <- The error arises here
            Pointer.Releaser release = pointer -> {
            };

            pointer = pointerToAddress(nativePeerHandle, Integer.class, release);
        }

        this.maximum = 100;
    }

    public void setProgressValue(long value)
    {
        if (isSupportedPlatform())
        {
            taskBarList3.SetProgressValue(pointer, value, maximum);
        }
    }

    public void resetProgress()
    {
        setProgressValue(0);
    }

    /*public void setProgressFlag(ITaskbarList3.TbpFlag flag)
    {
        if (isSupportedPlatform())
        {
            taskBarList3.SetProgressState(pointer, flag);
        }
    }*/

    private static boolean isSupportedPlatform()
    {
        return IS_OS_WINDOWS_7
                || IS_OS_WINDOWS_8
                || IS_OS_WINDOWS_10;
    }

    public void setMaximum(long maximum)
    {
        this.maximum = maximum;
    }
}

可以SSCCE找到here

我使用的maven依赖项是:

<!-- Windows 7+ task bar progress bar -->
<dependency>
    <groupId>com.nativelibs4java</groupId>
    <!-- https://github.com/nativelibs4java/BridJ -->
    <artifactId>bridj</artifactId>
    <version>0.7.0</version>
</dependency>
<dependency>
    <!-- https://github.com/java-native-access/jna -->
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>5.3.1</version>
</dependency>
<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna-platform</artifactId>
    <version>5.3.1</version>
</dependency>

但是,出现以下错误:

java.lang.UnsatisfiedLinkError: org.bridj.jawt.JawtLibrary.JAWT_GetAWT(Lorg/bridj/Pointer;Lorg/bridj/Pointer;)Z
    at org.bridj.jawt.JawtLibrary.JAWT_GetAWT(Native Method)
    at org.bridj.jawt.JAWTUtils.getJAWT(JAWTUtils.java:66)
    at org.bridj.jawt.JAWTUtils.getNativePeerHandle(JAWTUtils.java:129)

请注意,我也尝试了JNA之类的4.1.0较旧版本,并且产生了相同的错误。到底发生了什么,如何解决?

2 个答案:

答案 0 :(得分:0)

尽管可能性很小,但我建议将“ jawt” dll文件添加到项目中。

答案 1 :(得分:0)

不知何故,我在此行中通过注释错过了示例文件中正确的解决方案: https://github.com/nativelibs4java/BridJ/blob/master/src/main/demos/TaskbarListDemo.java#L99

getNativePeerHandle()代替getComponentID()呼叫就可以了。