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

[代码合集] 如何让BAT打开微信窗口后偏移,3个窗口叠加在一起的看不到另外2个

下面是BAT代码:
----------------------
start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
----------------------
主要是使用微信多开,但打开后3个登陆窗口都是叠加在一起的,想让他们分开展示在桌面上
毕竟没有老师教,自学很痛苦的

本帖最后由 idwma 于 2022-2-20 16:26 编辑

http://www.bathome.net/redirect. ... 1741&ptid=61628
学点基础,进入练气期,很多方法都通用的改一下就能用
  1. #&cls&@powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" &pause&exit
  2. 1..3|%{start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe}
  3. while($j -ne 3){sleep 1;if($j -ne $null){rv j};ps wechat|%{if(!($_.mainwindowtitle -eq '')){$j++}}}
  4. cls
  5. #Windows API
  6. $code=@'
  7.     using System;
  8.     using System.Runtime.InteropServices;
  9.     public struct RECT{
  10.         public uint left;
  11.         public uint top;
  12.         public uint right;
  13.         public uint bottom;
  14.     }
  15.     public static class WinApi{
  16.         [DllImport("user32.dll")]
  17.         public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
  18.         [DllImport("kernel32.dll")]
  19.         public static extern uint GetConsoleWindow();
  20.         [DllImport("user32.dll")]
  21.         public static extern bool GetWindowRect(uint hwnd, ref RECT rect);
  22.         [DllImport("user32.dll")]
  23.         public static extern uint GetDC(uint hwnd);
  24.         [DllImport("gdi32.dll")]
  25.         public static extern uint GetDeviceCaps(uint hdc, int index);
  26.         public static uint[] GetScreen(){
  27.             uint[] arr = {0,0};
  28.             uint hdc = GetDC(0);
  29.             arr[0] = GetDeviceCaps(hdc,118);
  30.             arr[1] = GetDeviceCaps(hdc,117);
  31.             return arr;
  32.         }
  33.     }
  34. '@
  35. Add-Type -TypeDefinition $code
  36. #获取记事本窗口句柄
  37. #$hwnd = (Get-Process 'notepad')[0].MainWindowHandle
  38. #获取窗口信息
  39. $rect = New-Object 'RECT'
  40. [void][WinApi]::GetWindowRect([int]$hwnd,[ref]$rect)
  41. $screen = [WinApi]::GetScreen()
  42. #计算水平居中坐标
  43. #$x = ($screen[0] - ($rect.right - $rect.left))/2
  44. #设置记事本水平居中
  45. $a=Get-Process 'WeChat'
  46. while($i++ -le $a.count){
  47. $hwnd = $a[$i-1].MainWindowHandle
  48. [WinApi]::SetWindowPos([int]$hwnd,$null,$i*100,$i*100,0,0,1)
  49. }
复制代码

TOP

本帖最后由 5i365 于 2022-2-20 17:28 编辑

回复 2# idwma

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

TOP

回复 2# idwma


    你这一大串代码,人家看都看不懂,就别说修改了。

TOP

回复 3# 5i365
  1. #获取记事本窗口句柄
  2. $a=Get-Process 'WeChat'
  3. $hwnd = $a[0].MainWindowHandle
  4. #获取窗口信息
  5. $rect = New-Object 'RECT'
  6. [void][WinApi]::GetWindowRect([int]$hwnd,[ref]$rect)
  7. $screen = [WinApi]::GetScreen()
  8. $mw=$rect.right - $rect.left
  9. #计算水平居中坐标
  10. $x=($screen[0]-$mw*$a.count)/2
  11. $y = ($screen[1] - ($rect.bottom - $rect.top))/2
  12. #设置记事本水平居中
  13. while($i++ -lt $a.count){
  14. $hwnd = $a[$i-1].MainWindowHandle
  15. [WinApi]::SetWindowPos([int]$hwnd,$null,$x,$y,0,0,1)
  16. $x+=$mw
  17. }
复制代码
1

评分人数

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

回复 6# 5i365
  1. #计算水平居中坐标
  2. $x = ($screen_w - $mw * $a.count)/($a.count-1)
  3. $y = ($screen_h - ($rect.bottom - $rect.top))/2
  4. #设置记事本水平居中
  5. while ($i++ -lt $a.count)
  6. {
  7. $hwnd = $a[$i - 1].MainWindowHandle
  8. [WinApi]::SetWindowPos([int]$hwnd, $null, $xx, $y, 0, 0, 1)
  9. $xx = $xx+$x+$mw
  10. }
复制代码

TOP

返回列表