vb中记事本程序的调用

用commondialog打开一个打开文件对话空然后如何调用记事本打开选择的文件。谢谢... 用commondialog打开一个打开文件对话空

然后如何调用记事本打开选择的文件。

谢谢
展开
 我来答
秋色烽火
2007-12-07 · TA获得超过1.2万个赞
知道大有可为答主
回答量:1.5万
采纳率:37%
帮助的人:1.2亿
展开全部
新建一个模块,加入如下代码

'====================================================
'调用API打开对话框声明
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (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
'======================================================�

在窗体上添加一个按钮 commandbutton1
加入如下代码:

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 = "文本文档(*.txt)" & Chr(0) & "*.txt" & Chr(0) & "所有文件" & Chr(0) & "*.*" & Chr(0)
ofn.lpstrFile = Space(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = App.Path
ofn.flags = 6148
rtn = GetOpenFileName(ofn)
If rtn >= 1 Then
Shell "notepad.exe " & ofn.lpstrFile, vbNormalFocus
End If
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式