tag:blogger.com,1999:blog-284600789737488130.post1708513744593483807..comments2024-02-07T02:22:20.642-05:00Comments on Ruby on Windows: Displaying a MessageBox Using the Windows APIDavid Mullethttp://www.blogger.com/profile/05597492688893461137noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-284600789737488130.post-88085814345710192382016-01-19T08:29:18.669-05:002016-01-19T08:29:18.669-05:00there is a gem for this:
http://www.rubydoc.info/g...there is a gem for this:<br />http://www.rubydoc.info/gems/messagebox/0.1.0Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-52706298555224317752015-01-05T01:38:37.855-05:002015-01-05T01:38:37.855-05:00OK
so i'm really new to ruby here
stand on th...OK<br />so i'm really new to ruby here<br /><br />stand on the shoulders of giants<br /><br />but i'd like to suggest:<br /><br />r, rs = msgbox.call([0, txt, title, buttons].pack('L!ppL!').unpack('L!*'))<br /><br />instead....the "buttons" variable was accidentally left as 0Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-62240992605220439562011-05-10T02:34:03.665-05:002011-05-10T02:34:03.665-05:00For Ruby 1.9 this produces an error:
message_box....For Ruby 1.9 this produces an error:<br /><br />message_box.rb:20:in `[]': wrong number of arguments(2 for 1) (ArgumentError)<br /> from message_box.rb:20:in `message_box'<br /> from message_box.rb:25:in `'<br /><br />The solution is to replace lines 20 & 21 by:<br /><br />msgbox = DL::CFunc.new(user32['MessageBoxA'], DL::TYPE_LONG, 'MessageBox')<br />r, rs = msgbox.call([0, txt, title, 0].pack('L!ppL!').unpack('L!*'))<br /><br />Source: http://www.ruby-forum.com/topic/138277Christian Baumannhttp://agile-and-testing.chriss-baumann.de/noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-4575707674292186792010-09-20T14:47:44.642-05:002010-09-20T14:47:44.642-05:00Thank you sooooo much for this code snippet. It w...Thank you sooooo much for this code snippet. It was a simple cut an paste for me!!! If you don't mind me asking, how did you know about this library? It is italized on the Ruby Standard Library Documentation meaning it is not documented. This is a skill I would like to have. <br /><br />Thank you,<br />Bobby WashingtonBobby Washingtonnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-83411495965793633952009-07-07T13:18:10.142-05:002009-07-07T13:18:10.142-05:00Excellent post! I've been looking for a simple...Excellent post! I've been looking for a simple way to do this. Never thought of using the windows API. Glad I found this!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-28444124463552899692009-03-05T17:21:00.000-05:002009-03-05T17:21:00.000-05:00Hi, thanks for the excellent info.One problem I ha...Hi, thanks for the excellent info.<BR/><BR/>One problem I have though is that the dialog box can quite easily get lost, simply because the user is doing something else while the script is running the background and their window takes focus over the dialog.<BR/><BR/>Do you know of a way to make thie Ruby dialog have properties such as always on top etc.?<BR/><BR/>I know in the Win32 API there is a owner window, so could it possible be hooked into that?<BR/><BR/>One other thought is that I am calling the script from a C# application. Is it possible to use the Window Handle of that in the Ruby script?<BR/><BR/>Thanks<BR/>LeeAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-53040157656384392002008-11-14T07:26:00.000-05:002008-11-14T07:26:00.000-05:00Something I observe when scripting a spreadsheet p...Something I observe when scripting a spreadsheet program which is *not* MS-Excel. I hope, though, it is the same there:<BR/><BR/>The method Sheets() of the workbook-object works differently, when parameterized with a String, that starts with a "cypher", i.e. <BR/>'02_2008'. I am unable to activate a sheet with such a name until I prefix it with another character, like this: 'M02_2008'.<BR/><BR/>The same works flawlessly in VB. I cannot but assume, that something special to Win32OLE is responsible.<BR/>TY anyway. ;-)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-41224337525319590802008-05-15T17:40:00.000-05:002008-05-15T17:40:00.000-05:00Great stuff! Please update the site!Great stuff! Please update the site!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-6416713165725069852007-11-16T05:54:00.000-05:002007-11-16T05:54:00.000-05:00Great, just what I needed.Only one disadvantage: t...Great, just what I needed.<BR/><BR/>Only one disadvantage: there's no icon on the message box. To use the Windows standard icons add the following code:<BR/><BR/>--------8<--------------<BR/>ICON_HAND = 16<BR/>ICON_QUESTION = 32<BR/>ICON_EXCLAMATION = 48<BR/>ICON_ASTERISK = 64<BR/><BR/>def message_box(txt='', title='', buttons=0, icon=0)<BR/> user32 = DL.dlopen('user32')<BR/> msgbox = user32['MessageBoxA', 'ILSSI']<BR/> r, rs = msgbox.call(0, txt, title, buttons+icon)<BR/> return r<BR/>end<BR/>--------8<--------------<BR/><BR/>Use it like that:<BR/>response = message_box("Are you sure you want to proceed?", "Proceed?", BUTTONS_YESNO, ICON_QUESTION)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-90974983992845917972007-08-06T15:18:00.000-05:002007-08-06T15:18:00.000-05:00Hi David, I have never done any windows programmin...Hi David, I have never done any windows programming, so I have no prior knowledge of windows dll's. Any sites I have found for the Win API is for C/C++, which I have no experience in. Do you have any suggestion for sites to go to or books to get that will explain all the dll's available and how to use them in Ruby?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-28125468833923288662007-06-12T21:17:00.000-05:002007-06-12T21:17:00.000-05:00@Anko:I have just posted a new article related to ...@Anko:<BR/><BR/>I have just posted a new article related to your question <A HREF="http://rubyonwindows.blogspot.com/2007/06/using-ruby-wmi-to-detect-usb-drive.html" REL="nofollow">here</A>. I hope that helps.<BR/><BR/>DavidDavid Mullethttps://www.blogger.com/profile/05597492688893461137noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-23715527122253461192007-06-06T01:46:00.000-05:002007-06-06T01:46:00.000-05:00@Anko: You probably won't get a very detailed acco...@Anko: You probably won't get a very detailed account, but just know that much of that stuff that is very `Windowsy' will require you to use something like Win32 OLE (dave has written up something <A HREF="http://rubyonwindows.blogspot.com/2007/06/using-ruby-ado-to-work-with-ms-access.html" REL="nofollow">here</A>).<BR/><BR/>In particular, if you did some stuff in those <I>schweet</I> days of Classic ASP, that stuff can almost all happen in Ruby with Win32 OLE stuff. Like sending mail, et cetera. So, if you find a solution based on Win32 OLE, you can translate well. I think.<BR/><BR/>Plus, thanks, Dave, for this one. I am a bit too Unix, for one, and Win32 is scary territory, but I guess it will hurt less with you around. :-)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-13411962003667794262007-06-06T00:42:00.000-05:002007-06-06T00:42:00.000-05:00Anyone know how to monitor Mass Storage Insert eve...Anyone know how to monitor Mass Storage Insert events (eg. When someone inserts a USB drive) from Ruby?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-87578267825346929832007-06-05T08:06:00.000-05:002007-06-05T08:06:00.000-05:00Yo David!!Excellent... You've given me a path to a...Yo David!!<BR/>Excellent... You've given me a path to a solution to what I was trying to do. Keep'em coming.<BR/><BR/>Thanks a lot<BR/><BR/>VijayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-85830527607478271372007-06-03T19:12:00.000-05:002007-06-03T19:12:00.000-05:00Thanks, Marco!"That's stuff you don't find easily ...Thanks, Marco!<BR/><BR/>"That's stuff you don't find easily elsewhere. I'm glad I stepped by."<BR/><BR/>Then I have done my job. I want this blog to be a valuable resource for Ruby developers, and to demonstrate the immense value that Ruby offers for the Windows platform.<BR/><BR/>DavidDavid Mullethttps://www.blogger.com/profile/05597492688893461137noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-77055406481294450512007-06-03T18:43:00.000-05:002007-06-03T18:43:00.000-05:00Hi David,excellent blog, very interesting. That's ...Hi David,<BR/>excellent blog, very interesting. That's stuff you don't find easily elsewhere. I'm glad I stepped by.<BR/><BR/>Congratulations and keep on!<BR/>MarcoUnknownhttps://www.blogger.com/profile/13121216433016461442noreply@blogger.com