Skip to content

Commit

Permalink
Added the possibility to minimize a window (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Aug 2, 2023
1 parent b3660b5 commit 80611a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
10 changes: 6 additions & 4 deletions PermaTop/UserControls/WindowPropertyItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="TitleTxt" FontWeight="ExtraBold" d:Text="WindowTItle" FontSize="14" VerticalAlignment="Center">
<TextBlock.ToolTip>
<ToolTip x:Name="TitleToolTip" Foreground="{DynamicResource Foreground1}" Background="{DynamicResource Background1}" />
</TextBlock.ToolTip>
</TextBlock>
<Button Foreground="{DynamicResource Foreground1}" x:Name="FavBtn" Click="FavBtn_Click" Width="30" Grid.Column="2" Style="{DynamicResource DefaultButton}" Background="{DynamicResource Background2}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xF710;" FontSize="14" Margin="0 0 5 0"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="PinBtn" Click="PinBtn_Click" Width="30" Grid.Column="3" Style="{DynamicResource DefaultButton}" Background="{DynamicResource Background2}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xF602;" FontSize="14" Margin="0 0 5 0"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="MaxRestoreBtn" Click="MaxRestoreBtn_Click" Width="30" Grid.Column="4" Style="{DynamicResource DefaultButton}" Background="{DynamicResource Background2}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xFA41;" FontSize="14" Margin="0 0 5 0"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="CloseBtn" Click="CloseBtn_Click" Width="30" Grid.Column="5" Style="{DynamicResource DefaultButton}" Background="{DynamicResource Background2}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xF36A;" FontSize="14"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="FavBtn" Click="FavBtn_Click" Width="30" Grid.Column="2" Style="{DynamicResource DefaultButton}" Background="{DynamicResource Background2}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xF710;" FontSize="14" Margin="0 0 5 0"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="PinBtn" Click="PinBtn_Click" Width="30" Grid.Column="3" Style="{DynamicResource DefaultButton}" Background="{DynamicResource Background2}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xF602;" FontSize="14" Margin="0 0 5 0"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="MinBtn" Click="MinBtn_Click" Width="30" Grid.Column="4" Style="{DynamicResource DefaultButton}" Background="{DynamicResource CardBackground}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xF4E0;" FontSize="14" Margin="0 0 5 0"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="MaxRestoreBtn" Click="MaxRestoreBtn_Click" Width="30" Grid.Column="5" Style="{DynamicResource DefaultButton}" Background="{DynamicResource CardBackground}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xFA41;" FontSize="14" Margin="0 0 5 0"/>
<Button Foreground="{DynamicResource Foreground1}" x:Name="CloseBtn" Click="CloseBtn_Click" Width="30" Grid.Column="6" Style="{DynamicResource DefaultButton}" Background="{DynamicResource CardBackground}" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Content="&#xF36A;" FontSize="14"/>
</Grid>
</Border>
</UserControl>
31 changes: 22 additions & 9 deletions PermaTop/UserControls/WindowPropertyItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void FavBtn_Click(object sender, RoutedEventArgs e)
private const int SC_CLOSE = 0xF060;
private const int SC_MAXIMIZE = 0xF030;
private const int SC_RESTORE = 0xF120;

private const int SC_MINIMIZE = 0xF020;

[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
Expand All @@ -101,15 +101,28 @@ private void CloseBtn_Click(object sender, RoutedEventArgs e)

private void MaxRestoreBtn_Click(object sender, RoutedEventArgs e)
{
if (!Global.IsWindowMaximized(WindowInfo.Hwnd))
try
{
if (!Global.IsWindowMaximized(WindowInfo.Hwnd))
{
SendMessage(WindowInfo.Hwnd, WM_SYSCOMMAND, (IntPtr)SC_MAXIMIZE, IntPtr.Zero);
MaxRestoreBtn.Content = "\uF670";
MaxRestoreBtn.FontSize = 18;
return;
}
SendMessage(WindowInfo.Hwnd, WM_SYSCOMMAND, (IntPtr)SC_RESTORE, IntPtr.Zero);
MaxRestoreBtn.Content = "\uFA41";
MaxRestoreBtn.FontSize = 14;
}
catch { }
}

private void MinBtn_Click(object sender, RoutedEventArgs e)
{
try
{
SendMessage(WindowInfo.Hwnd, WM_SYSCOMMAND, (IntPtr)SC_MAXIMIZE, IntPtr.Zero);
MaxRestoreBtn.Content = "\uF670";
MaxRestoreBtn.FontSize = 18;
return;
SendMessage(WindowInfo.Hwnd, WM_SYSCOMMAND, (IntPtr)SC_MINIMIZE, IntPtr.Zero);
}
SendMessage(WindowInfo.Hwnd, WM_SYSCOMMAND, (IntPtr)SC_RESTORE, IntPtr.Zero);
MaxRestoreBtn.Content = "\uFA41";
MaxRestoreBtn.FontSize = 14;
catch { }
}
}

0 comments on commit 80611a5

Please sign in to comment.