Class FlatNativeWindowsLibrary


  • public class FlatNativeWindowsLibrary
    extends java.lang.Object
    Native methods for Windows.

    Note: This is private API. Do not use!

    Since:
    3.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int API_VERSION_WINDOWS  
      static java.awt.Color COLOR_NONE  
      static int DWMWA_BORDER_COLOR
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      static int DWMWA_CAPTION_COLOR
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      static int DWMWA_COLOR_DEFAULT  
      static int DWMWA_COLOR_NONE  
      static int DWMWA_TEXT_COLOR
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      static int DWMWA_USE_IMMERSIVE_DARK_MODE
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      static int DWMWCP_DEFAULT
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      static int DWMWCP_DONOTROUND
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      static int DWMWCP_ROUND
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      static int DWMWCP_ROUNDSMALL
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      private static long osBuildNumber  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean dwmSetWindowAttributeBOOL​(long hwnd, int attribute, boolean value)
      Invokes Win32 API method DwmSetWindowAttribute() with a BOOL attribute value.
      static boolean dwmSetWindowAttributeCOLORREF​(long hwnd, int attribute, java.awt.Color color)
      Invokes Win32 API method DwmSetWindowAttribute() with a COLORREF attribute value.
      static boolean dwmSetWindowAttributeDWORD​(long hwnd, int attribute, int value)
      Invokes Win32 API method DwmSetWindowAttribute() with a DWORD attribute value.
      static long getHWND​(java.awt.Window window)
      Gets the Windows window handle (HWND) for the given Swing window.
      static long getOSBuildNumber()
      Gets the Windows operating system build number.
      private static long getOSBuildNumberImpl()
      Invokes Win32 API method GetVersionEx() and returns OSVERSIONINFO.dwBuildNumber.
      static boolean isLoaded()
      Checks whether native library is loaded/available.
      static boolean setWindowCornerPreference​(long hwnd, int cornerPreference)
      Sets the rounded corner preference for the window.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • API_VERSION_WINDOWS

        private static int API_VERSION_WINDOWS
      • osBuildNumber

        private static long osBuildNumber
      • DWMWCP_DEFAULT

        public static final int DWMWCP_DEFAULT
        DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
        See Also:
        Constant Field Values
      • DWMWCP_DONOTROUND

        public static final int DWMWCP_DONOTROUND
        DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
        See Also:
        Constant Field Values
      • DWMWCP_ROUND

        public static final int DWMWCP_ROUND
        DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
        See Also:
        Constant Field Values
      • DWMWCP_ROUNDSMALL

        public static final int DWMWCP_ROUNDSMALL
        DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
        See Also:
        Constant Field Values
      • DWMWA_USE_IMMERSIVE_DARK_MODE

        public static final int DWMWA_USE_IMMERSIVE_DARK_MODE
        DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
        Since:
        3.3
        See Also:
        Constant Field Values
      • DWMWA_BORDER_COLOR

        public static final int DWMWA_BORDER_COLOR
        DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
        Since:
        3.3
        See Also:
        Constant Field Values
      • DWMWA_CAPTION_COLOR

        public static final int DWMWA_CAPTION_COLOR
        DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
        Since:
        3.3
        See Also:
        Constant Field Values
      • DWMWA_TEXT_COLOR

        public static final int DWMWA_TEXT_COLOR
        DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
        Since:
        3.3
        See Also:
        Constant Field Values
      • DWMWA_COLOR_DEFAULT

        public static final int DWMWA_COLOR_DEFAULT
        Since:
        3.3
        See Also:
        Constant Field Values
      • COLOR_NONE

        public static final java.awt.Color COLOR_NONE
        Since:
        3.3
    • Constructor Detail

      • FlatNativeWindowsLibrary

        public FlatNativeWindowsLibrary()
    • Method Detail

      • isLoaded

        public static boolean isLoaded()
        Checks whether native library is loaded/available.

        Note: It is required to invoke this method before invoking any other method of this class. Otherwise, the native library may not be loaded.

      • getOSBuildNumber

        public static long getOSBuildNumber()
        Gets the Windows operating system build number.

        Invokes Win32 API method GetVersionEx() and returns OSVERSIONINFO.dwBuildNumber. See https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversionexa

      • getOSBuildNumberImpl

        private static long getOSBuildNumberImpl()
        Invokes Win32 API method GetVersionEx() and returns OSVERSIONINFO.dwBuildNumber. See https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversionexa
      • getHWND

        public static long getHWND​(java.awt.Window window)
        Gets the Windows window handle (HWND) for the given Swing window.

        Note that the underlying Windows window must be already created, otherwise this method returns zero. Use following to ensure this:

        
         if( !window.isDisplayable() )
             window.addNotify();
         
        or invoke this method after packing the window. E.g.
        
         window.pack();
         long hwnd = getHWND( window );
         
      • setWindowCornerPreference

        public static boolean setWindowCornerPreference​(long hwnd,
                                                        int cornerPreference)
        Sets the rounded corner preference for the window. Allowed values are DWMWCP_DEFAULT, DWMWCP_DONOTROUND, DWMWCP_ROUND and DWMWCP_ROUNDSMALL.

        Invokes Win32 API method DwmSetWindowAttribute(DWMWA_WINDOW_CORNER_PREFERENCE). See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute

        Supported since Windows 11 Build 22000.

      • dwmSetWindowAttributeBOOL

        public static boolean dwmSetWindowAttributeBOOL​(long hwnd,
                                                        int attribute,
                                                        boolean value)
        Invokes Win32 API method DwmSetWindowAttribute() with a BOOL attribute value. See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute
        Since:
        3.3
      • dwmSetWindowAttributeDWORD

        public static boolean dwmSetWindowAttributeDWORD​(long hwnd,
                                                         int attribute,
                                                         int value)
        Invokes Win32 API method DwmSetWindowAttribute() with a DWORD attribute value. See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute
        Since:
        3.3
      • dwmSetWindowAttributeCOLORREF

        public static boolean dwmSetWindowAttributeCOLORREF​(long hwnd,
                                                            int attribute,
                                                            java.awt.Color color)
        Invokes Win32 API method DwmSetWindowAttribute() with a COLORREF attribute value. See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute

        Supported since Windows 11 Build 22000.

        Since:
        3.3