The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
3 Code Libraries &nbsp


Take control over all the Windows Common Dialogs with this component

NOTE: this code has been superceded by the version at the new site.

Common Dialog Image

Download Code
VB5 code VB5 Control Binary (34kb) VB6 code VB6 Control Binary (34kb)
VB5 code VB5 Demonstration Project (15kb) VB6 code VB6 Demonstration Project (15kb)
VB5 code VB5 Full Source Code (73kb) VB6 code VB6 Full Source Code (73kb)

&nbsp UpdatedUpdated! 21 March 2000 &nbsp
&nbsp Added VB6 binary. &nbsp
&nbsp UpdatedUpdated! 1 November 1999 &nbsp
&nbsp Added support for templates, based on the code written by Cayce Cochran. &nbsp
&nbsp UpdatedUpdated! 20 February 1999 &nbsp
&nbsp The File Open Dialog did not return a usable result when set up to accept multiple filenames (OFN_ALLOWMULTISELECT flag). Now the filenames are returned and there is a new method ParseMultiFileName to convert the return value into a directory and an array of file titles.

Thanks to Steve Lager for pointing out this problem.
&nbsp Updated! 10 December 1998 &nbsp
&nbsp Improved Hook Support. Now all Common Dialogs (except the Print dialog) can be centred to a form or to the screen with just one line of code. See the code article Centre a Common Dialog - The Easy and the Hard Way for more details. Hooks also allows you to capture a Common Dialog into your own form - see create a VB style Open Project dialog for a demonstration. &nbsp
&nbsp Page Setup Dialog converted page sizes in inches into integer values. A new Page Setup method, VBPageSetupDlg2 has been added which correctly returns the values with decimal places. &nbsp
&nbsp The Page Setup Dialog always overwrote default and minimum margins. It now sets margins to the default unless you explicitly request it not to with the PSD_MINMARGINS/PSD_MARGINS flags. &nbsp
&nbsp Print and Page Setup dialogs used to ignore the flags parameter passed in. This meant, for example, it was impossible to display the Print Setup dialog box (the Print dialog box was always shown). &nbsp
&nbsp Print Setup failed to return number of copies and collation option when collation was turned on for some printer drivers. &nbsp
&nbsp Thanks to Larry Kuhn for spotting these problems. &nbsp

Common Dialog/Direct is a new DLL or class library which shows how to completely replace COMDLG32.OCX through Visual Basic code. The main advantage of this is you no longer need to put a control on a form to use common dialogs - just declare an instance of the class and you have a straight replacement. You can also incorporate the Common Dialog/Direct code straight into your own project if you want to reduce dependency files when you ship your project.

This library is based on articles in MSDN and the VB library provided by Bruce McKinney in his excellent book Hardcore Visual Basic. It expands on both sources - the Hardcore VB library isn't a drop in replacement for the VB version, it has a completely new interface, whilst the main MSDN version was somewhat bug-ridden.

There are a number of areas where Common Dialog/Direct improves upon the implementation of COMDLG32.OCX.

Here is a sample of how to use Common Dialog/Direct:

&nbsp &nbsp Dim c As New cCommonDialog
&nbsp &nbsp With c
&nbsp &nbsp &nbsp &nbsp .DialogTitle = "Choose Text FIle"
&nbsp &nbsp &nbsp &nbsp .CancelError = True
&nbsp &nbsp &nbsp &nbsp .hWnd = Me.hWnd
&nbsp &nbsp &nbsp &nbsp .flags = OFN_FILEMUSTEXIST Or OFN_PATHMUSTEXIST
&nbsp &nbsp &nbsp &nbsp .InitDir = "C:\STEVEMAC"
&nbsp &nbsp &nbsp &nbsp .Filter = "Internet documents (*.HTM)|*.HTM|Text files (*.TXT)|*.TXT|All Files (*.*)|*.*"
&nbsp &nbsp &nbsp &nbsp .FilterIndex = 1
&nbsp &nbsp &nbsp &nbsp .ShowOpen
&nbsp &nbsp &nbsp &nbsp
&nbsp &nbsp &nbsp &nbsp txtFileName = .filename
&nbsp &nbsp &nbsp &nbsp txtFilter = .Filter
&nbsp &nbsp &nbsp &nbsp txtContents = GetFileText(.filename)
&nbsp &nbsp &nbsp &nbsp
&nbsp &nbsp End With

The sample code in the download exercises all the different dialogs.

TopBack to top
Source Code - What We're About!Back to Code Libraries
Source Code - What We're About!Back to Source Code Overview


AboutContributeSend FeedbackPrivacy

Copyright 1998-2000, Steve McMahon ( All Rights Reserved.
Last updated: 21 March 2000