Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As- OPENFILENAME) As LongType 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 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然后在Form窗体上加一个文本框和按钮Caption属性为"打开".双击按钮加入下列代码:Private Sub Command1_Click() Dim ofn As OPENFILENAME Dim rtn As String ofn.lStructSize=len(ofn) ofn.hwndOwner=Me.hWnd ofn.hInstance=App.hInstance ofn.lpstrFilter="所有文件" ofn.lpstrFile=Space(254) ofn.nMaxFileTitle=255 ofn.lpstrInitialDir=app.path ofn.lpstrTitle="打开文件" ofn.flags=6148 rtn=GetOpenFileName(ofn) If rtn>=1 then Text1.Text=ofn.lpstrFile Else Text1.Text="Cancel Was Pressed" End If End Sub运行程序,点击"打开"按钮就会弹出打开文件对话框.选中任何文件再确定,Text1.Text就会显示任何文件名.
to happy_sea(开心海) 运行后并没有出现打开对话框,文本框中显示“Cancel Was Pressed”
lStructSize As Long
hwndOwner As long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile 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然后在Form窗体上加一个文本框和按钮Caption属性为"打开".双击按钮加入下列代码:Private Sub Command1_Click()
Dim ofn As OPENFILENAME
Dim rtn As String
ofn.lStructSize=len(ofn)
ofn.hwndOwner=Me.hWnd
ofn.hInstance=App.hInstance
ofn.lpstrFilter="所有文件"
ofn.lpstrFile=Space(254)
ofn.nMaxFileTitle=255
ofn.lpstrInitialDir=app.path
ofn.lpstrTitle="打开文件"
ofn.flags=6148
rtn=GetOpenFileName(ofn)
If rtn>=1 then
Text1.Text=ofn.lpstrFile
Else
Text1.Text="Cancel Was Pressed"
End If
End Sub运行程序,点击"打开"按钮就会弹出打开文件对话框.选中任何文件再确定,Text1.Text就会显示任何文件名.
运行后并没有出现打开对话框,文本框中显示“Cancel Was Pressed”
http://www.newasp.net/code/download.asp?softid=1122&downid=11&id=1122
要不你到http://www.newasp.net/code/vb/1122.html这个网页上自己找合适的地址来下载吧
或者把你的代码贴出来.