Important alert: (current site time 7/16/2013 7:24:47 AM EDT)
 

winzip icon

Common Dialog API calls

Email
Submitted on: 9/19/1999
By: Paul Mather  
Level: Not Given
User Rating: By 17 Users
Compatibility: VB 5.0, VB 6.0
Views: 203608
author picture
(About the author)
 
     Here are the Windows API calls for the ShowOpen, ShowSave, ShowPrinter, ShowColor and ShowFont (Thanks to Jaen Saul aka SlowByte for his post) dialogs. Also included is the beginnings of the ShowFonts dialog but I am haning some trouble getting it to work. These calls are more difficult to use than the CommonDialog control placed on a form, but don't have the version conflicts that Early-Bound and Form-Bound ActiveX controls have. In addition, I have added the ability to center the dialog on the form or center it on the screen.
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 24 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/20/1999 11:11:00 AMSlowByte

Do you have a working version of ShowFonts yet? I'd be glad (I am happy to learn just anything) to help 'n learn if you don't...
(If this comment was disrespectful, please report it.)

 
9/21/1999 5:45:00 AMPaul Mather

Actually yes, I changed this zip to include some stuff from your post! Thanks for the help!
(If this comment was disrespectful, please report it.)

 
9/23/1999 3:30:00 AMKevin

Nice..could have really used this back when VB 5 had serious version problems with the common dialog OCX. I wrote similar routines, but could never figure out the print dialog.
(If this comment was disrespectful, please report it.)

 
10/1/1999 9:31:00 PMKevino, MCP

I've looked a bit harder at this code and realized that the print dialog is of no use without the DEVMODE structure. For instance, there doesn't seem to be any way to get the printer oriention from this code. I am now attempting to add the DEVMODE structure to this code, but please report this (or email me) if you have already worked this out.

Kevin, MCP
(If this comment was disrespectful, please report it.)

 
10/3/1999 8:06:00 PMPaul Mather

Excellent Point, I have never actually used the Print Dialog API, I only got the code working to the point that it would open the form. If anyone has any more code to put behind the Print Dialog, I'd love to have it. Thanks.
(If this comment was disrespectful, please report it.)

 
11/7/1999 8:43:00 AMAce315

PLEASE e-mail me the type declaration for OLE_COLOR!!!
(If this comment was disrespectful, please report it.)

 
11/11/1999 9:37:00 AMPaul Mather

You are the third or fourth person to ask me this question, so I figure I'll post it here. When you create a new project, the only default "Reference" that you are able to turn off is "OLE Automation". Evidently, you have turned off "OLE Automation" because it contains the OLE_COLOR definition.
(If this comment was disrespectful, please report it.)

 
11/28/1999 12:59:00 AMKiat

When I open file more then 2 file in root dirrectory
(multi celect C:\011.txt + C:\022.txt) it's OK and then I open file again
but no have anything (open file dialog not show).why ?
pease let me know
(If this comment was disrespectful, please report it.)

 
1/11/2000 8:52:18 AMJohn G Duffy

The problem with the Devmode structure for the SHOWPRINTER is documented on MSDN article Q173981. This document does show how to change things such as copies, printer selection, orientation etc and works quite well.

However there is a problem with it. When I use it to send output to my HP Laser 1100i printer, I get a error message
"... has performed an illegal operation and has been shutdown".

There is a variation of this document posted on Planet-Source-Code that takes the info in it and turns it into a Class but it fails in the same way.

John
(If this comment was disrespectful, please report it.)

 
2/8/2000 6:13:12 PMHello

Goto www.allapi.net!
(They've got an amazing API guide download!)
(If this comment was disrespectful, please report it.)

 
6/5/2000 2:44:29 PMDouglas Livingstone

IMO, anyone interested in this code should pay a visit to: http://www.vbaccelerator.com/overlib.htm#seclibrary Ther are examples of not just showing the common dialogs, but also hooking them etc... Worth a look
(If this comment was disrespectful, please report it.)

 
3/18/2001 7:15:49 PMSteve G

Most of the time generic code using the Common Dialog control works for me. I havent had a problem with it yet.

Private Sub mnuPrint_Click()
dlgDemo.Flags = 0
dlgDemo.CancelError = True
On Error Resume Next
dlgDemo.ShowPrinter
If Err = 0 Then
'force current default printer:
Printer.Orientation = dlgDemo.Orientation

PrinterPrintML txtEdit, 10
Else
Err = 0
End If
On Error GoTo 0
End Sub

Private Sub mnuPrintSetup_Click()
dlgDemo.Flags = cdlPDPrintSetup
' dlgDemo.Flags = cdlPDPageNums
dlgDemo.CancelError = False
dlgDemo.ShowPrinter
End Sub

'CommonDialog1.Flags = cdlPDNoPageNums
'CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPages
'CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelection
'Printer.Print
'RTB.SelPrint Printer.hDC
'Printer.EndDoc
(If this comment was disrespectful, please report it.)

 
3/25/2002 4:06:01 AMTomás

I would like to know how Can I do when Commond Dialog show the default printer and I change the options of the printer that when I print a document, this document be printed with this options I put in the Commond Dialog.

If you can answer me, please send it me to my e-mail:abegon@hotmail.com

Thanks for all
(If this comment was disrespectful, please report it.)

 
6/2/2002 6:20:48 PMcdw

Very helpful. I could not resolve the dependencies for the ColorDialog on a target machine (worked just fine on the development machine). Kept getting "Run-time error '429': ActiveX component cannot create object". Tried tracking down dependencies, registering OCXs, even running VBC6.EXE. Still kept getting error 429. This code bypassed the whole problem.
(If this comment was disrespectful, please report it.)

 
1/24/2003 7:47:27 AM

The showprinter can only show the select printer only but it can't really print the the job
(If this comment was disrespectful, please report it.)

 
2/23/2003 12:45:44 PM

Downloaded (after about 1/2 hour of looking) your .BAS file to incorporate common Open File dialog into a project. Having trouble with preventing user from multi-selecting files. Would rather not let them have the ability to select more than one file, but can't seem to turn off this ability (even after stripping the OFN_ALLOWMULTISELECT flag from the calling button).

Any ideas? Other than that, I think this is excellent code and look forward to incorporating the other dialogs into my other VB projects.

Thanks for a great effort!
(If this comment was disrespectful, please report it.)

 
8/27/2003 8:45:31 AM

* FOR DISABLE MULTI SELECTING *
Delete the line:
'Public Const OFN_ALLOWMULTISELECT = &H200' in the BAS File
and all :
'Or OFN_ALLOWMULTISELECT' lines in the project.
Good Luck...::)
(If this comment was disrespectful, please report it.)

 
12/17/2003 9:53:52 AM

