Class FlatNativeWindowsLibrary

java.lang.Object
com.formdev.flatlaf.ui.FlatNativeWindowsLibrary

public class FlatNativeWindowsLibrary extends 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
     
    static final Color
     
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
     
    static final int
     
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    private static long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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, 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(Window window)
    Gets the Windows window handle (HWND) for the given Swing window.
    static long
    Gets the Windows operating system build number.
    private static long
    Invokes Win32 API method GetVersionEx() and returns OSVERSIONINFO.dwBuildNumber.
    static boolean
    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 Details

    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • DWMWA_COLOR_DEFAULT

      public static final int DWMWA_COLOR_DEFAULT
      Since:
      3.3
      See Also:
    • DWMWA_COLOR_NONE

      public static final int DWMWA_COLOR_NONE
      Since:
      3.3
      See Also:
    • COLOR_NONE

      public static final Color COLOR_NONE
      Since:
      3.3
  • Constructor Details

    • FlatNativeWindowsLibrary

      public FlatNativeWindowsLibrary()
  • Method Details

    • 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(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, 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