Flux rss

[VB6/VBA] The CommonDialog control

Published by netty5, last update on Thursday November 6, 2008 07:00:33 AM by netty5

[VB6/VBA] The CommonDialog control




The various functions of control CommonDialog

Here is a list of all the available constants,although they are not used in all functions, they will enable further researches.

The available functions with CommonDialog


The dialog box> Open File
The dialog box> Save as
The dialog box> Print
The dialog box> Selecting a policy

Getting started


A form> Name=Dialog
CommonDialog control> Name=CMDialog1

Button1>Caption =Open File
Code in CommandX_Click()>Ret =cmd_Open

Button2>Caption=Save as
Code in Clic Ret = cmd_Open()

Button3> Caption =Print
Code in CommandX_Click()>Ret = cmd_Print()

Button4> Caption = Policy
Code in CommandX_Click()> Ret = cmd_Policy()

An example of a standard module


Option Explicit

Public Filter1 As String
Public Filter2 As String
Public Filter 3 As String
Public Filter 4 As String
Public Filter 5 As String
Public Filter As String
Public Filter 7 As String

Public Const DLG_FILE_OPEN = 1
Public Const DLG_FILE_SAVE = 2
Public Const DLG_COLOR = 3
Public Const DLG_FONT = 4
Public Const DLG_Print = 5
Public Const DLG_HELP = 6

'File Open/Save Dialog Flags
Public Const OFN_READONLY = &H1&
Public Const OFN_OVERWRITEPROMPT = &H2&
Public Const OFN_HIDEREADONLY = &H4&
Public Const OFN_NOCHANGEDIR = &H8&
Public Const OFN_SHOWHELP = &H10&
Public Const OFN_NOVALIDATE = &H100&
Public Const OFN_ALLOWMULTISELECT = &H200&
Public Const OFN_EXTENSIONDIFFERENT = &H400&
Public Const OFN_PATHMUSTEXIST = &H800&
Public Const OFN_FILEMUSTEXIST = &H1000&
Public Const OFN_CREATEPROMPT = &H2000&
Public Const OFN_SHAREAWARE = &H4000&
Public Const OFN_NOREADONLYRETURN = &H8000&

'Color Dialog Flags
Public Const CC_RGBINIT = &H1&
Public Const CC_FULLOPEN = &H2&
Public Const CC_PREVENTFULLOPEN = &H4&
Public Const CC_SHOWHELP = &H8&

'Fonts Dialog Flags
Public Const CF_SCREENFONTS = &H1&
Public Const CF_PRINTERFONTS = &H2&
Public Const CF_BOTH = &H3&
Public Const CF_SHOWHELP = &H4&
Public Const CF_INITTOLOGFONTSTRUCT = &H40&
Public Const CF_USESTYLE = &H80&
Public Const CF_EFFECTS = &H100&
Public Const CF_APPLY = &H200&
Public Const CF_ANSIONLY = &H400&
Public Const CF_NOVECTORFONTS = &H800&
Public Const CF_NOSIMULATIONS = &H1000&
Public Const CF_LIMITSIZE = &H2000&
Public Const CF_FIXEDPITCHONLY = &H4000&
Public Const CF_WYSIWYG = &H8000&         'must also have CF_SCREENFONTS & CF_PRINTERFONTS
Public Const CF_FORCEFONTEXIST = &H10000
Public Const CF_SCALABLEONLY = &H20000
Public Const CF_TTONLY = &H40000
Public Const CF_NOFACESEL = &H80000
Public Const CF_NOSTYLESEL = &H100000
Public Const CF_NOSIZESEL = &H200000

'Printer Dialog Flags
Public Const PD_ALLPAGES = &H0&
Public Const PD_SELECTION = &H1&
Public Const PD_PAGENUMS = &H2&
Public Const PD_NOSELECTION = &H4&
Public Const PD_NOPAGENUMS = &H8&
Public Const PD_COLLATE = &H10&
Public Const PD_PRINTTOFILE = &H20&
Public Const PD_PRINTSETUP = &H40&
Public Const PD_NOWARNING = &H80&
Public Const PD_RETURNDC = &H100&
Public Const PD_RETURNIC = &H200&
Public Const PD_RETURNDEFAULT = &H400&
Public Const PD_SHOWHELP = &H800&
Public Const PD_USEDEVMODECOPIES = &H40000
Public Const PD_DISABLEPRINTTOFILE = &H80000
Public Const PD_HIDEPRINTTOFILE = &H100000

