查看: 22  |  回复: 0
  VB6 调用ShellExecute用记事本打开文件,子程序 OpenNotepadWithFile(filePath As String)
楼主
发表于 昨天 16:34

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
Private Const SW_SHOWNORMAL = 1
 
Private Sub OpenNotepadWithFile(filePath As String)
    Dim returnValue As Long
    
    ' 使用 ShellExecute 打开记事本并加载指定文件
    returnValue = ShellExecute(0, "open", "notepad", Chr(34) & filePath & Chr(34), "", SW_SHOWNORMAL)
    
    ' 检查是否成功执行
    If returnValue <= 32 Then
        MsgBox "无法打开记事本", vbExclamation
    End If
End Sub

Private Sub Command1_Click()
    Dim filePath As String
    filePath = App.Path & "\123.txt"
    Call OpenNotepadWithFile(filePath)
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com