From: Colin Bartlett Date: 2012-06-13T00:37:22+09:00 Subject: Re: ffi - Popping image on top of the screen If it's OK to use a Microsoft Windows MsgBox which a user will have to close manually then the following may help. (It might be possible to use something like SendKeys to close the MsgBox from Ruby.) It seems to work both with MRI Ruby ruby.exe in a console window and with MRI Ruby rubyw.exe (no console window, but as my trying that may be the first time I've ever used rubyw.exe, no guarantees!). # a longer example is here: # http://www.pastie.org/4074156 # For a Microsoft Windows MsgBox the basic idea is like this for MRI Ruby 1.9: require 'dl' User32 = DL.dlopen('user32') User32_MsgBox = DL::CFunc.new( User32[ 'MessageBoxA' ], DL::TYPE_LONG, 'MessageBox') def MsgBox(text, title = "", buttons_icon_etc=0, timeout=0, handle=nil) if (timeout == 0 || ! timeout) && ! handle then # User32_MsgBox.call returns an array: # [return_value, [0, text, title, buttons + icon + modality]] # we only want the return value, hence "result, =" # #dup used: if text or title are frozen, #pack('p') raises an exception result, = User32_MsgBox.call( [ 0, text.dup, title.dup, buttons_icon_etc ].pack('L!ppL!').unpack('L!*') ) return result end raise "MsgBox: to use timeout or handle may need something like AutoIt" end MsgBox("basic text then title Microsoft Windows MsgBox example" << "\ntried in 1.9 but not 1.8", "title is ruby " + RUBY_VERSION.to_s)