2022-12-14 13:37:23 +01:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2022-12-18 14:27:14 +01:00
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using Common.UI;
|
|
|
|
|
using interop;
|
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
|
|
|
|
{
|
|
|
|
|
internal static class Program
|
|
|
|
|
{
|
|
|
|
|
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
private static GcodePreviewHandlerControl _previewHandlerControl;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
ApplicationConfiguration.Initialize();
|
|
|
|
|
if (args != null)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length == 6)
|
|
|
|
|
{
|
|
|
|
|
string filePath = args[0];
|
2024-06-03 20:17:40 +08:00
|
|
|
IntPtr hwnd = IntPtr.Parse(args[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
2022-12-14 13:37:23 +01:00
|
|
|
|
|
|
|
|
int left = Convert.ToInt32(args[2], 10);
|
|
|
|
|
int right = Convert.ToInt32(args[3], 10);
|
|
|
|
|
int top = Convert.ToInt32(args[4], 10);
|
|
|
|
|
int bottom = Convert.ToInt32(args[5], 10);
|
2024-03-20 15:28:43 +01:00
|
|
|
Rectangle s = new Rectangle(left, top, right - left, bottom - top);
|
2022-12-14 13:37:23 +01:00
|
|
|
|
|
|
|
|
_previewHandlerControl = new GcodePreviewHandlerControl();
|
2024-08-07 13:41:51 +02:00
|
|
|
|
|
|
|
|
if (!_previewHandlerControl.SetWindow(hwnd, s))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
_previewHandlerControl.DoPreview(filePath);
|
|
|
|
|
|
|
|
|
|
NativeEventWaiter.WaitForEventLoop(
|
|
|
|
|
Constants.GcodePreviewResizeEvent(),
|
|
|
|
|
() =>
|
|
|
|
|
{
|
2024-08-07 13:41:51 +02:00
|
|
|
Rectangle s = default;
|
|
|
|
|
if (!_previewHandlerControl.SetRect(s))
|
|
|
|
|
{
|
|
|
|
|
// When the parent HWND became invalid, the application won't respond to Application.Exit().
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
}
|
2022-12-14 13:37:23 +01:00
|
|
|
},
|
|
|
|
|
Dispatcher.CurrentDispatcher,
|
|
|
|
|
_tokenSource.Token);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Wrong number of args: " + args.Length.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// To customize application configuration such as set high DPI settings or default font,
|
|
|
|
|
// see https://aka.ms/applicationconfiguration.
|
|
|
|
|
Application.Run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|