Ruby是很强大,可以利用附加库dl/win32的Win32API模块直接呼叫win32API
Win32API.new
参数1 字符串 呼叫dll名称
参数2 字符串 dll中dllexport的名称
参数3 字符串数组 表示每个参数的类型 L代表Long P代表Point I代表Int V代表Void (在实际使用的时候HResult和各种Handle都是Long,字符串是P)
参数4 字符串 表示返回值类型 同上
require
"
dl/win32
"

FindWindow
=
Win32API.new
'
user32.dll
'
,
'
FindWindow
'
,
%
w(L P),
'
L
'
SetWindowText
=
Win32API.new
'
user32.dll
'
,
'
SetWindowText
'
,
%
W(L P),
'
I
'

if
ARGV.length
==
0 then
puts
"
使用说明:
"
puts
"
一个参数时,是根据窗体标题查看窗体ID
"
puts
"
两个参数时,是根据参数1的标题查找窗体,然后更改为参数2的标题
"
elsif ARGV.length
>
0 then
win
=
FindWindow.call(0,ARGV.shift)
puts win
if
win
!=
0 then
bSet
=
SetWindowText.call(win, ARGV.shift)
if
bSet
==
1
then
puts
"
Success!
"
else
puts
"
Fail!
"
end
end
end
本文介绍如何使用Ruby通过dl/win32库调用Windows的API,具体演示了查找窗口并修改其标题的方法。

被折叠的 条评论
为什么被折叠?



