mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-11-21 21:30:12 +00:00
43caff1ca9
commit 2bbda3c4e4969fdf05566908fde01f1c9e4e23f7 Author: Stanley <hawkeyesk@outlook.com> Date: Mon Sep 5 23:54:39 2022 -0400 Added in-game panel support commit ec29b0ec2612b10e45ab9a73c10b88a98fcf6eaf Author: Stanley <hawkeyesk@outlook.com> Date: Sun Sep 4 21:21:37 2022 -0400 Added in-game panel support commit 97edc184f349e1fde74a15a643fb90fb9bd90395 Author: Stanley <hawkeyesk@outlook.com> Date: Thu Sep 1 18:08:44 2022 -0400 Update touch panel commit da48ca0a272290466952c5c1bd1ca035d56f930c Author: Stanley <hawkeyesk@outlook.com> Date: Mon Aug 29 22:19:38 2022 -0400 Added pop out panel temporary display commit 701346193804f93616b0e6e2222d9d55223f516f Author: Stanley <hawkeyesk@outlook.com> Date: Wed Aug 24 10:33:59 2022 -0400 Added auto resize window display mode commit 98cbcd949f1555b44db22267ce5c54858bef47cd Author: Stanley <hawkeyesk@outlook.com> Date: Wed Aug 24 09:39:38 2022 -0400 Added auto resize window display mode
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using MahApps.Metro.Controls;
|
|
using Microsoft.Web.WebView2.Core;
|
|
using MSFSPopoutPanelManager.Shared;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows;
|
|
|
|
namespace MSFSPopoutPanelManager.WpfApp
|
|
{
|
|
public partial class TouchPanelWebViewDialog : MetroWindow
|
|
{
|
|
private string _planeId;
|
|
private string _panelId;
|
|
private CoreWebView2Environment _webView2Environment;
|
|
|
|
public TouchPanelWebViewDialog(string planeId, string panelId, string caption, int width, int height, CoreWebView2Environment environment)
|
|
{
|
|
InitializeComponent();
|
|
//this.Topmost = true;
|
|
this.Title = caption;
|
|
//this.Width = width;
|
|
//this.Height = height;
|
|
|
|
_planeId = planeId;
|
|
_panelId = panelId;
|
|
_webView2Environment = environment;
|
|
|
|
Loaded += TouchPanelWebViewDialog_Loaded;
|
|
}
|
|
|
|
private async void TouchPanelWebViewDialog_Loaded(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
await webView.EnsureCoreWebView2Async(_webView2Environment);
|
|
|
|
if (webView != null && webView.CoreWebView2 != null)
|
|
{
|
|
webView.CoreWebView2.Navigate($"{Constants.WEB_HOST_URI}/{_planeId.ToLower()}/{_panelId.ToLower()}");
|
|
}
|
|
|
|
// This fixes webview which does not maximize correctly when host WPF dialog is maximized
|
|
WindowExtensions.FixWindowMaximizeCropping(this);
|
|
}
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
webView.Dispose();
|
|
}
|
|
}
|
|
|
|
internal static class WindowExtensions
|
|
{
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
public static extern IntPtr GetWindowLong(IntPtr hwnd, int nIndex);
|
|
|
|
[DllImport("USER32.dll", SetLastError = true)]
|
|
public static extern int SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
|
|
|
|
private const int GWL_STYLE = -16;
|
|
private const uint WS_MAXIMIZEBOX = 0x10000;
|
|
private const uint WS_MINIMIZEBOX = 0x20000;
|
|
|
|
public static void FixWindowMaximizeCropping(this Window window)
|
|
{
|
|
window.SourceInitialized += (s, e) =>
|
|
{
|
|
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
|
|
var currentStyle = GetWindowLong(hwnd, GWL_STYLE).ToInt64();
|
|
|
|
SetWindowLong(hwnd, GWL_STYLE, (uint)(currentStyle & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX));
|
|
};
|
|
}
|
|
}
|
|
}
|