1. 首页
  2. 编程语言
  3. VB
  4. 纯API 打开保存对话框

纯API 打开保存对话框

上传者: 2019-01-01 16:26:46上传 RAR文件 4.64KB 热度 51次
VB 纯API 打开保存对话框 Public Function FileDialog(FormObject As Form, SaveDialog As Boolean, ByVal Title As String, ByVal Filter As String, Optional ByVal FileName As String, Optional ByVal Extention As String, Optional ByVal InitDir As String) As String Dim OFN As OPENFILENAME Dim r As Long If Len(FileName) > MAX_PATH Then Call MsgBox("Filename Length Overflow", vbExclamation, App.Title + " - FileDialog Function"): Exit Function FileName = FileName + String(MAX_PATH - Len(FileName), 0) With OFN .lStructSize = Len(OFN) .hwndOwner = 0 .hInstance = App.hInstance .lpstrFilter = Replace(Filter, "|", vbNullChar) .lpstrFile = FileName .nMaxFile = MAX_PATH .lpstrFileTitle = Space$(MAX_PATH - 1) .nMaxFileTitle = MAX_PATH .lpstrInitialDir = InitDir .lpstrTitle = Title .flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or OFN_CREATEPROMPT .lpstrDefExt = Extention End With Dim L As Long L = GetTickCount If SaveDialog Then r = GetSaveFileName(OFN) Else r = GetOpenFileName(OFN) If GetTickCount - L < 20 Then OFN.lpstrFile = "" If SaveDialog Then r = GetSaveFileName(OFN) Else r = GetOpenFileName(OFN) End If If r = 1 Then FileDialog = Left$(OFN.lpstrFile, InStr(1, OFN.lpstrFile + vbNullChar, vbNullChar) - 1) End Function With OFN .lStructSize = Len(OFN) .hwndOwner = 0 .hInstance = App.hInstance .lpstrFilter = Replace(Filter, "|", vbNullChar) .lpstrFile = FileName .nMaxFile = MAX_PATH .lpstrFileTitle = Space$(MAX_PATH - 1) .nMaxFileTitle = MAX_PATH .lpstrInitialDir = InitDir .lpstrTitle = Title .flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or OFN_CREATEPROMPT .lpstrDefExt = Extention End With Dim L As Long L = GetTickCount If SaveDialog Then r = GetSaveFileName(OFN) Else r = GetOpenFileName(OFN) If GetTickCount - L < 20 Then OFN.lpstrFile = "" If SaveDialog Then r = GetSaveFileName(OFN) Else r = GetOpenFileName(OFN) End If If r = 1 Then FileDialog = Left$(OFN.lpstrFile, InStr(1, OFN.lpstrFile + vbNullChar, vbNullChar) - 1) End Function
用户评论