diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs
index 058b2dcb60..4364792cf5 100644
--- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs
+++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs
@@ -83,6 +83,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
///
public MarkdownPreviewHandlerControl()
{
+ this.SetBackgroundColor(Settings.BackgroundColor);
}
///
@@ -121,11 +122,12 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
_infoBarDisplayed = true;
}
- string markdownHTML = FilePreviewCommon.MarkdownHelper.MarkdownHtml(fileText, Common.UI.ThemeManager.GetWindowsBaseColor().ToLowerInvariant(), filePath, ImagesBlockedCallBack);
+ string markdownHTML = FilePreviewCommon.MarkdownHelper.MarkdownHtml(fileText, Settings.GetTheme(), filePath, ImagesBlockedCallBack);
_browser = new WebView2()
{
Dock = DockStyle.Fill,
+ DefaultBackgroundColor = Color.Transparent,
};
var webView2Options = new CoreWebView2EnvironmentOptions("--block-new-web-contents");
diff --git a/src/modules/previewpane/MarkdownPreviewHandler/Settings.cs b/src/modules/previewpane/MarkdownPreviewHandler/Settings.cs
new file mode 100644
index 0000000000..a69808d2ed
--- /dev/null
+++ b/src/modules/previewpane/MarkdownPreviewHandler/Settings.cs
@@ -0,0 +1,44 @@
+// Copyright (c) Microsoft Corporation
+// The Microsoft Corporation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Microsoft.PowerToys.PreviewHandler.Markdown
+{
+ internal sealed class Settings
+ {
+ ///
+ /// Gets the color of the window background.
+ /// Even though this is not a setting yet, it's retrieved from a "Settings" class to be aligned with other preview handlers that contain this setting.
+ /// It's possible it can be converted into a setting in the future.
+ ///
+ public static Color BackgroundColor
+ {
+ get
+ {
+ if (GetTheme() == "dark")
+ {
+ return Color.FromArgb(30, 30, 30); // #1e1e1e
+ }
+ else
+ {
+ return Color.White;
+ }
+ }
+ }
+
+ ///
+ /// Returns the theme.
+ ///
+ /// Theme that should be used.
+ public static string GetTheme()
+ {
+ return Common.UI.ThemeManager.GetWindowsBaseColor().ToLowerInvariant();
+ }
+ }
+}
diff --git a/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandler.cpp b/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandler.cpp
index 3a0210ff3a..29e48e192a 100644
--- a/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandler.cpp
+++ b/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandler.cpp
@@ -1,6 +1,7 @@
#include "pch.h"
#include "MarkdownPreviewHandler.h"
#include "Generated Files/resource.h"
+#include "../powerpreview/powerpreviewConstants.h"
#include
#include
@@ -10,6 +11,7 @@
#include
#include
#include
+#include
extern HINSTANCE g_hInst;
extern long g_cDllRef;
@@ -203,6 +205,8 @@ IFACEMETHODIMP MarkdownPreviewHandler::Unload()
IFACEMETHODIMP MarkdownPreviewHandler::SetBackgroundColor(COLORREF color)
{
+ HBRUSH brush = CreateSolidBrush(WindowsColors::is_dark_mode() ? powerpreviewConstants::DARK_THEME_COLOR : powerpreviewConstants::LIGHT_THEME_COLOR);
+ SetClassLongPtr(m_hwndParent, GCLP_HBRBACKGROUND, reinterpret_cast(brush));
return S_OK;
}
diff --git a/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandlerCpp.vcxproj b/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandlerCpp.vcxproj
index 6866ce4f77..2264a54adb 100644
--- a/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandlerCpp.vcxproj
+++ b/src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandlerCpp.vcxproj
@@ -76,7 +76,7 @@
true
false
GlobalExportFunctions.def
- Shlwapi.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)
+ Shlwapi.lib;dwmapi.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)
@@ -109,6 +109,9 @@
{6955446d-23f7-4023-9bb3-8657f904af99}
+
+ {98537082-0fdb-40de-abd8-0dc5a4269bab}
+
diff --git a/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs b/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs
index d8ba4640a3..2be1b0117a 100644
--- a/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs
+++ b/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs
@@ -77,6 +77,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
///
private string _base64FileCode;
+ public MonacoPreviewHandlerControl()
+ {
+ this.SetBackground();
+ }
+
[STAThread]
public override void DoPreview(T dataSource)
{
@@ -95,14 +100,12 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
base.DoPreview(dataSource);
- // Sets background color
- SetBackground();
-
// Starts loading screen
InitializeLoadingScreen();
// New webview2 element
_webView = new WebView2();
+ _webView.DefaultBackgroundColor = Color.Transparent;
// Checks if dataSource is a string
if (!(dataSource is string filePath))
diff --git a/src/modules/previewpane/MonacoPreviewHandler/Settings.cs b/src/modules/previewpane/MonacoPreviewHandler/Settings.cs
index 6bc7a11e76..dccfc2a5b4 100644
--- a/src/modules/previewpane/MonacoPreviewHandler/Settings.cs
+++ b/src/modules/previewpane/MonacoPreviewHandler/Settings.cs
@@ -86,7 +86,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
{
if (GetTheme() == "dark")
{
- return System.Drawing.ColorTranslator.FromHtml("#1e1e1e");
+ return Color.FromArgb(30, 30, 30); // #1e1e1e
}
else
{
diff --git a/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandler.cpp b/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandler.cpp
index 740769c5dd..99afc45d0a 100644
--- a/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandler.cpp
+++ b/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandler.cpp
@@ -1,5 +1,6 @@
#include "pch.h"
#include "MonacoPreviewHandler.h"
+#include "../powerpreview/powerpreviewConstants.h"
#include
#include
@@ -9,6 +10,7 @@
#include
#include
#include
+#include
extern HINSTANCE g_hInst;
extern long g_cDllRef;
@@ -202,6 +204,8 @@ IFACEMETHODIMP MonacoPreviewHandler::Unload()
IFACEMETHODIMP MonacoPreviewHandler::SetBackgroundColor(COLORREF color)
{
+ HBRUSH brush = CreateSolidBrush(WindowsColors::is_dark_mode() ? powerpreviewConstants::DARK_THEME_COLOR : powerpreviewConstants::LIGHT_THEME_COLOR);
+ SetClassLongPtr(m_hwndParent, GCLP_HBRBACKGROUND, reinterpret_cast(brush));
return S_OK;
}
diff --git a/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandlerCpp.vcxproj b/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandlerCpp.vcxproj
index 41098d30e4..4c32290011 100644
--- a/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandlerCpp.vcxproj
+++ b/src/modules/previewpane/MonacoPreviewHandlerCpp/MonacoPreviewHandlerCpp.vcxproj
@@ -72,7 +72,7 @@
true
false
GlobalExportFunctions.def
- Shlwapi.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)
+ Shlwapi.lib;dwmapi.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)
@@ -103,6 +103,9 @@
{6955446d-23f7-4023-9bb3-8657f904af99}
+
+ {98537082-0fdb-40de-abd8-0dc5a4269bab}
+
diff --git a/src/modules/previewpane/SvgPreviewHandler/Settings.cs b/src/modules/previewpane/SvgPreviewHandler/Settings.cs
index ee307e1003..d305bf26dc 100644
--- a/src/modules/previewpane/SvgPreviewHandler/Settings.cs
+++ b/src/modules/previewpane/SvgPreviewHandler/Settings.cs
@@ -47,7 +47,7 @@ namespace SvgPreviewHandler
{
if (Common.UI.ThemeManager.GetWindowsBaseColor().ToLowerInvariant() == "dark")
{
- return ColorTranslator.FromHtml("#1e1e1e");
+ return Color.FromArgb(30, 30, 30); // #1e1e1e
}
else
{
diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs
index 2cb2561729..1b89137654 100644
--- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs
+++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs
@@ -20,6 +20,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
///
public class SvgPreviewControl : FormHandlerControl
{
+ ///
+ /// Settings class
+ ///
+ private readonly SvgPreviewHandler.Settings _settings = new();
+
///
/// Generator for the actual preview file
///
@@ -78,6 +83,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
private string _webView2UserDataFolder = System.Environment.GetEnvironmentVariable("USERPROFILE") +
"\\AppData\\LocalLow\\Microsoft\\PowerToys\\SvgPreview-Temp";
+ public SvgPreviewControl()
+ {
+ this.SetBackgroundColor(_settings.ThemeColor);
+ }
+
///
/// Start the preview on the Control.
///
@@ -199,6 +209,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
private void AddWebViewControl(string svgData)
{
_browser = new WebView2();
+ _browser.DefaultBackgroundColor = Color.Transparent;
_browser.Dock = DockStyle.Fill;
// Prevent new windows from being opened.
diff --git a/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandler.cpp b/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandler.cpp
index 21841329a0..ba81c13e1d 100644
--- a/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandler.cpp
+++ b/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandler.cpp
@@ -1,5 +1,6 @@
#include "pch.h"
#include "SvgPreviewHandler.h"
+#include "../powerpreview/powerpreviewConstants.h"
#include
#include
@@ -9,6 +10,7 @@
#include
#include
#include
+#include
extern HINSTANCE g_hInst;
extern long g_cDllRef;
@@ -198,6 +200,8 @@ IFACEMETHODIMP SvgPreviewHandler::Unload()
IFACEMETHODIMP SvgPreviewHandler::SetBackgroundColor(COLORREF color)
{
+ HBRUSH brush = CreateSolidBrush(WindowsColors::is_dark_mode() ? powerpreviewConstants::DARK_THEME_COLOR : powerpreviewConstants::LIGHT_THEME_COLOR);
+ SetClassLongPtr(m_hwndParent, GCLP_HBRBACKGROUND, reinterpret_cast(brush));
return S_OK;
}
diff --git a/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandlerCpp.vcxproj b/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandlerCpp.vcxproj
index 0bf8d3967f..6e90f72f61 100644
--- a/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandlerCpp.vcxproj
+++ b/src/modules/previewpane/SvgPreviewHandlerCpp/SvgPreviewHandlerCpp.vcxproj
@@ -72,7 +72,7 @@
true
false
GlobalExportFunctions.def
- Shlwapi.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)
+ Shlwapi.lib;dwmapi.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)
@@ -103,6 +103,9 @@
{6955446d-23f7-4023-9bb3-8657f904af99}
+
+ {98537082-0fdb-40de-abd8-0dc5a4269bab}
+
diff --git a/src/modules/previewpane/powerpreview/powerpreviewConstants.h b/src/modules/previewpane/powerpreview/powerpreviewConstants.h
index 3f1c2b58a7..0380df6c7a 100644
--- a/src/modules/previewpane/powerpreview/powerpreviewConstants.h
+++ b/src/modules/previewpane/powerpreview/powerpreviewConstants.h
@@ -5,4 +5,10 @@ namespace powerpreviewConstants
{
// Name of the powertoy module.
inline const std::wstring ModuleKey = L"File Explorer";
-}
\ No newline at end of file
+
+ // Dark theme background color
+ const COLORREF DARK_THEME_COLOR = RGB(0x1e, 0x1e, 0x1e);
+
+ // Light theme background color
+ const COLORREF LIGHT_THEME_COLOR = RGB(0xff, 0xff, 0xff);
+}