"Open" dialog of Windows

Hi guys, been researching about pop up the “open” file dialog of
Windows. I didn’t find nothing, just a snippet of code that doesn’t
work:

require “win32ole”

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

Do you have the way to do that? Thank you.

On Tue, Dec 25, 2012 at 4:37 AM, Damián M. González
[email protected]wrote:

Do you have the way to do that? Thank you.

i cannot answer the win32ole part, but, … regarding gui dialogs, you
may
want to try tk. simpler and works on almost all platform…

eg to select a .rb file, and then print its content,

require ‘tk’
puts File.read Tk::getOpenFile( ‘filetypes’=>[[‘Currently’, ‘*.rb’]] )

tested to run in windows/linux/aix unix

kind regards -botp

That’s cool botp but I’m trying to not use any external gem rather than
FXRuby gem, if I include Tk plus all the gems that I’m using for my
project(roo, win32ole, etc…) the final pack will be big and I don’t
think that the fusion between both frameworks will be nice for the user,
I mean FXRuby widgets are pretty differents that the Tk ones. The
problem with the dialog in FXRuby is that its in English, I’m developing
an Spanish language app, so I can not pop up a dialog in English
expecting that the user will understand what said there. The solution
for me will be if I can pop up the “open” file dialog of Windows(I’m
developing just for windows). Of course I can create my own widget for
file opening but you know, everything takes time, and now I’m running
low, need the help you all can give me, thanks.

It is completely in english, as I said, the app is in spanish language.
Was wondering if I can save time using the windows open file dialog
instead of develop a new widget like the one you showed, I’m trying to
make a professional app so I don’t want for example that the button
‘cancel’ say ‘cancel’ in it, it must be ‘cancelar’, spanish…

Is this what you’re looking for?

http://www.fxruby.org/doc/api/classes/Fox/FXFileDialog.html

Doesn’t the windows dialog correspond to the language currently in use
in the operating system?

If you mean the #FXFileDialog from FXRuby then NO. I’ve tested it. It’s
always in English. If you mean the “Windows OS open dialog”(I mean the
one which say “Open” as caption in English version and “Abrir” in
Spanish version) then it depends of the language currently in use in the
operating system, and that’s what I want… because in this case the app
is explicit for a user which is working in a PC with spanish language.

Damián M. González wrote in post #1090200:

It is completely in english, as I said, the app is in spanish language.
Was wondering if I can save time using the windows open file dialog
instead of develop a new widget like the one you showed, I’m trying to
make a professional app so I don’t want for example that the button
‘cancel’ say ‘cancel’ in it, it must be ‘cancelar’, spanish…

Doesn’t the windows dialog correspond to the language currently in use
in the operating system?

I’d suggest looking into how that dialog is created and whether it’s
possible to change the source to something more suitable for your
project.

Have you tried asking the “Spanish Rails Group” on here? Someone there
might have already solved this problem.

Joel P. wrote in post #1090328:

I’d suggest looking into how that dialog is created and whether it’s
possible to change the source to something more suitable for your
project.

Well, FXRuby is basically a wraper to the C++ Fox framework, so the
pre-mades widgets are in some way hidden in C++ code, as I can’t
interpret C++ code I can’t do nothing. What I can do is combine a group
of widgets until that groups becomes a sort of “file open dialog”, but
I’m trynig to avoid that because it takes time, and am low of it.

Have you tried asking the “Spanish Rails Group” on here? Someone there
might have already solved this problem.

That’s a good recomendation! I think is even better ask in the Ruby on
Rails group since this is a global question, not explicit to some
language. Thank you Joel.

So if still anyone can help. I’ll be thankfull. :slight_smile:

On Mon, Dec 24, 2012 at 8:37 PM, Damin M. Gonzlez
[email protected]wrote:

Hi guys, been researching about pop up the “open” file dialog of
Windows. I didn’t find nothing, just a snippet of code that doesn’t
work:

Short answer: see Win32API GetOpenFileName - filter problem - Ruby - Ruby-Forum

Long answer:
It would have been helpful to include the error message and the Windows
and
Ruby software versions you are using. See
http://www.catb.org/esr/faqs/smart-questions.html#beprecise

Trying your example on Windows 7 Ruby 1.9.3 I get
Win32_Test.rb:3:in initialize': unknown OLE server: MSComDlg.CommonDialog’ (WIN32OLERuntimeError)

This suggests that component is not installed on my machine. Even if it
was
installed, Google suggests there would be a Microsoft component
licensing
issue:

If you insist on solving your problem by using native Windows dialogs,
an
alternative to an OLE component would be to access the Win32 API
directly:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/win32.html#S3

See Win32 GetOpenFileName():

GetOpenFileName() is deprecated but is probably easier to use than the
alternative. However, it will involve packing the OPENFILENAME members,
as
in the example I linked to at the start of my email.

Feliz Navidad,
Kieran

Short answer: see Win32API GetOpenFileName - filter problem - Ruby - Ruby-Forum

Long answer:
It would have been helpful to include the error message and the Windows
and
Ruby software versions you are using. See
How To Ask Questions The Smart Way

Trying your example on Windows 7 Ruby 1.9.3 I get
Win32_Test.rb:3:in initialize': unknown OLE server: MSComDlg.CommonDialog’ (WIN32OLERuntimeError)

Same OS and Ruby version.

This suggests that component is not installed on my machine. Even if it
was
installed, Google suggests there would be a Microsoft component
licensing
issue:

Same thing happen to me, I’ve been in that page. I’ve tried the
solution but doesn’t work for me, seems that the component is not
installed on my machine.

If you insist on solving your problem by using native Windows dialogs,
an
alternative to an OLE component would be to access the Win32 API
directly:
Programming Ruby: The Pragmatic Programmer's Guide

See Win32 GetOpenFileName():
GetOpenFileNameA function (commdlg.h) - Win32 apps | Microsoft Learn
Using Common Dialog Boxes - Win32 apps | Microsoft Learn

GetOpenFileName() is deprecated but is probably easier to use than the
alternative. However, it will involve packing the OPENFILENAME members,
as
in the example I linked to at the start of my email.

Well, this solution can be a mess, since I’ve scaped every time that I
looked to the Win32API, it hurst me. Seems that finally I have to appeal
to construct the entire widget with FXRuby.

Feliz Navidad,
Kieran

Thank you for taking the time to response. Feliz navidad y año nuevo!
:slight_smile: Damián.