李超

cc编程笔记本。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
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
posted on 2008-04-01 09:52  coderlee  阅读(2955)  评论(2编辑  收藏  举报