Photo Copyright © 1998 Wayne Vucenic

       No Bugs Software




Home Page
Ruby Win32 Drag and Drop
           

Ruby Win32 Drag and Drop

Ruby Win32 Drag and Drop is a Windows Explorer Drop Handler which allows Ruby scripts to be executed by dragging and dropping either files or text onto an .rb or .rbw file.

Example

Save the following Ruby script as test.rb

    require 'Win32API'

    Win32API.new('user32', 'MessageBox', 'LPPL', 'I').call(0, ARGF.read, '', 0)
                

Save the following text as data.txt

    This is a test

Now dragging and dropping data.txt onto test.rb, will result in a dialog box saying "This is a test".

Similarly, selecting the text "Hello World" in an editor (Notepad, Word, etc.) and dragging and dropping it onto test.rb generates a dialog box saying "Hello World".

Details

Dragging and dropping the files "a.txt", "b.txt", and "c.txt" onto the file "script.rb" runs rubyw as follows:

    rubyw script.rb a.txt b.txt c.txt

Notes

  1. Actually, the command line contains the full paths to all the script.rb, a.txt, b.txt, and c.txt files, each surrounded by double quotes in case any of the directories has a space in it. I didn't show this above for clarity.
  2. The dropped files appear in sorted order (sorted by full path, case insensitive). Ordinarily, the Windows shell provides the files names in a fairly random order. I felt sorting them made things slightly more predictable.
  3. If text is dropped, a file is created in a temp directory to hold the text, and the path to this file is provided on the command line. Currently this file is not deleted, but it will be in a future version.
  4. rubyw is invoked whether the files or text are dropped on a .rb or a .rbw file.

Installation

  1. Install Ruby using the One Click Installer.
  2. Copy the RubyDragAndDrop.dll file to anywhere. Sometimes files like this are placed in 'c:/windows/system32', but it can go anywhere.
  3. Start a Command Prompt window, cd to the directory containing RubyDragAndDrop.dll, and run regsvr32:
        C:\windows\system32>regsvr32 RubyDragAndDrop.dll

    If this is successful, you'll see a dialog box saying

  4. You're all set. You shouldn't need to reboot Windows.

Prerequisities/Assumptions

  1. Microsoft's file msvcrt.dll must be installed. msvcrt.dll has been included as part of the operating system since Win95 OSR2.
  2. I have tested this on NT4 SP6, Windows 2000, and Windows XP Home and Professional. I expect it will work on Windows Server 2003 and on Win95/98/ME, but I haven't been able to test this.
  3. If you don't use the Ruby One Click Installer to install Ruby, you need to ensure that at least two things are set up correctly:
    1. The directory containing rubyw.exe must be in your path. You can verify this by starting a Command Prompt window and running "rubyw". If it's in your path you won't see an error message:

          C:\>rubyw
          C:\>
    2. In the registry, the file extension .rb should map to rbFile, and .rbw should map to rbwFile. You can verify this in RegEdit by checking that the default value of the HKEY_CLASSES_ROOT/.rb registry key is "rbFile" (and of .rbw is "rbwFile")
    If there's sufficient interest I'll write up more detailed instructions for getting this to work in a non-OneClickInstaller environment.

Known Bugs and Limitations

  1. Temporary files created when text is dragged and dropped are never deleted. (No temporaries are created when files are dragged and dropped.)
  2. "regsvr32 -u RubyDragAndDrop.dll" does not work, and gets an error.

Download

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Click to download RubyDragAndDrop.dll Version 0.5 Oct-2-2005