Remove AllowsTransparency which is buggy in XP and poor performance.

This commit is contained in:
qianlifeng
2014-03-15 23:42:23 +08:00
parent f0b728a71b
commit a7b3ef34d8
8 changed files with 117 additions and 12 deletions

View File

@@ -0,0 +1,73 @@
using System;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace Wox.Helper
{
public class DwmDropShadow
{
[DllImport("dwmapi.dll", PreserveSig = true)]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);
/// <summary>
/// Drops a standard shadow to a WPF Window, even if the window isborderless. Only works with DWM (Vista and Seven).
/// This method is much more efficient than setting AllowsTransparency to true and using the DropShadow effect,
/// as AllowsTransparency involves a huge permormance issue (hardware acceleration is turned off for all the window).
/// </summary>
/// <param name="window">Window to which the shadow will be applied</param>
public static void DropShadowToWindow(Window window)
{
if (!DropShadow(window))
{
window.SourceInitialized += new EventHandler(window_SourceInitialized);
}
}
private static void window_SourceInitialized(object sender, EventArgs e) //fixed typo
{
Window window = (Window)sender;
DropShadow(window);
window.SourceInitialized -= new EventHandler(window_SourceInitialized);
}
/// <summary>
/// The actual method that makes API calls to drop the shadow to the window
/// </summary>
/// <param name="window">Window to which the shadow will be applied</param>
/// <returns>True if the method succeeded, false if not</returns>
private static bool DropShadow(Window window)
{
try
{
WindowInteropHelper helper = new WindowInteropHelper(window);
int val = 2;
int ret1 = DwmSetWindowAttribute(helper.Handle, 2, ref val, 4);
if (ret1 == 0)
{
Margins m = new Margins { Bottom = 0, Left = 0, Right = 0, Top = 0 };
int ret2 = DwmExtendFrameIntoClientArea(helper.Handle, ref m);
return ret2 == 0;
}
else
{
return false;
}
}
catch (Exception ex)
{
// Probably dwmapi.dll not found (incompatible OS)
return false;
}
}
}
}

View File

@@ -9,8 +9,6 @@
WindowStyle="None"
WindowStartupLocation="Manual"
ShowInTaskbar="False"
AllowsTransparency="True"
Background="{x:Null}"
Style="{DynamicResource WindowStyle}"
Icon="Images\app.png"
>

View File

@@ -46,6 +46,7 @@ namespace Wox
InitializeComponent();
Initialized = true;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
progressBar.ToolTip = toolTip;
@@ -57,9 +58,9 @@ namespace Wox
{
SetTheme(CommonStorage.Instance.UserSetting.Theme);
}
catch (IOException)
catch (Exception)
{
SetTheme(CommonStorage.Instance.UserSetting.Theme = "Default");
SetTheme(CommonStorage.Instance.UserSetting.Theme = "Dark");
}
SetHotkey(CommonStorage.Instance.UserSetting.Hotkey, OnHotkey);
@@ -75,6 +76,8 @@ namespace Wox
Plugins.Init();
InitProgressbarAnimation();
//only works for win7+
DwmDropShadow.DropShadowToWindow(this);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

View File

@@ -9,8 +9,6 @@
</Style>
<Style x:Key="WindowBorderStyle" BasedOn="{StaticResource BaseWindowBorderStyle}" TargetType="{x:Type Border}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="CornerRadius" Value="5" />
</Style>
<Style x:Key="WindowStyle" BasedOn="{StaticResource BaseWindowStyle}" TargetType="{x:Type Window}">

View File

@@ -13,14 +13,14 @@
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
</Style>
<Style x:Key="BaseWindowBorderStyle" TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="10" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Background" Value="#424242"></Setter>
<Setter Property="Padding" Value="8 10 8 8" />
</Style>
<Style x:Key="BaseWindowStyle" TargetType="{x:Type Window}">
<Setter Property="Height" Value="80" />
<Setter Property="Width" Value="500" />
<Setter Property="Background" Value="#424242" />
</Style>
<Style x:Key="BasePendingLineStyle" TargetType="{x:Type Line}">

View File

@@ -10,13 +10,11 @@
<Setter Property="Foreground" Value="#000000" />
</Style>
<Style x:Key="WindowBorderStyle" BasedOn="{StaticResource BaseWindowBorderStyle}" TargetType="{x:Type Border}">
<Setter Property="Background" Value="#FFFFFF"></Setter>
<Setter Property="CornerRadius" Value="8" />
<Setter Property="BorderBrush" Value="#AAAAAA" />
<Setter Property="BorderThickness" Value="10" />
<Setter Property="BorderThickness" Value="5" />
<Setter Property="Background" Value="#ffffff"></Setter>
</Style>
<Style x:Key="WindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource BaseWindowStyle}" >
<Setter Property="Width" Value="520"></Setter>
</Style>
<Style x:Key="PendingLineStyle" BasedOn="{StaticResource BasePendingLineStyle}" TargetType="{x:Type Line}" >
</Style>

30
Wox/Themes/Pink.xaml Normal file
View File

@@ -0,0 +1,30 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Default.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="#1f1d1f"/>
<Setter Property="Foreground" Value="#cc1081" />
</Style>
<Style x:Key="WindowBorderStyle" BasedOn="{StaticResource BaseWindowBorderStyle}" TargetType="{x:Type Border}">
<Setter Property="Background" Value="#1f1d1f"></Setter>
</Style>
<Style x:Key="WindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource BaseWindowStyle}" >
</Style>
<Style x:Key="PendingLineStyle" BasedOn="{StaticResource BasePendingLineStyle}" TargetType="{x:Type Line}" ></Style>
<Style x:Key="ItemTitleStyle" BasedOn="{StaticResource BaseItemTitleStyle}" TargetType="{x:Type TextBlock}" >
<Setter Property="Foreground" Value="#f5f5f5"></Setter>
</Style>
<Style x:Key="ItemSubTitleStyle" BasedOn="{StaticResource BaseItemSubTitleStyle}" TargetType="{x:Type TextBlock}" >
<Setter Property="Foreground" Value="#c2c2c2"></Setter>
</Style>
<Style x:Key="ItemTitleSelectedStyle" BasedOn="{StaticResource BaseItemTitleSelectedStyle}" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#f5f5f5" />
</Style>
<Style x:Key="ItemSubTitleSelectedStyle" BasedOn="{StaticResource BaseItemSubTitleSelectedStyle}" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#c2c2c2" />
</Style>
<Color x:Key="ItemSelectedBackgroundColor">#cc1081</Color>
<Style x:Key="ThumbStyle" BasedOn="{StaticResource BaseThumbStyle}" TargetType="{x:Type Thumb}"></Style>
<Style x:Key="ScrollBarStyle" BasedOn="{StaticResource BaseScrollBarStyle}" TargetType="{x:Type ScrollBar}"></Style>
</ResourceDictionary>

View File

@@ -129,6 +129,7 @@
<DependentUpon>CustomPluginHotkeySetting.xaml</DependentUpon>
</Compile>
<Compile Include="DispatcherExtensions.cs" />
<Compile Include="Helper\DWMDropShadow.cs" />
<Compile Include="Helper\Log.cs" />
<Compile Include="Helper\PluginInstaller.cs" />
<Compile Include="Helper\WoxException.cs" />
@@ -200,6 +201,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\Pink.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="WebSearchSetting.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>