'Help Constants
Public Const HELP_CONTEXT = &H1           'Display topic in ulTopic
Public Const HELP_QUIT = &H2              'Terminate help
Public Const HELP_INDEX = &H3             'Display index
Public Const HELP_CONTENTS = &H3
Public Const HELP_HELPONHELP = &H4        'Display help on using help
Public Const HELP_SETINDEX = &H5          'Set the current Index for multi index help
Public Const HELP_SETCONTENTS = &H5
Public Const HELP_CONTEXTPOPUP = &H8
Public Const HELP_FORCEFILE = &H9
Public Const HELP_KEY = &H101             'Display topic for keyword in offabData
Public Const HELP_COMMAND = &H102
Public Const HELP_PARTIALKEY = &H105      'call the search engine in winhelp

Function add(a$) As String
    If a$ <> "" Then a$ = a$ + "|"
    add = a$
End Function

'Command lines ...
'FileName = cmd_open()
'If 1 filter more >> FileName = cmd_open("txt") 
'If multiple filters, initialize filter1 to 4 
'routine adds all the filter
Function cmd_open(Optional Filt1 As String) As String
Dim CTRL$, a$, b$, F1$, F2$, F3$, F4$
CTRL$ = Chr$(13) + Chr$(10)
    If Filt1 <> "" Then
        a$ = " File (*." & Filt1 & ") | *." & Filt1
    End If
    If Filter1 <> "" Then
        a$ = add(a$)
        a$ = a$ + " File (*." & Filter1 & ") | *." & Filter1
        Filter1 = ""
    End If
    If Filter2 <> "" Then
        a$ = add(a$)
        a$ = a$ + " File (*." & Filter2 & ") | *." & Filter2
        Filter2 = ""
    End If
    If Filter3 <> "" Then
        a$ = add(a$)
        a$ = a$ + " File (*." & Filter3 & ") | *." & Filter3
        Filter 3 = ""
    End If
    If Filter4 <> "" Then
        a$ = add(a$)
        a$ = a$ + " File (*." & Filter4 & ") | *." & Filter4
        Filter4 = ""
    End If
        a$ = add(a$)
        a$ = a$ + " All (*.*) | *.*"
    Dialog.CMDialog1.Filter = a$
    Dialog.CMDialog1.FilterIndex = 1
    Dialog.CMDialog1.FLAGS = CF_EFFECTS Or OFN_HIDEREADONLY Or CF_ANSIONLY
    Dialog.CMDialog1.Action = DLG_FILE_OPEN
    cmd_open = Dialog.CMDialog1.FileName
    Unload Dialog
End Function

Function cmd_Policy()
    Dialog.CMDialog1.DialogTitle = "Select policy"
    Dialog.CMDialog1.FLAGS = CF_WYSIWYG + CF_BOTH + CF_SCALABLEONLY
    Dialog.CMDialog1.Action = DLG_FONT
    Filter1 = Dialog.CMDialog1.FontName
    Filter4 = Dialog.CMDialog1.FontSize
    Filter5 = Dialog.CMDialog1.FontBold
    Filter6 = Dialog.CMDialog1.FontItalic
    cmd_Policy = Dialog.CMDialog1.FontName
End Function

Function cmd_Print()
    Dialog.CMDialog1.FLAGS = PD_ALLPAGES
    Dialog.CMDialog1.Min = 1
    Dialog.CMDialog1.Max = 100
    Dialog.CMDialog1.FromPage = 1
    Dialog.CMDialog1.ToPage = 100
    Dialog.CMDialog1.Action = DLG_Print
    Unload Dialog
End Function

'Filt1 = file extension to be searched for
'eg: TXT ou EXE
'routine adds all the filter(*.*)
Function cmd_SaveAs(Filt1 As String) As String
    Filter1 = "File (*." & Filt1 & ") | *." & Filt1
    Filter2 = "All (*.*) | *.*"
    Dialog.CMDialog1.Filter = Filter1 + "|" + Filter2
    Dialog.CMDialog1.FilterIndex = 1
    Dialog.CMDialog1.FLAGS = OFN_HIDEREADONLY
    Dialog.CMDialog1.Action = DLG_FILE_SAVE
    cmd_SaveAs = Dialog.CMDialog1.FileName
    Unload Dialog

