Windows Pop Up

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

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

jackster the jackle wrote:

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: MessageBox function (winuser.h) - Win32 apps | Microsoft Learn


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)

Marvin

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

I really appreciate it!

jack

jackster the jackle wrote:

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 :wink:
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”. :wink:

Marvin

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

jackster the jackle wrote:

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

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

Marvin Gülker wrote:

Marvin Gülker wrote:

ruybw.exe
Ouch. rubyw.exe I meant.

Marvin

Marvin Gülker wrote:

ruybw.exe
Ouch. rubyw.exe I meant.

Marvin