Windows Pop Up

  • Thread starter jackster the jackle
  • Start date
J

jackster the jackle

I don't normally run ruby scripts on my windows machine but in this
case, I have one that I need to send a pop up message to the user
through the GUI when the script is run.

Does anyone have any base code they can share to perform this function?

thanks

jack
 
R

Roger Pack

Does anyone have any base code they can share to perform this function?

checkout visualuruby -- its examples probably contain one somewhere. Of
course that's ruby only--if you wanted cross platform I suppose jruby +
swing would work.

-r
 
M

Marvin Gülker

jackster said:
I don't normally run ruby scripts on my windows machine but in this
case, I have one that I need to send a pop up message to the user
through the GUI when the script is run.

Does anyone have any base code they can share to perform this function?

thanks

jack

For Windows, it should work with the MessageBox function from the
WinAPI: http://msdn.microsoft.com/en-us/library/ms645505(VS.85).aspx

----------------------------------
require "win32/api" #win32-api gem
MessageBox = Win32::API.new("MessageBox", 'LPPI', 'I', "user32")

MB_OK = 0x00000000
MB_OKCANCEL = 0x00000001
MB_ABORTRETRYIGNORE = 0x00000002
MB_YESNOCANCEL = 0x00000003
MB_YESNO = 0x00000004
MB_RETRYCANCEL = 0x00000005
MB_ICONHAND = 0x00000010
MB_ICONQUESTION = 0x00000020
MB_ICONEXCLAMATION = 0x00000030
MB_ICONASTERISK = 0x00000040
MB_ICONINFORMATION = MB_ICONASTERISK
MB_ICONSTOP = MB_ICONHAND


MessageBox.call(0, "Text", "Titel", MB_OK | MB_ICONINFORMATION)
 
J

jackster the jackle

Thanks ALOT Marvin...that worked perfectly and saved me a ton of time.

I really appreciate it!

jack
 
M

Marvin Gülker

jackster said:
Thanks ALOT Marvin...that worked perfectly and saved me a ton of time.

I really appreciate it!

jack

I'm happy I could help you ;-)
I just found a more complete list of the message box constants in my old
Windows-GUI project. Here it is:

#Layout consts

MB_OK = 0

MB_OKCANCEL = 1

MB_ABORTRETRYIGNORE = 2

MB_YESNOCANCEL = 3

MB_YESNO = 4

MB_RETRYCANCEL = 5

MB_CANCELTRYCONTINUE = 0x00000006


MB_ICONHAND = 16

MB_ICONQUESTION = 32

MB_ICONEXCLAMINATION = 48

MB_ICONASTERISK = 64

MB_ICONWARNING = MB_ICONEXCLAMINATION



MB_ICONINFORMATION = MB_ICONASTERISK

MB_ICONSTOP = MB_ICONHAND

MB_ICONERROR = MB_ICONSTOP



MB_DEFBUTTON1 = 0

MB_DEFBUTTON2 = 256

MB_DEFBUTTON3 = 512


MB_APPLMODAL = 0

MB_SYSTEMMODAL = 4096

MB_TASKMODAL = 8192

#Return consts

IDOK = 1

IDCANCEL = 2

IDABORT = 3

IDRETRY = 4

IDIGNORE = 5

IDYES = 6

IDNO = 7
MessageBox.call(0, "Text", "Titel", MB_OK | MB_ICONINFORMATION)
If you're interested in it: That first zero means that there's no parent
window for the message box. By using some other Windows API functions
you could pass in a window handle here and make a modal dialog, but I
think that's too much work for simple displaying something.

And, yeah, the "Titel" should have read "Title". ;-)

Marvin
 
J

jackster the jackle

Thanks again Marvin...

do you know of a way not to have the DOS window open up when I run when
I double click on the shortcut to the ruby script?

I would like to only get the pop up window when the script completes.

Any ideas?

thanks

jack
 
M

Marvin Gülker

jackster said:
Thanks again Marvin...

do you know of a way not to have the DOS window open up when I run when
I double click on the shortcut to the ruby script?

I would like to only get the pop up window when the script completes.

Any ideas?

thanks

jack

Change your script's file extension to ".rbw". That should cause Windows
to run your script with ruybw.exe instead of ruby.exe and no console
window pops up. But keep in mind that every puts and p will now cause
your script to fail, because the standard output and standard error
handles are invalid. I recommand you to redirect them to a file:
$stdout = $stderr = File.open("MyApplication.log", "a")

Marvin
 
J

jackster the jackle

I changed the extention and it works but I have a couple of system calls
with my script that still open CMD windows when those commands run...is
there any way you know of to get around that?

thanks
jack
 

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
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top