How can I get the window handle (hWnd) for a Stage in JavaFX?

后端 未结 4 2022
南旧
南旧 2020-12-17 03:17

We\'re building a JavaFX application in Windows, and we want to be able to do some things to manipulate how our application appears in the Windows 7/8 taskbar. This require

4条回答
  •  天命终不由人
    2020-12-17 03:51

    Here's a JavaFX2 version (uses Stage rather than Window):

    private static Pointer getWindowPointer(Stage stage) {
        try {
            TKStage tkStage = stage.impl_getPeer();
            Method getPlatformWindow = tkStage.getClass().getDeclaredMethod("getPlatformWindow" );
            getPlatformWindow.setAccessible(true);
            Object platformWindow = getPlatformWindow.invoke(tkStage);
            Method getNativeHandle = platformWindow.getClass().getMethod( "getNativeHandle" );
            getNativeHandle.setAccessible(true);
            Object nativeHandle = getNativeHandle.invoke(platformWindow);
            return new Pointer((Long) nativeHandle);
        } catch (Throwable e) {
            System.err.println("Error getting Window Pointer");
            return null;
        }
    }
    

提交回复
热议问题