Skip to content

Commit

Permalink
Add some DWM attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkwpsv committed Apr 5, 2021
1 parent c260f90 commit 1fceb3f
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 5 deletions.
22 changes: 22 additions & 0 deletions WindowDebugger/Converters/DWM_CLOAKEDToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Lsj.Util.Win32.Enums;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace WindowDebugger.Converters
{
public class DWM_CLOAKEDToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is DWM_CLOAKED)
{
return value.ToString();
}
return DependencyProperty.UnsetValue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}
}
22 changes: 22 additions & 0 deletions WindowDebugger/Converters/RECTToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Lsj.Util.Win32.Structs;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace WindowDebugger.Converters
{
public class RECTToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is RECT rect)
{
return $"({rect.left}, {rect.top}, {rect.right}, {rect.bottom})";
}
return DependencyProperty.UnsetValue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}
}
2 changes: 0 additions & 2 deletions WindowDebugger/Converters/WindowStylesToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Lsj.Util.Win32.Enums;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows;
using System.Windows.Data;

Expand Down
70 changes: 70 additions & 0 deletions WindowDebugger/ViewModels/WindowItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using static Lsj.Util.Win32.ComInterfaces.CLSIDs;
using static Lsj.Util.Win32.ComInterfaces.IIDs;
using static Lsj.Util.Win32.Enums.CLSCTX;
using static Lsj.Util.Win32.Enums.DWMWINDOWATTRIBUTE;

namespace WindowDebugger.ViewModels
{
Expand Down Expand Up @@ -102,6 +103,18 @@ static WindowItem()
private BitmapSource _screenshot;
public BitmapSource Screenshot { get => _screenshot; set => SetField(ref _screenshot, value); }

private bool _dwmNcRenderingEnabled;
public bool DWMNcRenderingEnabled { get => _dwmNcRenderingEnabled; }

private RECT _dwmCaptionButtonBounds;
public RECT DWMCaptionButtonBounds { get => _dwmCaptionButtonBounds; }

private RECT _dwmExtendedFrameBounds;
public RECT DWMExtendedFrameBounds { get => _dwmExtendedFrameBounds; }

private DWM_CLOAKED _dwmCloaked;
public DWM_CLOAKED DWMCloaked { get => _dwmCloaked; }

private bool _isTouchWindow;
public bool IsTouchWindow { get => _isTouchWindow; }

Expand All @@ -113,6 +126,11 @@ private void SetError()
LastError = ErrorMessageExtensions.GetSystemErrorMessageFromCode((uint)Marshal.GetLastWin32Error());
}

private void SetError(HRESULT hresult)
{
LastError = ErrorMessageExtensions.GetSystemErrorMessageFromCode(hresult & 0x0000FFFF);
}

public bool SetForeground()
{
var result = SetForegroundWindow(_windowHandle);
Expand Down Expand Up @@ -374,6 +392,7 @@ public void RefreshItem()
RefreshScreenShot();
RefreshIsTouchWindow();
RefreshVirtualDesktopID();
RefreshDWMAttributes();
}

public void RefreshText()
Expand Down Expand Up @@ -521,6 +540,57 @@ public void RefreshVirtualDesktopID()
}
}

public void RefreshDWMAttributes()
{
if ((Styles & WS_CHILD) != 0)
{
//Child Window will fail.
return;
}
BOOL boolVal = false;
RECT rectVal = new RECT();
DWM_CLOAKED cloakedVal = 0;
var result = Dwmapi.DwmGetWindowAttribute(WindowHandle, DWMWA_NCRENDERING_ENABLED, AsPointer(ref boolVal), SizeOf<BOOL>());
if (result)
{
SetField(ref _dwmNcRenderingEnabled, boolVal, propertyName: nameof(DWMNcRenderingEnabled));
}
else
{
SetError(result);
}

result = Dwmapi.DwmGetWindowAttribute(WindowHandle, DWMWA_CAPTION_BUTTON_BOUNDS, AsPointer(ref rectVal), SizeOf<RECT>());
if (result)
{
SetField(ref _dwmCaptionButtonBounds, rectVal, propertyName: nameof(DWMCaptionButtonBounds));
}
else
{
SetError(result);
}

result = Dwmapi.DwmGetWindowAttribute(WindowHandle, DWMWA_EXTENDED_FRAME_BOUNDS, AsPointer(ref rectVal), SizeOf<RECT>());
if (result)
{
SetField(ref _dwmExtendedFrameBounds, rectVal, propertyName: nameof(DWMExtendedFrameBounds));
}
else
{
SetError(result);
}

result = Dwmapi.DwmGetWindowAttribute(WindowHandle, DWMWA_CLOAKED, AsPointer(ref cloakedVal), SizeOf<DWM_CLOAKED>());
if (result)
{
SetField(ref _dwmCloaked, cloakedVal, propertyName: nameof(DWMCloaked));
}
else
{
SetError(result);
}
}

public override string ToString() => $"0x{WindowHandle.ToString("X8")}{(!Text.IsNullOrEmpty() ? $"({Text})" : "")}";
}
}
27 changes: 24 additions & 3 deletions WindowDebugger/Views/DWMTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<Border Padding="10,10,10,0">
<Grid>
<Grid.Resources>
<converters:RECTToStringConverter x:Key="RECTToStringConverter"/>
<converters:DWM_CLOAKEDToStringConverter x:Key="DWM_CLOAKEDToStringConverter"/>
<Style TargetType="TextBlock">
<Style.Setters>
<Setter Property="VerticalAlignment" Value="Center"/>
Expand Down Expand Up @@ -49,9 +51,28 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0" Content="DwmIsCompositionEnabled" IsChecked="{Binding DwmIsCompositionEnabled, Source={x:Static viewmodels:ViewModel.Instance}, Mode=OneWay}" IsEnabled="False"/>
<Grid Grid.Row="1" IsEnabled="{Binding DwmIsCompositionEnabled, Source={x:Static viewmodels:ViewModel.Instance}, Mode=OneWay}">
<GroupBox Header="">

<Grid Grid.Row="1" IsEnabled="{Binding DwmIsCompositionEnabled, Source={x:Static viewmodels:ViewModel.Instance}, Mode=OneWay}" Margin="0 5">
<GroupBox Header="DWM Attributes">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" MaxHeight="30"/>
<RowDefinition Height="*" MaxHeight="30"/>
<RowDefinition Height="*" MaxHeight="30"/>
<RowDefinition Height="*" MaxHeight="30"/>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="NCRENDERING ENABLED" IsChecked="{Binding DWMNcRenderingEnabled, Mode=OneWay}" IsEnabled="False"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="CAPTION BUTTON BOUNDS"/>
<TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding DWMCaptionButtonBounds, Converter={StaticResource RECTToStringConverter}, Mode=OneWay}" IsReadOnly="True"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="EXTENDED FRAME BOUNDS"/>
<TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding DWMExtendedFrameBounds, Converter={StaticResource RECTToStringConverter}, Mode=OneWay}" IsReadOnly="True"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="CLOAKED"/>
<TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding DWMCloaked, Converter={StaticResource DWM_CLOAKEDToStringConverter}, Mode=OneWay}" IsReadOnly="True"/>
</Grid>
</GroupBox>
</Grid>
</Grid>
Expand Down

0 comments on commit 1fceb3f

Please sign in to comment.