-
May 16th, 2021, 01:02 PM
#1
Thread Starter
PowerPoster
Show Select Unicode File by GetOpenFileNameW,comdlg32.dll
Code:
Private Type OPENFILENAME_WCHAR
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As Long
lpstrCustomFilter As Long
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As Long
nMaxFile As Long
lpstrFileTitle As Long
nMaxFileTitle As Long
lpstrInitialDir As Long
lpstrTitle As Long
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As Long
End Type
Private Const OFN_READONLY = &H1
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_SHOWHELP = &H10
Private Const OFN_ENABLEHOOK = &H20
Private Const OFN_ENABLETEMPLATE = &H40
Private Const OFN_ENABLETEMPLATEHANDLE = &H80
Private Const OFN_NOVALIDATE = &H100
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_EXTENSIONDIFFERENT = &H400
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_CREATEPROMPT = &H2000
Private Const OFN_SHAREAWARE = &H4000
Private Const OFN_NOREADONLYRETURN = &H8000
Private Const OFN_NOTESTFILECREATE = &H10000
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOLONGNAMES = &H40000
Private Const OFN_EXPLORER = &H80000
Private Const OFN_NODEREFERENCELINKS = &H100000
Private Const OFN_LONGNAMES = &H200000
Private Const OFN_SHAREFALLTHROUGH = 2
Private Const OFN_SHARENOWARN = 1
Private Const OFN_SHAREWARN = 0
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameW" ( _
pOpenfilename As OPENFILENAME_WCHAR) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameW" ( _
pOpenfilename As OPENFILENAME_WCHAR) As Long
' ?ffnen-Dialog
Public Function ShowOpenDlg(Optional strFilter As String, _
Optional strTitel As String, Optional strInitDir As String, Optional Hwnd As Long) As String
Dim lngOpenFileName As OPENFILENAME_WCHAR
Dim lngAnt As Long
Dim strFile As String
If strTitel = "" Then strTitel = "open file"
strFilter = IIf(strFilter = "", "All files (*.*)|*.*", strFilter)
With lngOpenFileName
.lStructSize = Len(lngOpenFileName)
.hwndOwner = Hwnd
.hInstance = App.hInstance
strFilter = Replace$(strFilter, "|", vbNullChar)
' Der Filter muss durch 2 NullChars terminiert werden
Do Until Right$(strFilter, 2) = vbNullChar & vbNullChar
strFilter = strFilter & vbNullChar
Loop
strFile = String$(512, 0) ' Sollte bei Multiselect vergr??ert werden.
.lpstrFilter = StrPtr(strFilter)
.lpstrFile = StrPtr(strFile)
.nMaxFile = Len(strFile)
.lpstrInitialDir = StrPtr(strInitDir)
.lpstrTitle = StrPtr(strTitel)
.flags = OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST
' Or OFN_ALLOWMULTISELECT Or OFN_EXPLORER
lngAnt = GetOpenFileName(lngOpenFileName)
If lngAnt Then
strFile = TrimNull(strFile)
ShowOpenDlg = strFile
Else
ShowOpenDlg = ""
End If
End With
End Function
' Speichern-Dialog
Public Function ShowSaveDlg(Optional strFilter As String, _
Optional strTitel As String, Optional strInitDir As String, Optional Hwnd As Long) As String
Dim lngOpenFileName As OPENFILENAME_WCHAR
Dim lngAnt As Long
Dim strFile As String
If strTitel = "" Then strTitel = "Save File"
strFilter = IIf(strFilter = "", "All files (*.*)|*.*", strFilter)
With lngOpenFileName
.lStructSize = Len(lngOpenFileName)
.hwndOwner = Hwnd
.hInstance = App.hInstance
strFilter = Replace$(strFilter, "|", vbNullChar)
Do Until Right$(strFilter, 2) = vbNullChar & vbNullChar
strFilter = strFilter & vbNullChar
Loop
strFile = String$(512, 0)
.lpstrFilter = StrPtr(strFilter)
.lpstrFile = StrPtr(strFile)
.nMaxFile = Len(strFile)
.lpstrInitialDir = StrPtr(strInitDir)
.lpstrTitle = StrPtr(strTitel)
.flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or _
OFN_CREATEPROMPT
lngAnt = GetSaveFileName(lngOpenFileName)
If lngAnt Then
strFile = TrimNull(strFile)
ShowSaveDlg = strFile
Else
ShowSaveDlg = ""
End If
End With
End Function
' Trim Funktion für vbNullChars
Public Function TrimNull(ByVal Text As String) As String
Dim lngStart As Long
Dim lngEnd As Long
lngEnd = Len(Text)
For lngStart = 1 To lngEnd
If Asc(Mid$(Text, lngStart, 1)) <> 0 Then
For lngEnd = lngEnd To lngStart Step -1
If Asc(Mid$(Text, lngEnd, 1)) <> 0 Then
TrimNull = Mid$(Text, lngStart, lngEnd - lngStart + 1)
Exit Function
End If
Next lngEnd
End If
Next lngStart
End Function
-
May 16th, 2021, 05:42 PM
#2
Re: Show Select Unicode File by GetOpenFileNameW,comdlg32.dll
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|