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
:P
只爱陌生人 2006-4-1 17:42
嗯,不错,不知道这个可不可以解决有时候出现的DLL不能调用的问题呀?是不是这样就可以让VB的控件的兼容性更好呢?