From ec934cdd809dbca39d4192b9da280999cdb8235d Mon Sep 17 00:00:00 2001 From: Lukas Kurz Date: Sun, 12 Feb 2023 18:54:52 +0100 Subject: [PATCH] Wpf host --- ShortDev.Uwp.FullTrust.sln | 23 +++++++++++ ShortDev.Uwp.FullTrust/NativeMethods.txt | 7 +--- .../Xaml/XamlWindowActivator.cs | 2 + WpfApp1/App.xaml | 9 +++++ WpfApp1/App.xaml.cs | 16 ++++++++ WpfApp1/AssemblyInfo.cs | 10 +++++ WpfApp1/MainWindow.xaml | 12 ++++++ WpfApp1/MainWindow.xaml.cs | 38 +++++++++++++++++++ WpfApp1/WpfApp1.csproj | 26 +++++++++++++ 9 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 WpfApp1/App.xaml create mode 100644 WpfApp1/App.xaml.cs create mode 100644 WpfApp1/AssemblyInfo.cs create mode 100644 WpfApp1/MainWindow.xaml create mode 100644 WpfApp1/MainWindow.xaml.cs create mode 100644 WpfApp1/WpfApp1.csproj diff --git a/ShortDev.Uwp.FullTrust.sln b/ShortDev.Uwp.FullTrust.sln index 2e7f344..6a5449d 100644 --- a/ShortDev.Uwp.FullTrust.sln +++ b/ShortDev.Uwp.FullTrust.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShortDev.Uwp.Internal", "Sh EndProject Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "WapProjTemplate1", "WapProjTemplate1\WapProjTemplate1.wapproj", "{7FC83479-C3DF-41FD-B73F-BCF0DABB2C48}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApp1", "WpfApp1\WpfApp1.csproj", "{A37144C7-0608-4B52-944A-53B0A62A797C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -161,6 +163,26 @@ Global {7FC83479-C3DF-41FD-B73F-BCF0DABB2C48}.Release|x86.ActiveCfg = Release|x86 {7FC83479-C3DF-41FD-B73F-BCF0DABB2C48}.Release|x86.Build.0 = Release|x86 {7FC83479-C3DF-41FD-B73F-BCF0DABB2C48}.Release|x86.Deploy.0 = Release|x86 + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|ARM.ActiveCfg = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|ARM.Build.0 = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|ARM64.Build.0 = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|x64.ActiveCfg = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|x64.Build.0 = Debug|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|x86.ActiveCfg = Debug|x86 + {A37144C7-0608-4B52-944A-53B0A62A797C}.Debug|x86.Build.0 = Debug|x86 + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|Any CPU.Build.0 = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|ARM.ActiveCfg = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|ARM.Build.0 = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|ARM64.ActiveCfg = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|ARM64.Build.0 = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|x64.ActiveCfg = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|x64.Build.0 = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|x86.ActiveCfg = Release|Any CPU + {A37144C7-0608-4B52-944A-53B0A62A797C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -169,6 +191,7 @@ Global {AF8198C2-56B9-4F92-9931-0C4837936F95} = {3AAF92E0-F9D8-443E-8B35-B6D97154AA0B} {41C1474E-C3EA-4909-96AC-0FD7ACAD3938} = {3AAF92E0-F9D8-443E-8B35-B6D97154AA0B} {7FC83479-C3DF-41FD-B73F-BCF0DABB2C48} = {3AAF92E0-F9D8-443E-8B35-B6D97154AA0B} + {A37144C7-0608-4B52-944A-53B0A62A797C} = {3AAF92E0-F9D8-443E-8B35-B6D97154AA0B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {94079978-D490-48BD-8069-F095B27A6654} diff --git a/ShortDev.Uwp.FullTrust/NativeMethods.txt b/ShortDev.Uwp.FullTrust/NativeMethods.txt index 8744da9..34e416b 100644 --- a/ShortDev.Uwp.FullTrust/NativeMethods.txt +++ b/ShortDev.Uwp.FullTrust/NativeMethods.txt @@ -10,6 +10,7 @@ SetWindowTheme NCCALCSIZE_PARAMS SendMessage ReleaseCapture +EnableMouseInPointer WM_NCLBUTTONDOWN HT_CAPTION ScreenToClient @@ -31,8 +32,4 @@ WM_CLOSE WM_DESTROY WM_NCCALCSIZE WM_NCHITTEST -WM_ACTIVATE - -GetDCEx -ReleaseDC -GetWindowDC \ No newline at end of file +WM_ACTIVATE \ No newline at end of file diff --git a/ShortDev.Uwp.FullTrust/ShortDev.Uwp.FullTrust/Xaml/XamlWindowActivator.cs b/ShortDev.Uwp.FullTrust/ShortDev.Uwp.FullTrust/Xaml/XamlWindowActivator.cs index a6299da..fdcae90 100644 --- a/ShortDev.Uwp.FullTrust/ShortDev.Uwp.FullTrust/Xaml/XamlWindowActivator.cs +++ b/ShortDev.Uwp.FullTrust/ShortDev.Uwp.FullTrust/Xaml/XamlWindowActivator.cs @@ -80,6 +80,8 @@ static void PrepareWindowInternal(Win32Window window) { // Enable acrylic "HostBackdropBrush" window.EnableHostBackdropBrush(); + + EnableMouseInPointer(true); } static XamlWindow MountXamlInternal(XamlConfig config, IntPtr hwnd, CoreWindow? coreWindow) diff --git a/WpfApp1/App.xaml b/WpfApp1/App.xaml new file mode 100644 index 0000000..2e70522 --- /dev/null +++ b/WpfApp1/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/WpfApp1/App.xaml.cs b/WpfApp1/App.xaml.cs new file mode 100644 index 0000000..9ceebd9 --- /dev/null +++ b/WpfApp1/App.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows; + +namespace WpfApp1 +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public App() + { + // Windows.UI.Xaml.Application singleton + new UwpUI.App(); + } + } +} diff --git a/WpfApp1/AssemblyInfo.cs b/WpfApp1/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/WpfApp1/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/WpfApp1/MainWindow.xaml b/WpfApp1/MainWindow.xaml new file mode 100644 index 0000000..cfada06 --- /dev/null +++ b/WpfApp1/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/WpfApp1/MainWindow.xaml.cs b/WpfApp1/MainWindow.xaml.cs new file mode 100644 index 0000000..e2634af --- /dev/null +++ b/WpfApp1/MainWindow.xaml.cs @@ -0,0 +1,38 @@ +using ShortDev.Uwp.FullTrust.Xaml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Interop; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WpfApp1 +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + + WindowInteropHelper windowInterop = new(this); + windowInterop.EnsureHandle(); + var uwpUI = XamlWindowActivator.Attach(windowInterop.Handle, new()); + uwpUI.Content = new Windows.UI.Xaml.Controls.Button() + { + Content = "Hallo!" + }; + } + } +} diff --git a/WpfApp1/WpfApp1.csproj b/WpfApp1/WpfApp1.csproj new file mode 100644 index 0000000..7f71519 --- /dev/null +++ b/WpfApp1/WpfApp1.csproj @@ -0,0 +1,26 @@ + + + + WinExe + netcoreapp3.1 + true + latest + uap10.0.19041 + 10.0.19041 + AnyCPU;x86 + + + + + + + + + + + + + + + +