How to open file dialog in Ruby, and get open FileName? :-(

I

iMelody Ooo

This is a pop MessaheBox example, but I don't know how to open fiel
dialog?

shell = Win32API.new('user32','MessageBox',['L', 'P', 'P', 'L'],'I')
shell.Call(0,"hello world","ShadowZ",0)
 
I

iMelody Ooo

I find an example from http://www.java2s.com , but pop error:

main.rb:21:in `initialize': failed to create WIN32OLE object from
`MSComDlg.CommonDialog' (WIN32OLERuntimeError)
HRESULT error code:0x80040112


cd = WIN32OLE.new("MSComDlg.CommonDialog")

cd.filter = "All Files(*.*)|*.*" +"|Ruby Files(*.rb)|*.rb"
cd.filterIndex = 2

cd.maxFileSize = 128 # Set MaxFileSize
cd.showOpen()
file = cd.fileName # Retrieve file, path

if not file or file==""
puts "No filename entered."
else
puts "The user selected: #{file}\n"
end
 
C

Charles Calvert

This is a pop MessaheBox example, but I don't know how to open fiel
dialog?

shell = Win32API.new('user32','MessageBox',['L', 'P', 'P', 'L'],'I')
shell.Call(0,"hello world","ShadowZ",0)

The signature of this function is:

int MessageBox(
HWND hWnd, // handle to owner window
LPCTSTR lpText, // text in message box
LPCTSTR lpCaption, // message box title
UINT uType // message box style
);

so your call looks correct at first glance. Note that user32.dll
doesn't export a function named "MessageBox". Instead, it exports
"MessageBoxA" and "MessageBoxW". The former handles ASCII strings and
the latter wide strings (i.e. Unicode). When writing C or C++ code,
one includes the appropriate headers that define the name "MessageBox"
as one of those two using a macro. It may be that you need to call
the appropriate version of the function directly if the Win32API
library doesn't handle that for you.
 
C

Charles Calvert

Charles Calvert wrote in post #955442:

Charles is it possible to open this MessageBox on client side??

As I just responded to you in another thread, this question makes no
sense. The Win32 API is the API for the 32 bit version of Windows,
which is an OS. It is inherently client-side.
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top