VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Common Dialog without OCX

by Manjula Dharmawardhana (1 Submission)
Category: Windows System Services
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (12 Votes)

Hi All,
The Perpose of this Progarm is to Use windows Common Dialog Control Control Without the COMDLG32.OCX file. This will work even if the File is not Present
This is only for Open and Save Functions. But You can append it to get Color and other Dialog Boxes too,
Just Send any comments to
[email protected]
Visit me at
https://www.manjulapra.com
Thank
You

Inputs
The Filter for the Common Dialog The Default Extention for the Common Dialog Optionally the Dialog Titile
Code Returns
The Path of the Selected File
Side Effects
None Identified
API Declarations
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private strfileName As OPENFILENAME
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter 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

Rate Common Dialog without OCX

'This Function sets the Filters for the Common Dialog
'It is basically the Same as in Commondialog OCX But when You want Multiple Filter Use as
'"All Files|*.*|Executable Files|*.exe"
Private Sub DialogFilter(WantedFilter As String)
  Dim intLoopCount As Integer
  strfileName.lpstrFilter = ""
  For intLoopCount = 1 To Len(WantedFilter)
    If Mid(WantedFilter, intLoopCount, 1) = "|" Then strfileName.lpstrFilter = _
    strfileName.lpstrFilter + Chr(0) Else strfileName.lpstrFilter = _
    strfileName.lpstrFilter + Mid(WantedFilter, intLoopCount, 1)
  Next intLoopCount
  strfileName.lpstrFilter = strfileName.lpstrFilter + Chr(0)
End Sub
'This is The Function To get the File Name to Open
'Even If U don't specify a Title or a Filter it is OK
Public Function fncGetFileNametoOpen(Optional strDialogTitle As String = "Open", Optional strFilter As String = "All Files|*.*", Optional strDefaultExtention As String = "*.*") As String
Dim lngReturnValue As Long
Dim intRest As Integer
  strfileName.lpstrTitle = strDialogTitle
  strfileName.lpstrDefExt = strDefaultExtention
  DialogFilter (strFilter)
  strfileName.hInstance = App.hInstance
  strfileName.lpstrFile = Chr(0) & Space(259)
  strfileName.nMaxFile = 260
  strfileName.flags = &H4
  strfileName.lStructSize = Len(strfileName)
  lngReturnValue = GetOpenFileName(strfileName)
  fncGetFileNametoOpen = strfileName.lpstrFile
End Function
'This Function Returns the Save File Name
'Remember, U have to Specify a Filter and default Extention for this
Public Function fncGetFileNametoSave(strFilter As String, strDefaultExtention As String, Optional strDialogTitle As String = "Save") As String
Dim lngReturnValue As Long
Dim intRest As Integer
  strfileName.lpstrTitle = strDialogTitle
  strfileName.lpstrDefExt = strDefaultExtention
  DialogFilter (strFilter)
  strfileName.hInstance = App.hInstance
  strfileName.lpstrFile = Chr(0) & Space(259)
  strfileName.nMaxFile = 260
  strfileName.flags = &H80000 Or &H4
  strfileName.lStructSize = Len(strfileName)
  lngReturnValue = GetSaveFileName(strfileName)
  fncGetFileNametoSave = strfileName.lpstrFile
End Function

Download this snippet    Add to My Saved Code

Common Dialog without OCX Comments

No comments have been posted about Common Dialog without OCX. Why not be the first to post a comment about Common Dialog without OCX.

Post your comment

Subject:
Message:
0/1000 characters