我在界面中做了个主目录,如何利用OPen控件选中文件后,添加把文件名到下面的ListBox中,可添加多个文件名,在ListBox中每双击一个文件,能够单独弹出一个RachTextBox文本,显示那个文件名的内容,麻烦各位大侠帮帮小弟,能说明大概用什么语句说明白,即可,能发下全部代码更好,谢谢大家,分数可商量

解决方案 »

  1.   

    标准模块:Module1.bas
    Option ExplicitPublic Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    Public 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窗体模块:'Form1上添加一列表框控件List1,一命令按钮Command1
    Option ExplicitPrivate Sub Command1_Click()
            Dim ofn As OPENFILENAME
            Dim rtn& ', S$, Str$, i%
            
            ofn.lStructSize = Len(ofn)
            ofn.hwndOwner = Me.hwnd
            ofn.hInstance = App.hInstance
            ofn.lpstrFilter = "所有文件"
            ofn.lpstrFile = Space(254)
            ofn.nMaxFile = 255
            ofn.lpstrFileTitle = Space(254)
            ofn.nMaxFileTitle = 255
            ofn.lpstrInitialDir = App.path
            ofn.lpstrTitle = "打开文件"
            ofn.flags = 6148
            rtn = GetOpenFileName(ofn)
            'For i = 1 To Len(Trim(ofn.lpstrFile))
            '    S = Mid(Trim(ofn.lpstrFile), i, 1)
            '    If Len(S) <> 0 Then Str = Str & S
            'Next
            'Debug.Print Str
            'List1.AddItem ofn.lpstrFile
            If rtn <> 0 Then
               List1.AddItem ofn.lpstrFile
            Else
               List1.AddItem "按了取消键!"
            End If
    End Sub
      

  2.   

    至于双击ListBox控件,打开文件显示内容的问题:
    用Open (文件名) As ...#1  格式打开文件,然后在RichTextBox中显示内容.