BRIDJ不再用于Windows任务栏加载



我一直在使用代码使我的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

我使用的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,并且产生了相同的错误。什么到底破裂了,如何修复?

以某种方式我错过了示例文件中通过此行的注释中正确的解决方案:https://github.com/nativelibs4java/bridj/blob/master/src/src/main/demos/taskbarlistdemo.java#l99

getComponentID()替换getNativePeerHandle()呼叫做到了。

尽管概率很低,但我建议在项目中添加'jawt'dll文件。

相关内容

  • 没有找到相关文章

最新更新