# Messagebox on client side

**URL:** <https://www.ruby-forum.com/t/messagebox-on-client-side/197803>\
**Category:** Ruby\
**Created:** [October 20, 2010, 2:33pm UTC](https://www.ruby-forum.com/t/messagebox-on-client-side/197803 "2010-10-20T14:33:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 20, 2010, 2:33pm UTC](https://www.ruby-forum.com/t/messagebox-on-client-side/197803/1 "2010-10-20T14:33:01Z")

</div>

Hii all,  
I used win32 api messagebox in ruby to generate a messagebox  
but only server side am able to see is there any way to open it at  
client side??

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [October 20, 2010, 3:43pm UTC](https://www.ruby-forum.com/t/messagebox-on-client-side/197803/2 "2010-10-20T15:43:03Z")

</div>

On 10/20/2010 7:33 AM, Amit T. wrote:

> Hii all,  
> I used win32 api messagebox in ruby to generate a messagebox  
> but only server side am able to see is there any way to open it at  
> client side??

No, it is not possible. Your Ruby code is running on your server and  
therefore can only access the Win32 API on your server. It has no way  
to access the API on a client machine connecting to your server, and how  
would that work for a non-Windows client anyway?

Do you need to use the Win32 API for this, or would a rough equivalent  
handled via javascript in the web browser of the client suffice?

-Jeremy

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [October 20, 2010, 3:50pm UTC](https://www.ruby-forum.com/t/messagebox-on-client-side/197803/3 "2010-10-20T15:50:41Z")

</div>

Thanks jermy for your response ,this is something i want to achive .In  
my application am uploading file to a folder but file is already there  
it would ask for overwrite by displaying messagebox but problem i  
already told .Could you suggest some other way to achieve this  
means i don;t know much about javascript .can we send desktop of one  
machine to other??

require ‘dl’

# button

constantsBUTTONS\_OK = 0  
BUTTONS\_OKCANCEL = 1  
BUTTONS\_ABORTRETRYIGNORE = 2  
BUTTONS\_YESNO = 4

CLICKED\_CANCEL = 2  
CLICKED\_ABORT = 3  
CLICKED\_RETRY = 4  
CLICKED\_IGNORE = 5  
CLICKED\_YES = 6  
CLICKED\_NO = 7

class UploadController \< ApplicationController  
def index  
render :file =\> ‘app\views\upload\uploadfile.rhtml’  
end

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

def uploadFile

name=DataFile.save1(params[:upload])  
puts name  
$t=0

k = []

File.open(“d:/dm/aan.txt”).each do |line|  
k \<\< line.chomp  
end

puts k  
#puts line.size  
$s=k.size  
#puts $s

for i in 0…Integer($s)

if $L=(name.eql?(k[i]) == true)

response = message\_box(“Are you sure you want to OVERWRITE”,  
“Proceed?”, BUTTONS\_YESNO)  
if response == CLICKED\_YES

```
post = DataFile.save(params[:upload])

render :text => "File has been uploaded successfully"

```

else

```
render :text => "File cann't successfully"

```

end  
end  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [October 20, 2010, 4:09pm UTC](https://www.ruby-forum.com/t/messagebox-on-client-side/197803/4 "2010-10-20T16:09:35Z")

</div>

On 10/20/2010 8:50 AM, Amit T. wrote:

> Thanks jermy for your response ,this is something i want to achive .In  
> my application am uploading file to a folder but file is already there  
> it would ask for overwrite by displaying messagebox but problem i  
> already told .Could you suggest some other way to achieve this  
> means i don;t know much about javascript .can we send desktop of one  
> machine to other??

No, you cannot send the desktop, and you wouldn’t want to either. I’ll  
leave you to think of scary reasons you never want to do that.

Your only option is to send a response to the user asking for  
confirmation in the event that the file exists. That response could  
simply be another page that has a couple buttons for Yes or No options.  
You would have to make the server store the uploaded file into some  
sort of temporary location in this case since the file will be uploaded  
from the first page. Once the user confirms to overwrite the file, the  
server could then move the file from the temporary location to the final  
one.

That’s all very rough, unfortunately. I don’t have enough experience  
with web apps and Rails to help you with anything concrete. All I can  
say is that you have headed down the completely wrong path with using  
the Win32 API to handle this prompt to the user. It cannot be made to  
work.

There are options available in javascript that will allow you to do  
something similar from within the client’s browser, but I don’t know the  
details of how to use those functions. Someone on the Rails list should  
be able to help you more.

-Jeremy

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [October 20, 2010, 4:16pm UTC](https://www.ruby-forum.com/t/messagebox-on-client-side/197803/5 "2010-10-20T16:16:24Z")

</div>

Thanks Jermy

for your time i will try to do what you said
