使JFace Window在任务栏中闪烁还是引起用户注意?

使JFace Window在任务栏中闪烁还是引起用户注意?,第1张

使JFace Window在任务栏中闪烁还是引起用户注意?

我认为没有平台独立的方法可以做到这一点。您将必须查看特定于平台的API调用,并通过JNI或JNA实现它们。

对于Windows,这是我自己的一个应用程序的摘录:

public static void flashWindow(final Shell shell, boolean flashTray,        boolean flashWindow) {    try {        if (isActiveWindow(shell)) { flashWindow = false; flashTray = false;        }        User32 lib = (User32) getLibrary("user32", User32.class);        User32.FLASHWINFO flash = new User32.FLASHWINFO();        flash.hWnd = new W32API.HANDLE(new W32API.UINT_PTR(shell.handle)     .toPointer());        flash.uCount = 2;        flash.dwTimeout = 1000;        if (flashTray || flashWindow) { flash.dwFlags = (flashTray ? User32.FLASHW_TRAY : 0)         | (flashWindow ? User32.FLASHW_CAPTION : 0);        } else { flash.dwFlags = User32.FLASHW_STOP;        }        flash.cbSize = flash.size();        if (lib.FlashWindowEx(flash) && !flashWindow) { final FocusListener focusListener = new FocusListener() {     public void focusGained(FocusEvent arg0) {         flashWindow(shell, false, false);         shell.removeFocusListener(this);     }     public void focusLost(FocusEvent arg0) {     } }; shell.addFocusListener(focusListener);        }    } catch (UnsatisfiedlinkError e) {    }}

这是的简化版本

getLibrary()

protected static StdCallLibrary getLibrary(String libraryName,        Class<?> interfaceClass) throws UnsatisfiedlinkError {    try {        StdCallLibrary lib = (StdCallLibrary) Native.loadLibrary(libraryName,     interfaceClass);        return lib;    } catch (UnsatisfiedlinkError e) {        Logger.out.error("Could not load " + libraryName + " library.");        throw e;    }}

使用

dispose()
完库后,请多加注意。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5439508.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存