یک خورده درهمه ولی همه چیز داره
Option Explicit
Private Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Const BIF_RETURNONLYFSDIRS = 1
Const MAX_PATH = 260
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpBI As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
'************************************************* ************************************
'************************************************* ************************************
'************************************************* ************************************
'************************************************* ************************************
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
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Dim OFName As OPENFILENAME
Public Function ShowOpen(Optional MFilter As String) As String
'Set the structure size
OFName.lStructSize = Len(OFName)
'Set the owner window
OFName.hwndOwner = MainForm.hwnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Set the filet
If MFilter = "" Then
OFName.lpstrFilter = "Supported Format فایلهای عمومی" + Chr$(0) + "*.BMP;*.PSD;*.JPG;*.Tif;*.PCX" + Chr$(0) + " All تمام فایلها" + Chr$(0) + "*.*" + Chr$(0) + "PhotoShop PSD فایلهای فتوشاپ" + Chr$(0) + "*.psd"
Else
OFName.lpstrFilter = MFilter
End If
'Create a buffer
OFName.lpstrFile = Space$(254)
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = App.Path '"C:\"
'Set the dialog title
OFName.lpstrTitle = "Open File "
'no extra flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
ShowOpen = Trim$(OFName.lpstrFile)
Else
ShowOpen = ""
End If
End Function
Public Function ShowSave(Optional MFilter As String) As String
'Set the structure size
OFName.lStructSize = Len(OFName)
'Set the owner window
OFName.hwndOwner = MainForm.hwnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Set the filet
If MFilter = "" Then
OFName.lpstrFilter = "PhotoShop (*.psd)" + Chr$(0) + "*.psd" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
Else
OFName.lpstrFilter = MFilter
End If
'Create a buffer
OFName.lpstrFile = Space$(254)
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = App.Path '"C:\"
'Set the dialog title
OFName.lpstrTitle = "Save File "
'no extra flags
OFName.flags = 0
'Show the 'Save File'-dialog
If GetSaveFileName(OFName) Then
ShowSave = Trim$(OFName.lpstrFile)
Else
ShowSave = ""
End If
End Function
Public Function BrowesFolder(InitDir As String) As String
Dim iNull As Integer, lpIDList As Long, lResult As Long
Dim sPath As String, udtBI As BrowseInfo
With udtBI
'Set the owner window
.hwndOwner = MainForm.hwnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("C:\", "")
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
BrowesFolder = sPath
End Function
Public Function RepairPath(MyPath As String) As String
RepairPath = IIf(Right(MyPath, 1) = "\", MyPath, MyPath & "\")
End Function