Skip to content

Commit

Permalink
Add DisplayAffinity.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkwpsv committed Mar 28, 2022
1 parent 54b02da commit 42e53db
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Lsj.Util.Win32.Enums;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Data;
using WindowDebugger.ViewModels;

namespace WindowDebugger.Converters
{
public class WindowItemToCanSetDisplayAffinityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value is WindowItem item &&
item.ProcessID == Process.GetCurrentProcess().Id &&
(item.Styles & WindowStyles.WS_CHILD) == 0;

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
}
21 changes: 20 additions & 1 deletion WindowDebugger/ViewModels/WindowItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Lsj.Util.Win32.Structs;
using Lsj.Util.WPF;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
Expand Down Expand Up @@ -89,7 +90,25 @@ public ClassStyles ClassStyles

public int Height { get => _window.Rect.bottom - _window.Rect.top; }

public ShowWindowCommands WindowShowStates { get => _window.ShowStates; set => _window.ShowStates = value; }
public ShowWindowCommands WindowShowStates
{
get => _window.ShowStates;
set
{
_window.ShowStates = value;
OnPropertyChanged();
}
}

public WindowDisplayAffinities WindowDisplayAffinity
{
get => ProcessID == Process.GetCurrentProcess().Id && (Styles & WindowStyles.WS_CHILD) == 0 ? _window.DisplayAffinity : default;
set
{
_window.DisplayAffinity = value;
OnPropertyChanged();
}
}

public DPI_AWARENESS DpiAwareness => GetWithDefaultValueWhenException(() => _window.DpiAwareness, DPI_AWARENESS_UNAWARE);

Expand Down
28 changes: 18 additions & 10 deletions WindowDebugger/Views/Tabs/WindowInfoTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
<FrameworkElement.Resources>
<utilconverters:IntPtrToHexConverter x:Key="IntPtrToHexConverter"/>
<converters:ParentWindowHandleToCanUpdateOwnerConverter x:Key="ParentWindowHandleToCanUpdateOwnerConverter"/>
<converters:WindowItemToCanSetDisplayAffinityConverter x:Key="WindowItemToCanSetDisplayAffinityConverter"/>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</FrameworkElement.Resources>
<StackPanel>
Expand Down Expand Up @@ -85,6 +86,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<FrameworkElement.Resources>
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
Expand Down Expand Up @@ -127,15 +129,21 @@
<Button Grid.Row="1" Grid.Column="2" Click="UpdateRect" Content="Change"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="WindowShowStates"/>
<ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" x:Name="ComboBoxWindowShowStates"
SelectedValue="{Binding WindowShowStates, Mode=TwoWay}"
ItemsSource="{markupExtensions:EnumToItemSource {x:Type win32Enums:ShowWindowCommands}}"
DisplayMemberPath="DisplayName" SelectedValuePath="Value"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Parent Window"/>
<TextBox Grid.Row="3" Grid.Column="1" x:Name="TextBoxParentWindowHandle" Text="{Binding ParentWindowHandle, Converter={StaticResource IntPtrToHexConverter}, UpdateSourceTrigger=Explicit}"/>
<Button Grid.Row="3" Grid.Column="2" Click="UpdateParentWindowHandle" Content="Change"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Owner Window"/>
<TextBox Grid.Row="4" Grid.Column="1" x:Name="TextBoxOwnerWindowHandle" Text="{Binding OwnerWindowHandle, Converter={StaticResource IntPtrToHexConverter}, UpdateSourceTrigger=Explicit}"/>
<Button Grid.Row="4" Grid.Column="2" Click="UpdateOwnerWindowHandle" Content="Change"
SelectedValue="{Binding WindowShowStates, Mode=TwoWay}"
ItemsSource="{markupExtensions:EnumToItemSource {x:Type win32Enums:ShowWindowCommands}}"
DisplayMemberPath="DisplayName" SelectedValuePath="Value"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="WindowShowStates"/>
<ComboBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" x:Name="ComboBoxWindowDisplayAffinities"
SelectedValue="{Binding WindowDisplayAffinity, Mode=TwoWay}"
ItemsSource="{markupExtensions:EnumToItemSource {x:Type win32Enums:WindowDisplayAffinities}}"
IsEnabled="{Binding Converter={StaticResource WindowItemToCanSetDisplayAffinityConverter}}"
DisplayMemberPath="DisplayName" SelectedValuePath="Value"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Parent Window"/>
<TextBox Grid.Row="4" Grid.Column="1" x:Name="TextBoxParentWindowHandle" Text="{Binding ParentWindowHandle, Converter={StaticResource IntPtrToHexConverter}, UpdateSourceTrigger=Explicit}"/>
<Button Grid.Row="4" Grid.Column="2" Click="UpdateParentWindowHandle" Content="Change"/>
<TextBlock Grid.Row="5" Grid.Column="0" Text="Owner Window"/>
<TextBox Grid.Row="5" Grid.Column="1" x:Name="TextBoxOwnerWindowHandle" Text="{Binding OwnerWindowHandle, Converter={StaticResource IntPtrToHexConverter}, UpdateSourceTrigger=Explicit}"/>
<Button Grid.Row="5" Grid.Column="2" Click="UpdateOwnerWindowHandle" Content="Change"
IsEnabled="{Binding ParentWindowHandle,Converter={StaticResource ParentWindowHandleToCanUpdateOwnerConverter}}"/>
</Grid>
</StackPanel>
Expand Down
4 changes: 2 additions & 2 deletions WindowDebugger/WindowDebugger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

<ItemGroup>
<PackageReference Include="Lsj.Util.JSON" Version="6.0.0" />
<PackageReference Include="Lsj.Util.Win32" Version="6.1.0" />
<PackageReference Include="Lsj.Util.Win32" Version="6.2.0" />
<PackageReference Include="Lsj.Util.WPF" Version="6.0.0" />
<PackageReference Include="Lsj.Util.Win32.NativeUI" Version="6.0.2" />
<PackageReference Include="Lsj.Util.Win32.NativeUI" Version="6.0.4-debug2058" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="WPF-UI" Version="1.2.2" />
</ItemGroup>
Expand Down

0 comments on commit 42e53db

Please sign in to comment.