It is currently Fri Nov 27, 2020 3:06 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Windows 'Dark' mode.
PostPosted: Mon Sep 28, 2020 6:20 am 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3164
Location: United Kingdom
Apparently, the latest Windows has a Win32 API now for 'Dark' mode:

Could support for this be added to PureBasic?

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Last edited by DoubleDutch on Mon Sep 28, 2020 6:57 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Windows 'Dark' mode.
PostPosted: Mon Sep 28, 2020 6:56 am 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3164
Location: United Kingdom
It looks like they have settled on a new win32 API call called 'setWindowCompositionAttribute'.

Here is what Microsoft' bash terminal uses to use dark mode:

Code:
diff --git a/src/winmain.c b/src/winmain.c
index 0672f94..4544a12 100644
--- a/src/winmain.c
+++ b/src/winmain.c
@@ -186,7 +186,13 @@ trace_winsize(char * tag)
 static HRESULT (WINAPI * pDwmIsCompositionEnabled)(BOOL *) = 0;
 static HRESULT (WINAPI * pDwmExtendFrameIntoClientArea)(HWND, const MARGINS *) = 0;
 static HRESULT (WINAPI * pDwmEnableBlurBehindWindow)(HWND, void *) = 0;
+static HRESULT (WINAPI * pDwmSetWindowAttribute)(HWND, DWORD, LPCVOID, DWORD) = 0;
+
 static HRESULT (WINAPI * pSetWindowCompositionAttribute)(HWND, void *) = 0;
+static BOOL (WINAPI * pSystemParametersInfoA)(UINT, UINT, PVOID, UINT) = 0;
+
+static BOOLEAN (WINAPI * pShouldAppsUseDarkMode)(void) = 0;
+static HRESULT (WINAPI * pSetWindowTheme)(HWND, const wchar_t *, const wchar_t *) = 0;
 
 // Helper for loading a system library. Using LoadLibrary() directly is insecure
 // because Windows might be searching the current working directory first.
@@ -209,6 +215,8 @@ load_dwm_funcs(void)
 {
   HMODULE dwm = load_sys_library("dwmapi.dll");
   HMODULE user32 = load_sys_library("user32.dll");
+  HMODULE uxtheme = load_sys_library("uxtheme.dll");
+
   if (dwm) {
     pDwmIsCompositionEnabled =
       (void *)GetProcAddress(dwm, "DwmIsCompositionEnabled");
@@ -216,10 +224,20 @@ load_dwm_funcs(void)
       (void *)GetProcAddress(dwm, "DwmExtendFrameIntoClientArea");
     pDwmEnableBlurBehindWindow =
       (void *)GetProcAddress(dwm, "DwmEnableBlurBehindWindow");
+    pDwmSetWindowAttribute =
+      (void *)GetProcAddress(dwm, "DwmSetWindowAttribute");
   }
   if (user32) {
     pSetWindowCompositionAttribute =
       (void *)GetProcAddress(user32, "SetWindowCompositionAttribute");
+    pSystemParametersInfoA =
+      (void *)GetProcAddress(user32, "SystemParametersInfoA");
+  }
+  if (uxtheme) {
+    pShouldAppsUseDarkMode =
+      (void *)GetProcAddress(uxtheme, MAKEINTRESOURCEA(132)); /* ordinal */
+    pSetWindowTheme =
+      (void *)GetProcAddress(uxtheme, "SetWindowTheme");
   }
 }
 
@@ -4782,6 +4800,26 @@ main(int argc, char *argv[])
                         x, y, width, height,
                         null, null, inst, null);
   trace_winsize("createwindow");
+
+  // Dark mode support
+  if (pShouldAppsUseDarkMode) {
+    HIGHCONTRAST hc = { 0 };
+    hc.cbSize = sizeof hc;
+    pSystemParametersInfoA(SPI_GETHIGHCONTRAST, sizeof hc, &hc, 0);
+
+    if (!(hc.dwFlags & HCF_HIGHCONTRASTON) && pShouldAppsUseDarkMode()) {
+      pSetWindowTheme(wnd, L"DarkMode_Explorer", NULL);
+      BOOL dark = 1;
+
+#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
+#define DWMWA_USE_IMMERSIVE_DARK_MODE 19
+#endif
+
+      pDwmSetWindowAttribute(wnd, DWMWA_USE_IMMERSIVE_DARK_MODE,
+                             &dark, sizeof dark);
+    }
+  }
+
   // Workaround for failing title parameter:
   if (pEnableNonClientDpiScaling)
     SetWindowTextW(wnd, wtitle);

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject: Re: Windows 'Dark' mode.
PostPosted: Mon Sep 28, 2020 7:58 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 769
Location: Linz, Austria
https://stackoverflow.com/questions/53501268/win10-dark-theme-how-to-use-in-winapi

https://github.com/ysc3839/win32-darkmode

_________________
Et cetera is my worst enemy


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye