The new vbAccelerator Site - more VB and .NET Code and Controls
name="sectop">
Source Code
  Code Libraries  
 

CommonDialog/Direct

 
 

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)

  UpdatedUpdated! 21 March 2000  
  Added VB6 binary.  
  UpdatedUpdated! 1 November 1999  
  Added support for templates, based on the code written by Cayce Cochran.  
  UpdatedUpdated! 20 February 1999  
  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.
 
  Updated! 10 December 1998  
  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.  
  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.  
  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.  
  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).  
  Print Setup failed to return number of copies and collation option when collation was turned on for some printer drivers.  
  Thanks to Larry Kuhn for spotting these problems.  

 



Overview
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.

Features
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:

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

   
 

About  Contribute  Send Feedback  Privacy

Copyright © 1998-2000, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 21 March 2000