Win32 的 FindWindow() 可以找到具有确切标题的特定窗口,但是“try.bat - Notepad"呢? [英] Win32's FindWindow() can find a particular window with the exact title, but what about "try.bat - Notepad"?
问题描述
Win32的FindWindow()
可以找到标题为无标题-记事本"的窗口,但是如果我只想找到一个记事本窗口却不知道是不是try.bat - Notepad"或标题栏上的其他文件名?
Win32's FindWindow()
can find a window having the title of "Untitled - Notepad", but what if I just want to find a Notepad window but don't know whether it is "try.bat - Notepad" or some other file name on the title bar?
好像title传入一个NULL值,那么任何一个窗口都会返回,但是只返回一个窗口,所以没有办法grep
使用正则表达式为标题.
It seems that if the title is passed in a NULL value, then any window will be returned, but only one window is returned, so there is no way to grep
for the title using regular expression.
(我使用 Ruby 的 Win32API 执行此操作)
(I am doing this using Ruby's Win32API)
推荐答案
我会听从 Eric 的建议来使用 EnumWindows.您可以通过 win32-api 向 Windows API 函数提供 Ruby 回调.这是从 win32-api 自述文件:
I would follow Eric's advice to use EnumWindows. You can provide Ruby callbacks to Windows API functions through win32-api. Here's an example that was trivially modified from the sample in the win32-api README:
require 'win32/api'
include Win32
# Callback example - Enumerate windows
EnumWindows = API.new('EnumWindows', 'KP', 'L', 'user32')
GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32')
EnumWindowsProc = API::Callback.new('LP', 'I'){ |handle, param|
buf = "\0" * 200
GetWindowText.call(handle, buf, 200);
if (!buf.index(param).nil?)
puts "window was found: handle #{handle}"
0 # stop looking after we find it
else
1
end
}
EnumWindows.call(EnumWindowsProc, 'Firefox')
这篇关于Win32 的 FindWindow() 可以找到具有确切标题的特定窗口,但是“try.bat - Notepad"呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!