Board logo

标题: 动态弹出另存为对话框?(不用Commondialog控件) [打印本页]

作者: junki    时间: 2004-12-18 08:50     标题: 动态弹出另存为对话框?(不用Commondialog控件)

'动态弹出另存为对话框?(不用Commondialog控件)
'用API函数!
'---------------------------------------------------------------
'模块中声明:
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 GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

Dim OFName As OPENFILENAME

Private Sub Command2_Click()
    Dim sFile As String
    sFile = ShowSave
    If sFile <> "" Then
          MsgBox "You chose this file: " + sFile
    Else
          MsgBox "You pressed cancel"
    End If
End Sub

Private Sub Form_Load()
    Command2.Caption = "ShowSave"
End Sub

Private Function ShowSave() As String
    OFName.lStructSize = Len(OFName)
      
    OFName.hwndOwner = Me.hWnd
      
    OFName.hInstance = App.hInstance
      
    OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
      
    OFName.lpstrFile = Space$(254)
      
    OFName.nMaxFile = 255
      
    OFName.lpstrFileTitle = Space$(254)
      
    OFName.nMaxFileTitle = 255
      
    OFName.lpstrInitialDir = "C:"
      
    OFName.lpstrTitle = "Save File"
      
    OFName.flags = 0

      
    If GetSaveFileName(OFName) Then
          ShowSave = Trim$(OFName.lpstrFile)
    Else
          ShowSave = ""
    End If

End Function

作者: Nothing    时间: 2004-12-19 01:39

这个贴子不错,支持,顶一下
作者: 只爱陌生人    时间: 2006-4-1 17:42

嗯,不错,不知道这个可不可以解决有时候出现的DLL不能调用的问题呀?是不是这样就可以让VB的控件的兼容性更好呢?
作者: Nothing    时间: 2006-4-1 18:20

不会出问题,调用的是系统的API




欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/) Powered by Discuz! 6.0.0