[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 5i365 于 2022-2-20 17:28 编辑

回复 2# idwma

感谢分享, 错开了一点距离, 但还是有重叠, 怎样水平方向上居中, 一字 等距离  排开?

TOP

本帖最后由 5i365 于 2022-2-21 07:35 编辑

回复 5# idwma


    修改了一下代码, 可读性更强些, C#代码减了些, 但是现在三个微信窗口是紧挨在一起的,二维码挨在一起, 扫时不方便, 怎样将两两窗口相接的地方分开, 空距在水平均分?
  1. 1 .. 3 |
  2. foreach{
  3. start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
  4. }
  5. while ($j -ne 3)
  6. {
  7. sleep 1
  8. if ($j -ne $null) { rv j }
  9. ps wechat |
  10. ForEach{
  11. if (!($_.mainwindowtitle -eq ''))
  12. {
  13. $j++
  14. }
  15. }
  16. }
  17. Add-Type @'
  18.     using System.Runtime.InteropServices;
  19.     public struct RECT{
  20.         public uint left;
  21.         public uint top;
  22.         public uint right;
  23.         public uint bottom;
  24.     }
  25.     public static class WinApi{
  26.         [DllImport("user32.dll")]
  27.         public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
  28.         [DllImport("user32.dll")]
  29.         public static extern bool GetWindowRect(uint hwnd, ref RECT rect);
  30.     }
  31. '@
  32. #获取记事本窗口句柄
  33. $a = Get-Process 'WeChat'
  34. $hwnd = $a[0].MainWindowHandle
  35. #获取窗口信息
  36. $rect = New-Object 'RECT'
  37. [void][WinApi]::GetWindowRect([int]$hwnd, [ref]$rect)
  38. $screen_w = [Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width
  39. $screen_h = [Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height
  40. $mw = $rect.right - $rect.left
  41. #计算水平居中坐标
  42. $x = ($screen_w - $mw * $a.count)/2
  43. $y = ($screen_h - ($rect.bottom - $rect.top))/2
  44. #设置记事本水平居中
  45. while ($i++ -lt $a.count)
  46. {
  47. $hwnd = $a[$i - 1].MainWindowHandle
  48. [WinApi]::SetWindowPos([int]$hwnd, $null, $x, $y, 0, 0, 1)
  49. $x += $mw
  50. }
复制代码

TOP

返回列表