Skip to content

Commit

Permalink
fix screen count bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lsylusiyao committed Jun 23, 2020
1 parent 287dcb4 commit 727597e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
18 changes: 2 additions & 16 deletions ScreenRotateForWin10/Display.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public static bool Rotate(uint DisplayNumber, Orientations Orientation)
return result;
}

public static void ResetAllRotations()
public static void ResetAllRotations(int screenCount = default)
{
try
{
uint i = 0;
while (++i <= GetScreenCount()) // make exception less
while (++i <= (screenCount == default ? 64 : screenCount)) // make exception less
{
Rotate(i, Orientations.DEGREES_CW_0);
}
Expand All @@ -88,20 +88,6 @@ public static void ResetAllRotations()
// Everything is fine, just reached the last display
}
}

/// <summary>
/// Get the number of screens
/// </summary>
/// <returns>screen count</returns>
public static uint GetScreenCount()
{
DISPLAY_DEVICE d = new DISPLAY_DEVICE();
d.cb = Marshal.SizeOf(d);

uint result = 0;
while (!APIWrapper.EnumDisplayDevices(null, ++result - 1, ref d, 0)) { }
return result;
}
}

}
2 changes: 1 addition & 1 deletion ScreenRotateForWin10/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<StackPanel Orientation="Horizontal" Height="30" VerticalAlignment="Top" Margin="0,0,-0.4,0">
<Label Content="要旋转的屏幕:" FontSize="16" FontWeight="Bold"/>
<!--Content="Screen to Rotate"-->
<ComboBox x:Name="choiceComboBox" SelectedIndex="0" Width="100" FontSize="16" ItemsSource="{Binding ScreenNums}"/>
<ComboBox x:Name="choiceComboBox" Width="100" FontSize="16" ItemsSource="{Binding ScreenNums}"/>
</StackPanel>
<UniformGrid Rows="3" Columns="3" Margin="0,35,0,0" Height="220">
<Label/>
Expand Down
10 changes: 6 additions & 4 deletions ScreenRotateForWin10/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms;

namespace ScreenRotateForWin10
{
Expand All @@ -22,14 +23,15 @@ public MainWindow()
private void Init()
{
var result = new List<string>();
screenCount = Screen.AllScreens.Count();
result.AddRange(
Enumerable.Range(1, (int)(Display.GetScreenCount()))
.Select(x => $"{x}号屏幕") // $"NO.{x} Screen"
Enumerable.Range(0, screenCount)
.Select(x => $"{x + 1}号屏幕") // $"NO.{x} Screen"
);
result.Add("所有"); // All
screenList = result;
choiceComboBox.ItemsSource = screenList;
screenCount = (int)Display.GetScreenCount();
choiceComboBox.SelectedIndex = result.Count - 1; // Last
}

private void RotateChoice(int choice, Display.Orientations degree)
Expand All @@ -45,7 +47,7 @@ private void RotateChoice(int choice, Display.Orientations degree)
}
}

private void DefaultButton_Click(object sender, RoutedEventArgs e) => Display.ResetAllRotations();
private void DefaultButton_Click(object sender, RoutedEventArgs e) => Display.ResetAllRotations(screenCount);

private void Button_Click(object sender, RoutedEventArgs e)
{
Expand Down
1 change: 1 addition & 0 deletions ScreenRotateForWin10/ScreenRotateForWin10.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down

0 comments on commit 727597e

Please sign in to comment.