gpt4 book ai didi

java - Bridj 不再支持 Windows 任务栏加载

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:52 25 4
gpt4 key购买 nike

我一直在使用代码使我的 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,但它产生了相同的错误。究竟是什么出了问题以及如何修复?

最佳答案

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

getComponentID() 替换 getNativePeerHandle() 调用就可以了。

关于java - Bridj 不再支持 Windows 任务栏加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56102905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com