从windows中的ruby代码弹出指令最简单的方法是什么?

时间:2011-12-29 09:15:13

标签: ruby

平台是windows xp x86。

我想编写一个函数,比如pop_up_instruction(),在调用它时,应该有一个弹出对话框或记事本或命令行或其他任何可以在其上打印指令块的内容。

指令包含“\ r \ n”,如下所示:

Explorer [/n] [/e] [(,)/root,<object>] [/select,<object>]

/n                Opens a new single-pane window for the default
                  selection. This is usually the root of the drive Windows
                   is installed on. If the window is already open, a
                  duplicate opens.
/e                Opens Windows Explorer in its default view.
/root,<object>    Opens a window view of the specified object.
/select,<object>  Opens a window view with the specified folder, file or
                  application selected.

我编写了一个函数将上面的字符串转换为vb-string,并将其打印到vbs文件并使用system(the_vbs_file)调用此vbs文件,the_vbs_file内容:

  MsgBox "Explorer [/n] [/e] [(,)/root,<object>] [/select,<object>]" & vbCrLf & _
  "" & vbCrLf & _
  "/n                Opens a new single-pane window for the default" & vbCrLf & _
  "                  selection. This is usually the root of the drive Windows" & vbCrLf & _
  "                   is installed on. If the window is already open, a" & vbCrLf & _
  "                  duplicate opens." & vbCrLf & _
  "/e                Opens Windows Explorer in its default view." & vbCrLf & _
  "/root,<object>    Opens a window view of the specified object." & vbCrLf & _
  "/select,<object>  Opens a window view with the specified folder, file or" & vbCrLf & _
  "                  application selected." & vbCrLf & _
  ""

我们还有其他更好的方法吗?

1 个答案:

答案 0 :(得分:0)

你应该看看win32api:

require "Win32API"  
title, message =  'dialog title', "line 1\nline 2"
Win32API.new('user32','MessageBox',['L', 'P', 'P', 'L'],'I').call(0,message,title,0)