如何用Ruby、Perl或Python将“Firefox”窗口移动到屏幕坐标(0,0)并调整大小为1024 x 768?

1 投票
2 回答
886 浏览
提问于 2025-04-16 01:45

这个程序能不能通过窗口标题和exe文件名来移动呢?

如果有其他语言中关于如何移动它的信息,那也会很有帮助。

更新:在Win32::GuiTest上可以找到一些Perl的示例,但似乎没有调整大小或移动的功能。

2 个回答

2

这里有一种在Ruby中使用 win32-api 的方法:

# example.rb
require 'win32/api'
include Win32

FindWindow = API.new('FindWindow', 'PP', 'L', 'user32')
hWnd = FindWindow.call(nil, "firefox")
if (hWnd == 0)
  puts "firefox not found"
  exit 1
end

MoveWindow = API.new('MoveWindow', 'LIIIII', 'I', 'user32')
ret = MoveWindow.call(hWnd, 0, 0, 1024, 768, true)
if (ret == 0)
  puts "MoveWindow failed"
  exit 1
end

puts "success"

这个方法只适用于窗口名称**完全**是“firefox”(我测试时不区分大小写)。因为窗口的标题可能会有所不同(比如“Google - Mozilla Firefox”),所以你可能需要使用 EnumWindows 来遍历所有窗口,找到你想要的那个。

撰写回答