Using JNA to get/set application identifier

前端 未结 3 1151
忘了有多久
忘了有多久 2020-12-04 12:48

Following up on my previous question concerning the Windows 7 taskbar, I would like to diagnose why Windows isn\'t acknowledging that my application is independent of

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 13:12

    If you just need to set the AppUserModelId then the above JNA code is enough. However if you want to take advantage of the new Windows 7 features in you Java application then check out J7Goodies a Java library providing Windows 7 taskbar extensions.


    EDIT: more info from J7Goodies Programmer's Guide

    4.2. Setting AppUserModelID

    In order to use any of the Windows 7 features an application must explicitly set its process identifier – Application User Model ID (AppUserModelID). It can have no more than 128 characters and cannot contain spaces. Each section should be camel-cased, for example:

     CompanyName.ProductName.SubProduct.VersionInformation
    

    This identifier must be set before any GUI (window) is shown. You set it by calling:

    // Remember to set AppUserModelID before creating any UI
    AppUserModelId.setCurrentProcessId("StrixCode.J7Goodies.Appname");
    

    4.3. Setting Window Properties

    A Java application cannot be pinned to the Windows 7 taskbar unless its window properties are defined. The properties consist of four fields:

    • AppUserModelID – the same as passed to AppUserModelId.setCurrentProcessId(String)
    • RelaunchDisplayName – application’s name
    • RelaunchCommand – the full command used to launch the application. In case of a Java program it will be: -jar
    • RelaunchIcon – path to application’s icon

    Important: RelaunchCommand and RelaunchDisplayName must always be set together. To set these properties use the straightforward WindowProperties class.

    WindowProperties props = new WindowProperties(myFrame);
    props.setRelaunchCommand("");
    props.setRelaunchDisplayName("My Java Application");
    props.setRelaunchIcon("");
    props.setAppUserModelID("StrixCode.J7Goodies.Appname");
    props.save();
    

提交回复
热议问题