1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- # 获取 "BlueStacks App Player" 的窗口句柄
- $bluestacks = Get-Process | Where-Object { $_.MainWindowTitle -eq "BlueStacks App Player" } | Select-Object -First 1
- $hwnd = ($bluestacks.MainWindowHandle)
- # 定义调整窗口大小和将窗口移动到前台的函数:MoveWindowToFrontAndResize
- function MoveWindowToFrontAndResize {
- param (
- [Parameter(Mandatory=$true)] [IntPtr]$Handle,
- [Parameter(Mandatory=$true)] [int]$x,
- [Parameter(Mandatory=$true)] [int]$y,
- [Parameter(Mandatory=$true)] [int]$width,
- [Parameter(Mandatory=$true)] [int]$height
- )
-
- # 加载 user32.dll
- $user32 = Add-Type -Name "User32" -Namespace "Win32" -PassThru `
- -MemberDefinition @"
- [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
- [DllImport("user32.dll")] public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
- "@
- # 将窗口移动到前台
- $null = $user32::SetForegroundWindow($Handle)
- # 延迟一段时间确保窗口已经是前台
- Start-Sleep -Seconds 1
- # 调整窗口大小和位置
- $null = $user32::MoveWindow($Handle, $x, $y, $width, $height, $true)
- }
- # 定义窗口的新位置和大小
- $x = 100
- $y = 100
- $width = 1170
- $height = 563
- # 如果找到了窗口句柄,则移动窗口到前台并调整其大小
- if ($hwnd -ne 0) {
- MoveWindowToFrontAndResize -Handle $hwnd -x $x -y $y -width $width -height $height
- Write-Host "窗口已移动到前台并调整为宽度: $width, 高度: $height."
- } else {
- Write-Host "未能找到 'BlueStacks App Player' 窗口。"
- }
|