Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Frank O's CommonDialog Class

3 views
Skip to first unread message

Dave F

unread,
Feb 4, 2004, 11:15:05 AM2/4/04
to
Hi

I've never used classes before, & I think I'm being a bit on the dim side.
I've imported the class into a project, but then what?
Has anybody got an example to get me going?
Does it need to run from within a form or directly from a module?

TIA
Dave F.


James Belshan

unread,
Feb 4, 2004, 12:18:38 PM2/4/04
to
Dave, here's code I use to let the user pick a filename to Save a TIF file
to. I have this code in a code module that is called from a form's OK
button.

James

' build TIF filename based on dwg name, sheet and revision, and open
SaveAs dialog
Dim strTIFname As String, strTIFpath As String, strTIFtitle As String
strTIFpath = curdwg.Path
strTIFtitle = dwgNum & "_" & sheetNum & "_" & revNum & ".tif"
strTIFname = strTIFpath & "\" & strTIFtitle

Dim oComDlg As New CommonDialog
Dim retVal As Long

Set oComDlg = New CommonDialog
oComDlg.DefaultExt = "tif"
oComDlg.DialogTitle = "Save TIF File"
oComDlg.Filter = "TIF files (*.tif)|*.tif|All files (*.*)|*.*"
oComDlg.Flags = OFN_OVERWRITEPROMPT
oComDlg.InitDir = strTIFpath

'file name (excluding path) and at least 2 NullChar's must fit in
.MaxFileSize
' or else it will cause an error.
'if it's too long just use the null filename that oComDlg initialized
with
If oComDlg.MaxFileSize - 1 > Len(strTIFtitle) Then
oComDlg.FileName = strTIFtitle & String(oComDlg.MaxFileSize -
Len(strTIFtitle), vbNullChar)
End If

retVal = oComDlg.ShowSave
If retVal <= 0 Then 'user cancelled or the API call failed, see
CommonDialog class
'restore the printer configuration path to its previous value before
exiting
curApp.Preferences.Files.PrinterConfigPath = prevPrintCfgPath
Exit Sub
End If
'get the TIF filename that the user picked
strTIFname = oComDlg.FileName
strTIFpath = oComDlg.Path

Set oComDlg = Nothing 'throw away common dialog

Dave F

unread,
Feb 4, 2004, 1:03:31 PM2/4/04
to
Thanks for that James

I'm trying to find help for the all the flags.
I don't suppose you know of one?

TIA

Dave F.

"James Belshan" <belsh...@nns.com> wrote in message
news:4021296f$1_2@newsprd01...

James Belshan

unread,
Feb 4, 2004, 8:54:51 PM2/4/04
to
Lots of them on the web...

http://www.google.com/search?q=OFN_OVERWRITEPROMPT+api

From that search:
http://vbnet.mvps.org/index.html?http://vbnet.mvps.org/api/_consts/constso.htm

To use them together, I believe you'll use the OR operator, e.g. (or is it
i.e.)
filebox.flags = OFN_PATHMUSTEXIST Or OFN_OVERWRITEPROMPT Or
OFN_HIDEREADONLY

Good luck,
James

"Dave F" <davi...@NOSPAMburohappold.com> wrote in message
news:402133f6_2@newsprd01...

Dave F

unread,
Feb 5, 2004, 4:57:58 AM2/5/04
to

Another query, if you've the time.

This seems a bit weird

I've amended your very helpful example slightly

The showopen dialog defaults to the normal Win '98+ open dialog.
But if I add the flag multiselect it displays a really old looking dialog
(Win 3.1?).

Do you know if there's a way to avoid this?

oComDlg.Flags = OFN_ALLOWMULTISELECT

retVal = oComDlg.ShowOpen

TIA
Dave F.


Mike Tuersley

unread,
Feb 5, 2004, 8:06:32 AM2/5/04
to
Don't use the common dialog control then. Use the API instead so you're
not hampered by old controls. Visit vbnet.com and download one of their
sample projects to see how to do it.
___________________________
Mike Tuersley
CADalyst's AutoCAD Clinic
Rand IMAGINiT Technologies

