1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 22:20:06 +00:00
msfs-popout-panel-manager/WpfApp/OnScreenMessageDialog.xaml.cs

69 lines
2.5 KiB
C#
Raw Normal View History

2022-01-27 13:40:04 +00:00
using MahApps.Metro.Controls;
2022-07-23 19:23:32 +00:00
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent;
2022-01-27 13:40:04 +00:00
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Interop;
namespace MSFSPopoutPanelManager.WpfApp
{
public partial class OnScreenMessageDialog : MetroWindow
{
2022-07-23 19:23:32 +00:00
public StatusMessageType StatusMessageType { get; set; }
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
public OnScreenMessageDialog(string message, StatusMessageType statusMessageType, int duration)
2022-01-27 13:40:04 +00:00
{
InitializeComponent();
this.DataContext = this;
this.Topmost = true;
this.txtMessage.Text = message;
2022-07-23 19:23:32 +00:00
StatusMessageType = statusMessageType;
2022-01-27 13:40:04 +00:00
this.Loaded += (sender, e) =>
{
2022-04-18 03:38:33 +00:00
var winObj = Window.GetWindow(this);
2022-01-27 13:40:04 +00:00
2022-04-18 03:38:33 +00:00
if (winObj != null)
{
var window = new WindowInteropHelper(winObj);
if (window != null)
{
var dialogHandle = window.Handle;
2022-07-23 19:23:32 +00:00
var simulatorProcess = WindowProcessManager.GetSimulatorProcess();
2022-04-18 03:38:33 +00:00
2022-06-30 23:53:08 +00:00
if (simulatorProcess != null)
{
Rectangle rectangle;
PInvoke.GetWindowRect(simulatorProcess.Handle, out rectangle);
Rectangle clientRectangle;
PInvoke.GetClientRect(simulatorProcess.Handle, out clientRectangle);
2022-01-27 13:40:04 +00:00
2022-06-30 23:53:08 +00:00
var x = Convert.ToInt32(rectangle.X + clientRectangle.Width / 2 - this.Width / 2);
var y = Convert.ToInt32(rectangle.Y + clientRectangle.Height / 2 - this.Height / 2);
2022-01-27 13:40:04 +00:00
2022-07-23 19:23:32 +00:00
WindowActionManager.MoveWindow(dialogHandle, PanelType.WPFWindow, x, y, Convert.ToInt32(this.Width), Convert.ToInt32(this.Height));
}
else
{
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
2022-06-30 23:53:08 +00:00
}
2022-04-18 03:38:33 +00:00
}
}
2022-01-27 13:40:04 +00:00
};
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += (sender, e) =>
{
Application.Current.Dispatcher.Invoke(() =>
{
this.Close(); timer.Enabled = false;
});
};
2022-06-30 23:53:08 +00:00
timer.Interval = duration * 1000;
2022-01-27 13:40:04 +00:00
timer.Enabled = true;
}
}
}