End Function
Processes - control - control.exe control.exe (control stands for Control Panel) is a Windows NT/2000/XP generic process which corresponds to the control panel. The file that corresponds to this process is normally found in the directory "%SystemRoot%\system32\control.exe" (where... en.kioskea.net/processus/control-exe.php3
Quality - COBIT (Control Objectives for Information and related Technologies) COBIT ( Control Objectives for Information and related Technologies) is a methodology for evaluating a company's IT department that was published in 1996 by the IT Governance Institute and the ISACA (Information Systems Audit and Control Association)... en.kioskea.net/qualite/cobit.php3
The Add/Remove Programs icon is missing in Control Panel The Add/Remove Programs icon is missing in Control Panel When trying to add a program on your computer system, you suddenly noticed that the specific icon is missing. This can be due to Appwiz.cpl missing or damaged. This applet... en.kioskea.net/faq/sujet-465-the-add-remove-programs-icon-is-missing-in-control-panel
Activate Volume Control in the taskbarActivate Volume Control in the taskbar It may happen that after some configurations on your computer system, the icon volume control on your task bar disappears. Below is an indication how to recover same. The first step is to go to... en.kioskea.net/faq/sujet-659-activate-volume-control-in-the-taskbar
Creating a shortcut to Control Panel optionCreating a shortcut to Control Panel option Below is a simple tips for creating a shortcut to Control Panel on your Desktop. Go to ‘Menu Start’ and select/open ‘Control Panel’. Then select the option you want to create... en.kioskea.net/faq/sujet-428-creating-a-shortcut-to-control-panel-option
DirectX in the control panel?Introduction This is a trick to allow you to install the device easy adjustment of DirectX on your Windows Control Panel. DirectX in the control panel Windows Conclusion DirectX in the control panel Windows The Windows Control... en.kioskea.net/faq/sujet-55-directx-in-the-control-panel
Network Controller driver???? (Solved)Dear all Due to a virus problem, I have had to install windows (xp) on my laptop but in device manager under other devices the following item has yellow question marks:- network controller As network controller driver is missing I can't connect... en.kioskea.net/forum/affich-5494-network-controller-driver
Network Controller is not Working!!!!________________________________________ Dear all Due to a virus problem, I have had to install windows (xp) on my laptop but in device manager under other devices the following item has yellow question marks:- network controller As network controller... en.kioskea.net/forum/affich-5493-network-controller-is-not-working
ActiveX Control and VirusMy wife was on my PC and asked what an ActiveX control was and why my computer was saying it needed to download it... Here’s my mistake... I assumed she was on YouTube or something and didn't look as what it said. Needless to say it was a... en.kioskea.net/forum/affich-473-activex-control-and-virus
Download My Voice ControllerMy Voice Controller is a tool allowing to simulate the manipulation of the mouse and the keyboard by using your voice only. It is a tool necessarily established for the online players " gamers " to attend them with the simultaneous manipulation of the... en.kioskea.net/telecharger/telecharger-587-my-voice-controller
Download Face Control Plug-inWhen you want to touch up a picture, the facial party is the most delicate. If this party is missed, though you make on the rest of the body, result will not be very convincing. Face Control is not a tool of modification photograph as such, but a... en.kioskea.net/telecharger/telecharger-378-face-control-plug-in
Download Control KidsParental control software which filters all the web sites with pornographic or violent contents, blocks the downloads of certain dangerous programs, transmission of personal data such as the e-mail, telephone or bank cards numbers. Control Kids... en.kioskea.net/telecharger/telecharger-1462-control-kids
Facebook enhances privacy controlsFacebook logo displayed on a computer screen. Facebook said Tuesday it is giving users more control over who gets to see personal information posted in profiles at the hot social-networking website. Facebook said Tuesday it is giving users more... en.kioskea.net/actualites/facebook-enhances-privacy-controls-10213-actualite.php3
China seems to ease Wikipedia controlsA woman surfs the Internet at a cafe in Beijing. Chinese censors appear to have relaxed their control of Wikipedia -- a popular online encyclopaedia -- as reports from users suggested it was accessible in at least parts of the country. Chinese... en.kioskea.net/actualites/china-seems-to-ease-wikipedia-controls-10258-actualite.php3
PC Assembly - Hard drive installation The motherboard usually has two IDE (Integrated Device Electronics) connectors: The first connector is known as the primary device controller; The second is known as the secondary device controller. Each connector can take two IDE devices connected... en.kioskea.net/assemblage/branchement-disques-durs.php3
Windows networking To configure each computer, simply go to the control panel, then double-click "network connections" and right-click "local area connection", then choose properties! The local area connection window displays the various protocols installed. To be able... en.kioskea.net/configuration-reseau/configurer-reseau-windows-xp.php3
WiFi - Data link layer and access methods The data link layer of the 802.11 standard is composed of two sublayers: the Logical Link Control layer (or LLC for short), and the Media Access Control layer (or MAC). The MAC layer defines two different access methods: The CSMA/CA method, which... en.kioskea.net/wifi/wifimac.php3