Dave F

unread,
Feb 5, 2004, 8:45:16 AM2/5/04
to
I may have got the wrong end of the stick, but aren't VBA routines not
allowed to use the API?

Cheers
Dave F.

"Mike Tuersley" <MikeDOT...@techsoftware.com> wrote in message
news:MPG.1a8c09e37...@discussion.autodesk.com...

James Belshan

unread,
Feb 5, 2004, 9:45:58 AM2/5/04
to
> I may have got the wrong end of the stick, but aren't VBA routines not
> allowed to use the API?
>

Dave,
They are allowed to, and you already are. Frank's CommonDialog.cls is a
wrapper for the API functions. The first lines the module declare the API
functions that are used (GetOpenFilename is the one you're calling -- look
at the ShowOpen function).

Try this:
oComDlg.Flags = OFN_EXPLORER Or OFN_ALLOWMULTISELECT

James


Mike Tuersley

unread,
Feb 5, 2004, 11:59:30 AM2/5/04
to
Yeah, you've got it flip-flopped. You are allowed to use thhe API but
not necessarily the controls such as the common dialog. Frank's class
wraps the API calls for the same API that the common dialog does. There
are other APIs and approaches to use which is why I directed you to the
vbnet site.

Dave F

unread,
Feb 5, 2004, 2:51:32 PM2/5/04
to
> Now I just need to work out how to parse the string of multiple files
names
> that gets returned.

Got it! at http://vbnet.mvps.org
Hey, you know, I think this internet thing might just catch on! ;-)


Dave F

unread,
Feb 5, 2004, 2:44:10 PM2/5/04
to
Thanks, it seems to work.

Now I just need to work out how to parse the string of multiple files names
that gets returned.

Cheers

Dave F.

"James Belshan" <belsh...@nns.com> wrote in message

news:40225727$1_3@newsprd01...

Frank Oquendo

unread,
Feb 5, 2004, 3:18:27 PM2/5/04
to
James Belshan wrote:
> I think the first one may be the path, but I'm not sure.

ParseFileNames returns an array of fully-qualified paths. The situation
you described is the default API behavior when querying the selected
file(s) after a multiple selection.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)


Frank Oquendo

unread,
Feb 5, 2004, 3:12:16 PM2/5/04
to
Mike Tuersley wrote:

> There are other APIs

Not for the OpenFileDialog.

Frank Oquendo

unread,
Feb 5, 2004, 3:10:44 PM2/5/04
to
Dave F wrote:

> oComDlg.Flags = OFN_ALLOWMULTISELECT

Always include OFN_EXPLORER.

James Belshan

unread,
Feb 5, 2004, 3:09:13 PM2/5/04
to
> > Now I just need to work out how to parse the string of multiple files
> > names that gets returned.

Well, it sounds like you've already got this solved, but FYI, Frank's
wrapper class has a method that would do this for you, too. Oddly enough,
it's called ParseFileNames ;-) and will return an array of the filenames.


I think the first one may be the path, but I'm not sure.

James


Frank Oquendo

unread,
Feb 5, 2004, 3:11:29 PM2/5/04
to
Mike Tuersley wrote:
> Don't use the common dialog control then. Use the API instead so
> you're not hampered by old controls.

It's not a control. It's a class module wrapper around the API. The
problem is the failure to specify the OFN_EXPLORER flag.

Mike Tuersley

unread,
Feb 5, 2004, 10:32:53 PM2/5/04
to
You're using comdlg32 which is just wrapping the commondialog control.
Couldn't you also use shell32 and/or kernel32 for files? I know you can
for folders and I assumed [yeah, I know about assuming<g>] you could for
files well??? True, you would be making your own control and not using a
wrapper - but that gets you out from under the eula [if it applies
here].

Dave F

unread,
Feb 6, 2004, 6:05:24 AM2/6/04
to
I'd like to thank all above who've have help me out, & lead me into another
useful area of VB programming.

Cheers
Dave F.


0 new messages