本帖最后由 5i365 于 2022-2-21 07:35 编辑
回复 5# idwma
修改了一下代码, 可读性更强些, C#代码减了些, 但是现在三个微信窗口是紧挨在一起的,二维码挨在一起, 扫时不方便, 怎样将两两窗口相接的地方分开, 空距在水平均分?- 1 .. 3 |
- foreach{
- start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
- }
- while ($j -ne 3)
- {
- sleep 1
- if ($j -ne $null) { rv j }
- ps wechat |
- ForEach{
- if (!($_.mainwindowtitle -eq ''))
- {
- $j++
- }
- }
- }
-
- Add-Type @'
- using System.Runtime.InteropServices;
- public struct RECT{
- public uint left;
- public uint top;
- public uint right;
- public uint bottom;
- }
- public static class WinApi{
- [DllImport("user32.dll")]
- public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
- [DllImport("user32.dll")]
- public static extern bool GetWindowRect(uint hwnd, ref RECT rect);
- }
- '@
-
- #获取记事本窗口句柄
- $a = Get-Process 'WeChat'
- $hwnd = $a[0].MainWindowHandle
-
- #获取窗口信息
- $rect = New-Object 'RECT'
- [void][WinApi]::GetWindowRect([int]$hwnd, [ref]$rect)
- $screen_w = [Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width
- $screen_h = [Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height
- $mw = $rect.right - $rect.left
-
- #计算水平居中坐标
- $x = ($screen_w - $mw * $a.count)/2
- $y = ($screen_h - ($rect.bottom - $rect.top))/2
-
- #设置记事本水平居中
- while ($i++ -lt $a.count)
- {
- $hwnd = $a[$i - 1].MainWindowHandle
- [WinApi]::SetWindowPos([int]$hwnd, $null, $x, $y, 0, 0, 1)
- $x += $mw
- }
复制代码
|