首页 /编程语言和算法/VB6/ASP
 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


 
全部回复(0)
首页 | 电脑版 |