Your code does just the job, but I'm having trouble using it in VBA (not VB) - I'm doing it within Excel.

I can't work out how to do the Me.hWnd bit - the Me is a worksheet in Excel.

So close, yet so far!
(If this comment was disrespectful, please report it.)

 
12/17/2003 9:55:05 AM

Your code is just what I need - but how do I use it in VBA in Excel?

I'm having trouble with the Me.hWnd bit - the Me is an Excel worksheet.

Thanks for any help ... I'm so close yet so far!
(If this comment was disrespectful, please report it.)

 
4/16/2004 3:42:28 AM

Thanks for your source code. I already downloaded it but i don't understand the API call. I'm having a problem on my assignment on how to use vb 6 to open the Fuji xerox viewer light(program that allowed us to view scanned images).
Can you please send me a piece of code on how to open it without using API?

i'm using this code but i seems like not working. The file i selected can't be opened. The selected file doesn't appear on the screen.

commondialog1.ShowOpen
filename = commondialog1.filename

Do i need to add somemore code in the previous one?? Or can i use the Shell() function to open it?? Or can i add the Fuji xerox viewer light through Project>Component?

Sorry for interrupt and thank you.
(If this comment was disrespectful, please report it.)

 
5/31/2004 2:20:45 PMLCSBSSRHXXX

hmm, this code looks very similar to the common dialouge stuff in api guide
(If this comment was disrespectful, please report it.)

 
1/26/2005 8:08:41 AM

hello ,
I want to close the dialog automatically when it is displayed after pressing a button on a form.
The dialog contains ok button ultimaltely the ok button should be pressed automatically is my requirement.
Please I need a quick answer.
from
Raheel
(If this comment was disrespectful, please report it.)

 
1/26/2005 8:12:37 AM

hi
I want some assistance please. I want to close the dialog box automatically which opened after being pressed a button on a form. This dialog contains only ok button. Ultimately this ok button should be pressed automatically. Please I need quick assistance.
from Raheel.
(If this comment was disrespectful, please report it.)

 
2/4/2005 1:29:40 PM

Multiselect does work!
in the show open code in the api module change:

If ret Then
If Trim$(FileDialog.sFileTitle) = "" Then
LastCharacter = 0
Count = 0

To:

If ret Then
If Trim$(FileDialog.sFileTitle) = Chr(0) Then
LastCharacter = 0
Count = 0
(If this comment was disrespectful, please report it.)

 
2/8/2005 11:11:39 AM

Nice code, but in the showsave, you don't care about the sDefaultExt field, so I added the code in the showsave to take care of it

ShowSave.sFiles(1) = Mid(FileDialog.sFile, FileDialog.nFileOffset + 1, InStr(1, FileDialog.sFile, Chr$(0), vbTextCompare) - FileDialog.nFileOffset - 1)
FileDialog.sDefFileExt = Trim$(FileDialog.sDefFileExt)
If FileDialog.sDefFileExt <> "" Then
If Right$(ShowSave.sFiles(1), Len(FileDialog.sDefFileExt)) <> FileDialog.sDefFileExt Then
ShowSave.sFiles(1) = ShowSave.sFiles(1) & IIf(InStr(FileDialog.sDefFileExt, ".") > 0, "", ".") & FileDialog.sDefFileExt
End If
End If

There.... better.
(If this comment was disrespectful, please report it.)

 
7/25/2006 7:07:06 AMIVan

Great Paul, this solve my projects issue. Thanks very much Paul Mather . GBU!
(If this comment was disrespectful, please report it.)

 
10/26/2006 5:24:31 PMKevin Ritch

Excellent Paul

A belated 5 globes from me.

Cheers,
Kevin
(If this comment was disrespectful, please report it.)

 
2/20/2007 9:49:33 AMOrhan Candan

thanks
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.