Ruby msgbox?

A

aidy

This may seem obvious to some of you guys, but have I got to use a
win32 dll to create a message box in a Ruby program?

Cheers

Aidy
 
C

ChrisH

I guess you could. Or you could use one of the GUI libs (Tk, wx, Fox)
and use their implementation of a messageBox

Cheers
Chris
 
J

Johnny Software

Tk is a really easy way to do that. Does not take much code, it is
portable, and there are widely available examples of Tk GUIs in Ruby
out there.

There are some examples of this in the "Programming Ruby" 2nd edition
book from Pragmatic Programmers.

If you see stuff like the following in your Ruby lib directory - where
ever that is on your Windows computer, you probably are set up to use
Tk from Ruby.

../1.8/test/unit/ui/tk
../1.8/tk
../1.8/tkextlib
../1.8/tkextlib/blt
../1.8/tkextlib/blt/tile
../1.8/tkextlib/bwidget
../1.8/tkextlib/ICONS
../1.8/tkextlib/itcl
../1.8/tkextlib/itk
../1.8/tkextlib/iwidgets
../1.8/tkextlib/tcllib
../1.8/tkextlib/tclx
../1.8/tkextlib/tile
../1.8/tkextlib/tkDND
../1.8/tkextlib/tkHTML
../1.8/tkextlib/tkimg
../1.8/tkextlib/tktable
../1.8/tkextlib/tktrans
../1.8/tkextlib/treectrl
../1.8/tkextlib/trofs
../1.8/tkextlib/vu
../1.8/tkextlib/winico

Tk is nicer to use than the bare bones Win32 API for GUIs because Tk
has a layout manager. So when window resizing occurs, layout of its
contents is updated sanely/automatically.
 
A

Alan Chen

If all you want is the standard message box, you could just access the
direct WinAPI function:

msgbox = Win32API.new( 'user32', 'MessageBox', ['i', 'p', 'p', 'i'],
'i' )
flags = 0 # 0, ok, 1, ok cancel, etc
result = msgbox.call(0, "message", "title", flags )

Lookup the MessageBox function on msdn to determine all the flags.
Note, this is probably the wrong way to go if you want more extended
gui interactions; at that point it would likely be more worth your time
to climb the learning curove on one of the other Ruby Gui bindings.

Cheers,
- alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
RollandKna

Latest Threads

Top