马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
cad2014里不能引用原来vb6.0的common dialog的控件,我在网上,也查了用api的方法调用comdlg32.dll的方法,但是都不起作用,请各位大神帮忙看一下怎么解决!
- Public Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOPENFILENAME As OPENFILENAME) As Long
- Public Declare PtrSafe Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOPENFILENAME As OPENFILENAME) As Long
- 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
- Public Const OFN_OVERWRITEPROMPT = &H2
- Public Const OFN_HIDEREADONLY = &H4
- Public Const OFN_PATHMUSTEXIST = &H800
- Public Const OFN_FILEMUSTEXIST = &H1000
- Public Function GetDialog(ByVal sMethod As String, ByVal sTitle As String, ByVal FileType As String, ByVal sFileName As String) As String
- 'Public Function GetDialog(ByVal sMethod As String, ByVal sTitle As String, ByVal sFileName As String) As String
- Err.Clear
- On Error GoTo myError
- Dim rtn As Long, Pos As Integer
- Dim file As OPENFILENAME
- 'file.lStructSize = Len(file)
- 'file.hInstance = ThisDrawing.Application.HWND32
- file.hInstance = ThisDrawing.HWND32
- file.lpstrFile = sFileName & VBA.String$(255 - VBA.Len(sFileName), 0)
- file.nMaxFile = 255
- file.lpstrFileTitle = VBA.String$(255, 0)
- file.nMaxFileTitle = 255
- file.lpstrInitialDir = ""
- 'file.lpstrFilter = "Excel文件" & vbNullChar & "*.xls" '这个为xls文件
- file.lpstrFilter = FileType & vbNullChar & FileType '这个为xls文件"
- file.lpstrTitle = sTitle
- file.lStructSize = Len(file)
- If VBA.UCase(sMethod) = "OPEN" Then
- file.flags = OFN_HIDEREADONLY + OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST
- rtn = GetOpenFileName(file)
- Else
- file.lpstrDefExt = "exe"
- file.flags = OFN_HIDEREADONLY + OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT
- rtn = GetSaveFileName(file)
- End If
- If rtn > 0 Then
- Pos = InStr(file.lpstrFile, VBA.Chr$(0))
- If Pos > 0 Then
- GetDialog = VBA.Left$(file.lpstrFile, Pos - 1)
- End If
- End If
- Exit Function
- myError:
- 'Err.Raise
- GetDialog = "FileName Error!"
- End Function
|