Преглед изворни кода

Bug 1920: Use dark window title for the main window in the dark mode on Windows 10 2004

https://winscp.net/tracker/1920
(cherry picked from commit e7e138fd52de479891dfab9be82a2b5acb28eb3f)

Source commit: c0421d5ae51ecacf7774414b72d32eb7b619e404
Martin Prikryl пре 5 година
родитељ
комит
e2c08d76d3
3 измењених фајлова са 30 додато и 11 уклоњено
  1. 22 11
      source/core/Common.cpp
  2. 1 0
      source/core/Common.h
  3. 7 0
      source/forms/CustomScpExplorer.cpp

+ 22 - 11
source/core/Common.cpp

@@ -2980,6 +2980,28 @@ bool __fastcall IsWin10()
   return CheckWin32Version(10, 0);
 }
 //---------------------------------------------------------------------------
+static OSVERSIONINFO __fastcall GetWindowsVersion()
+{
+  OSVERSIONINFO Result;
+  memset(&Result, 0, sizeof(Result));
+  Result.dwOSVersionInfoSize = sizeof(Result);
+  // Cannot use the VCL Win32MajorVersion+Win32MinorVersion+Win32BuildNumber as
+  // on Windows 10 due to some hacking in InitPlatformId, the Win32BuildNumber is lost
+  GetVersionEx(&Result);
+  return Result;
+}
+//---------------------------------------------------------------------------
+bool __fastcall IsWin10Build(unsigned int BuildNumber)
+{
+  // It might be enough to check the dwBuildNumber, as we do in TWinConfiguration::IsDDExtBroken()
+  OSVERSIONINFO OSVersionInfo = GetWindowsVersion();
+  return
+    (OSVersionInfo.dwMajorVersion > 10) ||
+    ((OSVersionInfo.dwMajorVersion == 10) && (OSVersionInfo.dwMinorVersion > 0)) ||
+    ((OSVersionInfo.dwMajorVersion == 10) && (OSVersionInfo.dwMinorVersion == 0) &&
+     (OSVersionInfo.dwBuildNumber >= BuildNumber));
+}
+//---------------------------------------------------------------------------
 bool __fastcall IsWine()
 {
   HMODULE NtDll = GetModuleHandle(L"ntdll.dll");
@@ -3065,17 +3087,6 @@ UnicodeString __fastcall WindowsProductName()
   return Result;
 }
 //---------------------------------------------------------------------------
-static OSVERSIONINFO __fastcall GetWindowsVersion()
-{
-  OSVERSIONINFO Result;
-  memset(&Result, 0, sizeof(Result));
-  Result.dwOSVersionInfoSize = sizeof(Result);
-  // Cannot use the VCL Win32MajorVersion+Win32MinorVersion+Win32BuildNumber as
-  // on Windows 10 due to some hacking in InitPlatformId, the Win32BuildNumber is lost
-  GetVersionEx(&Result);
-  return Result;
-}
-//---------------------------------------------------------------------------
 int __fastcall GetWindowsBuild()
 {
   return GetWindowsVersion().dwBuildNumber;

+ 1 - 0
source/core/Common.h

@@ -138,6 +138,7 @@ bool __fastcall IsWinVista();
 bool __fastcall IsWin7();
 bool __fastcall IsWin8();
 bool __fastcall IsWin10();
+bool __fastcall IsWin10Build(unsigned int BuildNumber);
 bool __fastcall IsWine();
 bool __fastcall IsUWP();
 TLibModule * __fastcall FindModule(void * Instance);

+ 7 - 0
source/forms/CustomScpExplorer.cpp

@@ -9696,6 +9696,13 @@ void __fastcall TCustomScpExplorerForm::CreateWnd()
 
   // win32-darkmode calls AllowDarkModeForWindow(this, true) here, but it does not seem to have any effect
 
+  if (IsWin10Build(2004))
+  {
+    BOOL DarkMode = TRUE;
+    const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
+    DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, &DarkMode, sizeof(DarkMode));
+  }
+
   if (FSessionsDragDropFilesEx == NULL)
   {
     FSessionsDragDropFilesEx = CreateDragDropFilesEx();