首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

有关VB公共对话框的有关问题

2013-06-25 
有关VB公共对话框的问题我在VB6.0中写了一段公共对话框的程式,可以显示打开文件的控件,但不能打开所选中的

有关VB公共对话框的问题
我在VB6.0中写了一段公共对话框的程式,可以显示打开文件的控件,但不能打开所选中的问件,请各位大师指点一下,好吗?
[解决办法]
打开文件要靠其他代码,根据你的文件情况来定


[解决办法]


'文件对话框只能获得所选择文件的路径并不能打开文件。
'测试以下代码,它能打开windows能识别的文件。

Option Explicit

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 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 Command1_Click()
    Dim ofn As OPENFILENAME
    Dim rtn As String
    
    ofn.lStructSize = Len(ofn)
    ofn.hwndOwner = Me.hwnd
    ofn.hInstance = App.hInstance
    ofn.lpstrFilter = "TEXT (*.TXT)" & Chr$(0) & "*.TXT" & Chr$(0)
    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)
    


    If rtn >= 1 Then
       ShellExecute Me.hwnd, "open", ofn.lpstrFileTitle, vbNullString, _
                 Left(ofn.lpstrFile, InStrRev(ofn.lpstrFile, "") - 1), 1

    End If

End Sub

热点排行