DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

David has posted 23 posts at DZone. View Full User Profile

Display A MessageBox Using The Windows API

06.03.2007
| 6909 views |
  • submit to reddit
        Sometimes the only user interface you need is a message box... Yes/No... OK/Cancel... You can use the DL library to call the MessageBoxA Windows API function.

require 'dl'

# button constants
BUTTONS_OK = 0
BUTTONS_OKCANCEL = 1
BUTTONS_ABORTRETRYIGNORE = 2
BUTTONS_YESNO = 4

# return code constants
CLICKED_OK = 1
CLICKED_CANCEL = 2
CLICKED_ABORT = 3
CLICKED_RETRY = 4
CLICKED_IGNORE = 5
CLICKED_YES = 6
CLICKED_NO = 7

def message_box(txt, title=APP_TITLE, buttons=BUTTONS_OK)
    user32 = DL.dlopen('user32')
    msgbox = user32['MessageBoxA', 'ILSSI']
    r, rs = msgbox.call(0, txt, title, buttons)
    return r
end

Further details can be found <a href="http://rubyonwindows.blogspot.com/2007/06/displaying-messagebox-using-windows-api.html">here</a>.