简体   繁体   English

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

[英]Bridj no longer working for Windows taskbar loading

I've been using code to make the taskbar icon of my Java application have a loading bar feature which is native to Windows 7+ applications.我一直在使用代码使我的 Java 应用程序的任务栏图标具有Windows 7+应用程序原生的加载栏功能。 The code I use is the following:我使用的代码如下:

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

An SSCCE can be found here .可以在此处找到SSCCE

The maven dependencies I use are:我使用的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>

However, I'm getting the following error:但是,我收到以下错误:

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)

Note that I tried an older JNA version like 4.1.0 as well and it yielded the same error.请注意,我也尝试了较旧的JNA版本,例如4.1.0 ,但它产生了相同的错误。 What exactly broke and how can it be fixed?究竟是什么坏了,如何修复?

Somehow I missed the solution which was right in the example file via comment on this line: https://github.com/nativelibs4java/BridJ/blob/master/src/main/demos/TaskbarListDemo.java#L99不知何故,我通过在这一行的评论错过了示例文件中正确的解决方案: https : //github.com/nativelibs4java/BridJ/blob/master/src/main/demos/TaskbarListDemo.java#L99

Replacing the getNativePeerHandle() call with getComponentID() did the trick.getComponentID()替换getNativePeerHandle()调用就成功了。

虽然可能性很小,但我建议在您的项目中添加 'jawt' dll 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM