Skip to content

Commit

Permalink
feat: Add minimization to popupwindow (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Joker authored Sep 15, 2024
1 parent acc7149 commit 0731321
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Starward/Pages/LauncherPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Timers;
using Windows.Storage;
Expand Down Expand Up @@ -645,6 +646,12 @@ private async Task StartGameAsync()
var process2 = await _playTimeService.StartProcessToLogAsync(CurrentGameBiz);
GameProcess = process2 ?? process1;
}
using WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (AppConfig.GetStartArgument(CurrentGameBiz)?.IndexOf("-popupwindow", StringComparison.OrdinalIgnoreCase) >= 0 && principal.IsInRole(WindowsBuiltInRole.Administrator))
{
_ = Task.Run(() => GameService.PopupwindowMinimize(process1));
}
}
}
catch (Exception ex)
Expand Down
31 changes: 30 additions & 1 deletion src/Starward/Services/GameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using Vanara.PInvoke;

namespace Starward.Services;

Expand Down Expand Up @@ -284,5 +286,32 @@ private void DeleteFolderAndParent(string folder)



private static void WaitWindow(Process process)
{
while (process.MainWindowHandle == IntPtr.Zero)
{
Thread.Sleep(1000);
process.Refresh();
}
}



public static void PopupwindowMinimize(Process process)
{
WaitWindow(process);
IntPtr hWnd = process.MainWindowHandle;
if (hWnd != IntPtr.Zero)
{
int style = User32.GetWindowLong(hWnd, User32.WindowLongFlags.GWL_STYLE);
style |= (int)User32.WindowStyles.WS_MINIMIZEBOX;
User32.SetWindowLong(hWnd, User32.WindowLongFlags.GWL_STYLE, style);
// 刷新窗口状态,但会修改窗口位置。因为修改的较早,一般修改后游戏会自行刷新窗口状态
//User32.SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, User32.SetWindowPosFlags.SWP_NOMOVE | User32.SetWindowPosFlags.SWP_NOSIZE | User32.SetWindowPosFlags.SWP_NOZORDER | User32.SetWindowPosFlags.SWP_FRAMECHANGED);
}
}




}
}

0 comments on commit 0731321

Please sign in to comment.