@@ -848,6 +848,26 @@ HL_PRIM int HL_NAME(get_screen_height)() {
848848 return GetSystemMetrics (SM_CYSCREEN );
849849}
850850
851+ HL_PRIM void HL_NAME (win_set_dark_mode )( dx_window * wnd , bool enabled ) {
852+ // Load dynamically the required function and fail silently if they are not available
853+ // (which could be true for older Windows 10 versions and before)
854+ HMODULE dwmapi = LoadLibraryA ("Dwmapi.dll" );
855+
856+ if (dwmapi == NULL )
857+ return ;
858+
859+ typedef HRESULT (* DwmSetWindowAttributePTR )(HWND , DWORD , LPCVOID , DWORD );
860+ DwmSetWindowAttributePTR DwmSetWindowAttribute =
861+ (DwmSetWindowAttributePTR )GetProcAddress (dwmapi , "DwmSetWindowAttribute" );
862+
863+ if (DwmSetWindowAttribute == NULL )
864+ return ;
865+
866+ int DWMWA_USE_IMMERSIVE_DARK_MODE = 20 ;
867+ BOOL dark_mode = enabled ;
868+ DwmSetWindowAttribute (wnd , DWMWA_USE_IMMERSIVE_DARK_MODE , & dark_mode , sizeof (dark_mode ));
869+ }
870+
851871typedef struct {
852872 int idx ;
853873 varray * arr ;
@@ -970,6 +990,7 @@ DEFINE_PRIM(_DYN, win_get_current_display_setting, _BYTES _BOOL);
970990DEFINE_PRIM (_I32 , win_change_display_setting , _BYTES _DYN );
971991DEFINE_PRIM (_ARR , win_get_monitors , _NO_ARG );
972992DEFINE_PRIM (_BYTES , win_get_monitor_from_window , TWIN );
993+ DEFINE_PRIM (_VOID , win_set_dark_mode , TWIN _BOOL );
973994
974995DEFINE_PRIM (_I32 , get_screen_width , _NO_ARG );
975996DEFINE_PRIM (_I32 , get_screen_height , _NO_ARG );
0 commit comments