Results 1 to 4 of 4

Thread: how to call common dialog using win dll

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    India,Karnataka,Bangalore
    Posts
    61

    how to call common dialog using win dll

    please help me to dlls to call fileopen,filesave,filesaveas dialog
    boxes

    its giving an error stating user defined datatype not found

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    If you need to do it with API then:
    Code:
    ' This code is licensed according to the terms and conditions listed here.
    
    ' Declarations and such needed for the example:
    ' (Copy them to the (declarations) section of a module.)
    Public Type OPENFILENAME
    	lStructSize As Long
    	hwndOwner As Long
    	hInstance As Long
    	lpstrFilter As String
    	lpstrCustomFilter As String
    	nMaxCustomFilter As Long
    	nFilterIndex As Long
    	lpstrFile As String
    	nMaxFile As Long
    	lpstrFileTitle As String
    	nMaxFileTitle As Long
    	lpstrInitialDir As String
    	lpstrTitle As String
    	flags As Long
    	nFileOffset As Integer
    	nFileExtension As Integer
    	lpstrDefExt As String
    	lCustData As Long
    	lpfnHook As Long
    	lpTemplateName As String
    End Type
    Public Const OFN_FILEMUSTEXIST = &H1000
    Public Const OFN_HIDEREADONLY = &H4
    Public Const OFN_PATHMUSTEXIST = &H800
    Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (lpofn _
    	As OPENFILENAME) As Long
    
    ' *** Place the following code inside a form window.
    
    Private Sub Command1_Click()
    	Dim filebox As OPENFILENAME  ' open file dialog structure
    	Dim fname As String          ' filename the user selected
    	Dim result As Long           ' result of opening the dialog
    	
    	' Configure how the dialog box will look
    	With filebox
    		' Size of the structure.
    		.lStructSize = Len(filebox)
    		' Handle to window opening the dialog.
           		.hwndOwner = Me.hWnd
    		' Handle to calling instance (not needed).
    		.hInstance = 0
    		' File filters to make available: Text Files and All Files
    		.lpstrFilter = "Text Files (*.txt)" & vbNullChar & "*.txt" & vbNullChar & _
    			"All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
    		'.lpstrCustomFilter is ignored -- unused string
    		.nMaxCustomFilter = 0
    		' Default filter is the first one (Text Files, in this case).
    		.nFilterIndex = 1
    		' No default filename.  Also make room for received
    		' path and filename of the user's selection.
    		.lpstrFile = Space(256) & vbNullChar
    		.nMaxFile = Len(.lpstrFile)
    		' Make room for filename of the user's selection.
    		.lpstrFileTitle = Space(256) & vbNullChar
    		.nMaxFileTitle = Len(.lpstrFileTitle)
    		' Initial directory is C:\.
    		.lpstrInitialDir = "C:\" & vbNullChar
    		' Title of file dialog.
    		.lpstrTitle = "Select a File" & vbNullChar
    		' The path and file must exist; hide the read-only box.
    		.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
    		' The rest of the options aren't needed.
    		.nFileOffset = 0
    		.nFileExtension = 0
    		'.lpstrDefExt is ignored -- unused string
    		.lCustData = 0
    		.lpfnHook = 0
    		'.lpTemplateName is ignored -- unused string
    	End With
    	
    	' Display the dialog box.
    	result = GetOpenFileName(filebox)
    	If result <> 0 Then 
    		' Remove null space from the file name.
    		fname = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, vbNullChar) - 1)
    		Debug.Print "The selected file: "; fname
    	End If
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    OPENFILENAME info
    Code:
    lStructSize
    The size in bytes of the structure. 
    hwndOwner
    A handle to the window opening the file dialog box. 
    hInstance
    If using a dialog box template, this is a handle to the memory block of the dialog box template to use. If using the default dialog box, set to 0. 
    lpstrFilter
    The entries in the File Type drop box. The format of the string is "name of file type" & vbNullChar & "mask" & vbNullChar ... for as many types, where name of file type is the text that appears in the list and mask is the extension mask. The string must end with a double vbNullChar. 
    lpstrCustomFilter
    Similar to lpstrFilter, but holds only one file type name/mask pair that specifies a user-defined file type. If unused, set to an empty string. 
    nMaxCustFilter
    The size in bytes of the string contained in lpstrCustomFilter. 
    nFilterIndex
    The number (#1, #2, etc.) of data type specified lpstrFilter should be the default one. 
    lpstrFile
    Set it as a series of blank spaces. If you want to specify a default filename, set this string to that default filename and pad it with spaces. Receives the complete path and filename of the file(s) the user selects. If multiple files are selected, each filename is separated by vbNullChar, and the entire string will end with a double vbNullChar. 
    nMaxFile
    The length in characters of lpstrFile. 
    lpstrFileTitle
    Very similar to lpstrFile, but only receives the filename of the selected file. If multiple files are selected, this is not set to any useful data. 
    nMaxFileTitle
    The length in characters of lpstrFileTitle. 
    lpstrInitialDir
    The default directory to look in. 
    lpstTitle
    The text that appears in the dialog box's title bar. 
    flags
    Zero or more of the following flags specifying how to create the file dialog box. Some of these flags will be set by the function after the call to reflect the user's selections. 
    OFN_ALLOWMULTISELECT
    Allow the user to select multiple files (Open File dialog box only). 
    OFN_CREATEPROMPT
    Prompt if a non-existing file is chosen. 
    OFN_ENABLEHOOK
    Use the function specified by lpfnHook to process the dialog box's messages. 
    OFN_ENABLESIZING
    Windows 98, 2000: Allow the dialog box to be resized. This is selected by default unless a hook function or custom template is specified. 
    OFN_ENABLETEMPLATE
    Use the dialog box template specifed by hInstance and lpTemplateName. 
    OFN_ENABLETEMPLATEHANDLE
    Use the preloaded dialog box template specified by hInstance. 
    OFN_EXPLORER
    Use Windows Explorer-like additions to the file dialog box. This is selected by default unless a hook function or custom template is specified. 
    OFN_EXTENSIONDIFFERENT
    The function sets this flag if the user selects a file with an extension different than the one specified by lpstrDefExt. 
    OFN_FILEMUSTEXIST
    Only allow the selection of existing files. 
    OFN_HIDEREADONLY
    Hide the Open As Read Only check box (Open File dialog box only). 
    OFN_LONGNAMES
    Have the file dialog use long file names. This is automatically specified unless the Explorer-type extensions are not used. 
    OFN_NOCHANGEDIR
    Don't change Windows's current directory to match the one chosen in the dialog box. 
    OFN_NODEREFERENCELINKS
    If a shortcut file (.lnk or .pif) is chosen, return the shortcut file itself instead of the file or directory it points to. 
    OFN_NOLONGNAMES
    Have the file dialog use short (8.3) file names. This is ignored unless a file dialog without Explorer-type extensions are not used. 
    OFN_NONETWORKBUTTON
    Hide and disable the Network button in the dialog box. 
    OFN_NOREADONLYRETURN
    The function sets this flag if the selected file is not read-only (Open File dialog box only). 
    OFN_NOTESTFILECREATE
    Do not create a test file before the box closes. Normally, this check is done to verify that the disk exists, that there is sufficient disk space, etc. However, this check should not be used on a create-nonmodify network share. Specifying this flag prevents this test from being done. 
    OFN_NOVALIDATE
    Don't check the filename for invalid characters. 
    OFN_OVERWRITEPROMPT
    Prompt the user if the chosen file already exists (Save File dialog box only). 
    OFN_PATHMUSTEXIST
    Only allow the selection of existing paths. 
    OFN_READONLY
    Check the Open As Read Only box. This flag is set after the function call if the box is checked after the user clicks OK. 
    OFN_SHAREAWARE
    Ignore any file sharing violations. 
    OFN_SHOWHELP
    Show the Help button in the dialog box. The button sends the WM_HELP message to the hook function specified by the structure. If no hook function is used, the Help button will do nothing. 
    nFileOffet
    Receives the zero-based index specifying where in lpstrFile the pathname ends and the filename begins. 
    nFileExtension
    Receives the zero-based index specifying where in lpstrFile the file extension begins. 
    lpstrDefExt
    The default extension of a file (only for the Save dialog box). If a file is chosen with the *.* mask, the file gets this extension. Don't include the period. 
    lCustData
    Information to pass to the hook function specified by lpfnHook whenever it is called. 
    lpfnHook
    A pointer to a hook function to use to processes the dialog box's messages. For file dialogs with Explorer-type extensions, this is a pointer to a OFNHookProc hook function. For file dialogs without those extensions, this is a pointer to a OFNHookProcOldStyle hook function. If not using a hook function, set to 0. 
    lpTemplateName
    The name of the dialog box template specified by hInstance, if needed. 
    Constant Definitions
    
    Const OFN_ALLOWMULTISELECT = &H200
    Const OFN_CREATEPROMPT = &H2000
    Const OFN_ENABLEHOOK = &H20
    Const OFN_ENABLESIZING = &H800000
    Const OFN_ENABLETEMPLATE = &H40
    Const OFN_ENABLETEMPLATEHANDLE = &H80
    Const OFN_EXPLORER = &H80000
    Const OFN_EXTENSIONDIFFERENT = &H400
    Const OFN_FILEMUSTEXIST = &H1000
    Const OFN_HIDEREADONLY = &H4
    Const OFN_LONGNAMES = &H200000
    Const OFN_NOCHANGEDIR = &H8
    Const OFN_NODEREFERENCELINKS = &H100000
    Const OFN_NOLONGNAMES = &H40000
    Const OFN_NONETWORKBUTTON = &H20000
    Const OFN_NOREADONLYRETURN = &H8000
    Const OFN_NOTESTFILECREATE = &H10000
    Const OFN_NOVALIDATE = &H100
    Const OFN_OVERWRITEPROMPT = &H2
    Const OFN_PATHMUSTEXIST = &H800
    Const OFN_READONLY = &H1
    Const OFN_SHAREAWARE = &H4000
    Const OFN_SHOWHELP = &H10
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width