本帖最后由 idwma 于 2022-2-20 16:26 编辑
http://www.bathome.net/redirect. ... 1741&ptid=61628
学点基础,进入练气期,很多方法都通用的改一下就能用- #&cls&@powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" &pause&exit
- 1..3|%{start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe}
- while($j -ne 3){sleep 1;if($j -ne $null){rv j};ps wechat|%{if(!($_.mainwindowtitle -eq '')){$j++}}}
- cls
-
- #Windows API
- $code=@'
- using System;
- 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("kernel32.dll")]
- public static extern uint GetConsoleWindow();
- [DllImport("user32.dll")]
- public static extern bool GetWindowRect(uint hwnd, ref RECT rect);
- [DllImport("user32.dll")]
- public static extern uint GetDC(uint hwnd);
- [DllImport("gdi32.dll")]
- public static extern uint GetDeviceCaps(uint hdc, int index);
-
- public static uint[] GetScreen(){
- uint[] arr = {0,0};
- uint hdc = GetDC(0);
- arr[0] = GetDeviceCaps(hdc,118);
- arr[1] = GetDeviceCaps(hdc,117);
- return arr;
- }
- }
- '@
- Add-Type -TypeDefinition $code
-
- #获取记事本窗口句柄
- #$hwnd = (Get-Process 'notepad')[0].MainWindowHandle
- #获取窗口信息
- $rect = New-Object 'RECT'
- [void][WinApi]::GetWindowRect([int]$hwnd,[ref]$rect)
- $screen = [WinApi]::GetScreen()
- #计算水平居中坐标
- #$x = ($screen[0] - ($rect.right - $rect.left))/2
- #设置记事本水平居中
- $a=Get-Process 'WeChat'
- while($i++ -le $a.count){
- $hwnd = $a[$i-1].MainWindowHandle
- [WinApi]::SetWindowPos([int]$hwnd,$null,$i*100,$i*100,0,0,1)
- }
复制代码
|