将 window 句柄分配给 cmd 中的变量以脚本移动 windows

Assigning window handles to variables in cmd to script moving windows around

我正在使用 VLC 的克隆功能在使用相同控件的扩展显示器上显示相同的视频。这些 windows 是无边界的,所以我不能用鼠标移动它们。默认情况下,VLC 在主显示屏上将它们相互叠加打开。

我想编写一个脚本,将那些 windows 移动到不同的坐标。

我试过使用 cmdow.exe 移动 open windows。但是,我需要单独解决它们。唯一的区别是它们的句柄。我的输出如下所示:

C:\cmdow.exe "VLC (Direct3D9 output)"
Handle  Lev  Pid -Window status- Image   Caption
0x1E084A 1 17740 Res Ina Ena Vis vlc     VLC (Direct3D9 output)
0x170762 1 17740 Res Ina Ena Vis vlc     VLC (Direct3D9 output)

当然,每次重新打开 VLC 时,Handle 值都会更改。

如何将这些值分配给脚本中的变量?

既然你想设置变量(这不是必需的),你永远不会知道返回的行数,因此我们可以创建一个变量数组,其值:

@echo off
setlocal enabledelayedexpansion
set cnt=0
for /f "skip=1" %%i in ('cmdow.exe "VLC (Direct3D9 output)"') do (
   set /a cnt+=1
   set handle!cnt!=%%i
)
for /l %%a in (1,1,%cnt%) do echo !handle%%a!

for /l 循环将允许您使用每个变量集,无论是 1 还是 1000