1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 13:50:14 +00:00
msfs-popout-panel-manager/WpfApp/TouchPanelWebViewDialog.xaml.cs

74 lines
2.5 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using MahApps.Metro.Controls;
using Microsoft.Web.WebView2.Core;
2022-07-23 19:23:32 +00:00
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;
2022-07-23 19:23:32 +00:00
public TouchPanelWebViewDialog(string planeId, string panelId, string caption, int width, int height, CoreWebView2Environment environment)
2022-07-23 19:23:32 +00:00
{
InitializeComponent();
//this.Topmost = true;
this.Title = caption;
2022-08-02 20:55:20 +00:00
//this.Width = width;
//this.Height = height;
2022-07-23 19:23:32 +00:00
_planeId = planeId;
_panelId = panelId;
_webView2Environment = environment;
2022-07-23 19:23:32 +00:00
Loaded += TouchPanelWebViewDialog_Loaded;
}
private async void TouchPanelWebViewDialog_Loaded(object sender, System.Windows.RoutedEventArgs e)
2022-07-23 19:23:32 +00:00
{
await webView.EnsureCoreWebView2Async(_webView2Environment);
2022-07-23 19:23:32 +00:00
if (webView != null && webView.CoreWebView2 != null)
{
webView.CoreWebView2.Navigate($"{Constants.WEB_HOST_URI}/{_planeId.ToLower()}/{_panelId.ToLower()}");
}
2022-07-23 19:23:32 +00:00
// This fixes webview which does not maximize correctly when host WPF dialog is maximized
WindowExtensions.FixWindowMaximizeCropping(this);
2022-07-23 19:23:32 +00:00
}
2022-08-08 06:07:24 +00:00
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
webView.Dispose();
}
2022-07-23 19:23:32 +00:00
}
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));
};
}
}
}