菜菜鸟求救:打开文件对话框 API 调用

csdntoll 2003-12-18 12:00:45
如何实现?谢谢!

搜索找到一篇介绍,如下,可是比较菜,没能实现,请帮帮忙:

http://search.csdn.net/expert/topic/51/5101/2001/1/11/57690.htm
...全文
36 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihonggen0 2003-12-18
  • 打赏
  • 举报
回复
那你得自己写程序打开文件了

如打开一个文本文件
Open "f:\d.txt" For Input As #1
Text1.Text = StrConv(InputB$(LOF(1), 1), vbUnicode)
Close #1
csdntoll 2003-12-18
  • 打赏
  • 举报
回复
谢谢李大斑竹热心回答,

如果,我要实现真正打开文件呢,谢谢,

If GetOpenFileName(OFName) Then
......
End If
lihonggen0 2003-12-18
  • 打赏
  • 举报
回复
或者是用CommonDialog控件

Private Sub Command1_Click()
On Error GoTo Err
CommonDialog1.CancelError = True
CommonDialog1.InitDir = "C:\Program Files"
CommonDialog1.Filter = "Jpg (*.JPG)|*.JPG|BMP(*.BMP)|*.BMP"
CommonDialog1.ShowOpen

Err:
If Err.Number = 32755 Then
MsgBox "你按了取消!", vbCritical, "系统提示"
End If
End Sub
lihonggen0 2003-12-18
  • 打赏
  • 举报
回复
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
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 Sub Form_Load()
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Me.hWnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the title
OFName.lpstrTitle = "Open File"
'No flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
End Sub

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