Set up IHostEnvironment
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Windows.Win32;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
@@ -6,27 +7,42 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
||||
{
|
||||
public class WindowHelper
|
||||
{
|
||||
public static void MoveAndResize(HWND handle, int x, int y, int width, int height)
|
||||
{
|
||||
PInvoke.SetWindowPos(handle, new HWND(), x, y, width, height, 0);
|
||||
}
|
||||
|
||||
public static void BringToForeground(HWND handle)
|
||||
{
|
||||
if (TryGetBounds(handle, out var bounds))
|
||||
if (TryGetBoundsUnsafe(handle, out var bounds))
|
||||
{
|
||||
PInvoke.SetWindowPos(handle, new HWND(), bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top, SET_WINDOW_POS_FLAGS.SWP_SHOWWINDOW | SET_WINDOW_POS_FLAGS.SWP_NOACTIVATE);
|
||||
}
|
||||
}
|
||||
|
||||
public static HWND Find(string windowName) => PInvoke.FindWindow(windowName, null);
|
||||
|
||||
public static HWND Find(string windowName, HWND parentHandle)
|
||||
public static IntPtr Find(string windowName)
|
||||
{
|
||||
return PInvoke.FindWindowEx(parentHandle, new HWND(), windowName, null);
|
||||
return PInvoke.FindWindow(windowName, null);
|
||||
}
|
||||
|
||||
public static unsafe bool TryGetBounds(IntPtr handle, out RECT rect)
|
||||
public static IntPtr Find(string windowName, IntPtr parentHandle)
|
||||
{
|
||||
return PInvoke.FindWindowEx(new HWND(parentHandle), new HWND(), windowName, null);
|
||||
}
|
||||
|
||||
public static void MoveAndResize(HWND handle, int x, int y, int width, int height)
|
||||
{
|
||||
PInvoke.SetWindowPos(handle, new HWND(), x, y, width, height, 0);
|
||||
}
|
||||
public static bool TryGetBounds(IntPtr handle, [MaybeNullWhen(false)]out Rect rect)
|
||||
{
|
||||
if (TryGetBoundsUnsafe(handle, out var unsafeRect))
|
||||
{
|
||||
rect = new Rect(unsafeRect.left, unsafeRect.top, unsafeRect.right - unsafeRect.left, unsafeRect.bottom - unsafeRect.top);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
rect = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static unsafe bool TryGetBoundsUnsafe(IntPtr handle, out RECT rect)
|
||||
{
|
||||
fixed (RECT* lpRectLocal = &rect)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user