Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
441 changes: 264 additions & 177 deletions WinUIGallery/Samples/ControlPages/AppWindowPage.xaml

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions WinUIGallery/Samples/ControlPages/AppWindowPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ private void ShowSampleWindow3(object sender, RoutedEventArgs e)
window.Activate();
}

private void ShowSampleWindow4(object sender, RoutedEventArgs e)
{
SampleWindow4 window = new SampleWindow4((int)MinWidthBox.Value, (int)MinHeightBox.Value, (int)MaxWidthBox.Value, (int)MaxHeightBox.Value);
window.Activate();
}

private void HasBorder_Toggled(object sender, RoutedEventArgs e)
{
if(!HasBorder.IsOn)
Expand All @@ -60,21 +66,21 @@ private void HasTitleBar_Toggled(object sender, RoutedEventArgs e)

string BoolToLowerString(bool value) => value.ToString().ToLower();

private void ShowSampleWindow4(object sender, RoutedEventArgs e)
private void ShowSampleWindow5(object sender, RoutedEventArgs e)
{
ModalWindow window = new ModalWindow();
window.Activate();
}

private void ShowSampleWindow5(object sender, RoutedEventArgs e)
private void ShowSampleWindow6(object sender, RoutedEventArgs e)
{
SampleWindow5 window = new SampleWindow5();
SampleWindow6 window = new SampleWindow6();
window.Activate();
}

private void ShowSampleWindow6(object sender, RoutedEventArgs e)
private void ShowSampleWindow7(object sender, RoutedEventArgs e)
{
SampleWindow6 window = new SampleWindow6((string)InitialSize.SelectedItem);
SampleWindow7 window = new SampleWindow7((string)InitialSize.SelectedItem);
window.Activate();
}

Expand Down
89 changes: 0 additions & 89 deletions WinUIGallery/Samples/SampleCode/AppWindow/AppWindowSample4_cs.txt

This file was deleted.

This file was deleted.

68 changes: 62 additions & 6 deletions WinUIGallery/Samples/SampleCode/AppWindow/AppWindowSample5_cs.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using WinRT.Interop;

namespace YourNamespace;

public sealed partial class SampleWindow5 : Window
public sealed partial class ModalWindow : Window
{
private AppWindow appWindow;

public SampleWindow5()
public ModalWindow()
{
this.InitializeComponent();
appWindow = GetAppWindowForCurrentWindow();
appWindow.Resize(new Windows.Graphics.SizeInt32(400,300));

// Set the window to Full-Screen mode
appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
OverlappedPresenter presenter = OverlappedPresenter.CreateForDialog();

// Set this modal window's owner (the main application window).
// The main window can be retrieved from App.xaml.cs if it's set as a static property.
SetOwnership(appWindow, App.StartupWindow);

// Make the window modal (blocks interaction with the owner window until closed).
presenter.IsModal = true;

// Apply the presenter settings to the AppWindow.
appWindow.SetPresenter(presenter);

// Show the modal window.
appWindow.Show();

Closed += ModalWindow_Closed;
}

private AppWindow GetAppWindowForCurrentWindow()
Expand All @@ -26,8 +42,48 @@ public sealed partial class SampleWindow5 : Window
return AppWindow.GetFromWindowId(myWndId);
}

private void Close_Click(object sender, RoutedEventArgs e)
// Sets the owner window of the modal window.
private void SetOwnership(AppWindow ownedAppWindow, Window ownerWindow)
{
// Get the HWND (window handle) of the owner window (main window).
IntPtr ownerHwnd = WindowNative.GetWindowHandle(ownerWindow);

// Get the HWND of the AppWindow (modal window).
IntPtr ownedHwnd = Win32Interop.GetWindowFromWindowId(ownedAppWindow.Id);

// Set the owner window using SetWindowLongPtr for 64-bit systems
// or SetWindowLong for 32-bit systems.
if (IntPtr.Size == 8) // Check if the system is 64-bit
{
SetWindowLongPtr(ownedHwnd, -8, ownerHwnd); // -8 = GWLP_HWNDPARENT
}
else // 32-bit system
{
SetWindowLong(ownedHwnd, -8, ownerHwnd);
}
}

// Import the Windows API function SetWindowLongPtr for modifying window properties on 64-bit systems.
[DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr")]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

// Import the Windows API function SetWindowLong for modifying window properties on 32-bit systems.
[DllImport("User32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")]
public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

private void ModalWindow_Closed(object sender, WindowEventArgs args)
{
// Reactivate the main application window when the modal window closes.
App.StartupWindow.Activate();
}

private void OKButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}

private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
</Window.SystemBackdrop>

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="8">
<TextBlock Text="This window is running in Fullscreen mode" Style="{ThemeResource TitleTextBlockStyle}" TextAlignment="Center" />
<Button x:Name="Close" Click="Close_Click" Width="150" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<SymbolIcon Symbol="Cancel" Foreground="{ThemeResource SystemFillColorCriticalBrush}" Margin="0,0,4,0" />
<TextBlock Text="Close" Foreground="{ThemeResource SystemFillColorCriticalBrush}" />
</StackPanel>
</Button>
<TextBlock Text="Modal Window" Style="{ThemeResource TitleTextBlockStyle}" TextAlignment="Center" />

<TextBlock Text="This is a modal window created using AppWindow with OverlappedPresenter." Style="{ThemeResource BodyTextBlockStyle}" TextAlignment="Center" TextWrapping="Wrap" />

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="8">
<Button Content="OK" Width="80" Click="OKButton_Click" />
<Button Content="Cancel" Width="80" Click="CancelButton_Click" />
</StackPanel>
</StackPanel>
</Window>
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using System;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using WinRT.Interop;

namespace WinUIGallery.Samples.SamplePages;
namespace YourNamespace;

public sealed partial class SampleWindow5 : Window
public sealed partial class SampleWindow6 : Window
{
private AppWindow appWindow;

public SampleWindow5()
public SampleWindow6()
{
this.InitializeComponent();
appWindow = GetAppWindowForCurrentWindow();
Expand All @@ -30,4 +30,4 @@ private void Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
</Window.SystemBackdrop>

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="8">
<TextBlock Text="This window is set to CompactOverlay (Picture-in-Picture) mode." TextAlignment="Center" TextWrapping="Wrap" />
<TextBlock Text="This window is running in Fullscreen mode" Style="{ThemeResource TitleTextBlockStyle}" TextAlignment="Center" />
<Button x:Name="Close" Click="Close_Click" Width="150" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<SymbolIcon Symbol="Cancel" Foreground="{ThemeResource SystemFillColorCriticalBrush}" Margin="0,0,4,0" />
<TextBlock Text="Close" Foreground="{ThemeResource SystemFillColorCriticalBrush}" />
</StackPanel>
</Button>
</StackPanel>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Window ...>
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="8">
<TextBlock Text="This window is set to CompactOverlay (Picture-in-Picture) mode." TextAlignment="Center" TextWrapping="Wrap" />
</StackPanel>
</Window>
3 changes: 0 additions & 3 deletions WinUIGallery/Samples/SamplePages/SampleWindow3.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ public sealed partial class SampleWindow3 : Window
public SampleWindow3(bool IsAlwaysOnTop, bool IsMaximizable, bool IsMinimizable, bool IsResizable, bool HasBorder, bool HasTitleBar)
{
this.InitializeComponent();

appWindow = GetAppWindowForCurrentWindow();

presenter = OverlappedPresenter.Create();
presenter.IsAlwaysOnTop = IsAlwaysOnTop;
presenter.IsMaximizable = IsMaximizable;
presenter.IsMinimizable = IsMinimizable;
presenter.IsResizable = IsResizable;
presenter.SetBorderAndTitleBar(HasBorder,HasTitleBar);

appWindow.SetPresenter(presenter);
}

Expand Down
44 changes: 44 additions & 0 deletions WinUIGallery/Samples/SamplePages/SampleWindow4.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" ?>
<Window
x:Class="WinUIGallery.Samples.SamplePages.SampleWindow4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:WinUIGallery.Samples.SamplePages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>

<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="10">
<Button
x:Name="RestoreBtn"
Width="150"
Click="RestoreBtn_Click"
Content="Restore" />
<Button
x:Name="MinimizeBtn"
Width="150"
Click="MinimizeBtn_Click"
Content="Minimize" />

<Button
x:Name="CloseBtn"
Width="150"
Margin="0,16,0,0"
Click="CloseBtn_Click">
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<SymbolIcon
Margin="0,0,4,0"
Foreground="{ThemeResource SystemFillColorCriticalBrush}"
Symbol="Cancel" />
<TextBlock Foreground="{ThemeResource SystemFillColorCriticalBrush}" Text="Close" />
</StackPanel>
</Button>
</StackPanel>
</Window>
Loading