因为后台软件限制在win7下,
而前台是以前做过的项目,使用了vb6,
且只有4天要交活,没有时间改平台,所以有上面的限制。commonDialogbox里边的open框只能选择一个图片,但是带有预览功能。
如果flags加上cdlOFNAllowMultiselect,就变成了一个特别落后的对话框,可以多选,但是没有预览功能。我看到win7中有很多对话框既有浏览的功能,也有预览的功能(比如word自带的open对话框),这个是怎么完成的呢?
如果是在某个dll里边有这样的代码,接口是什么呢?

解决方案 »

  1.   

    很抱歉,让你失望了,没办法。我也是Win7曾经我也有跟你想过同样的问题,不过最后发现没办法
      

  2.   

    恭喜你,还真给我在我的源码库里找到这样的代码,拿去用吧'浏览文件夹函数
    Public Function BrowseFolder(ByVal hwnd As Long, ByVal Title As String) As String
        Dim bi As BROWSEINFO
        Dim rtn, pid As Long
        Dim path As String * 512
        Dim pos As Integer
        With bi
            .hOwner = hwnd
            .ulFlags = BIF_RETURNONLYFSDIRS Or BIF_NEWDIALOGSTYLE
            .lpszTitle = Title
        End With
        pid = SHBrowseForFolder(bi)
        rtn = SHGetPathFromIDList(ByVal pid, ByVal path)
        If rtn Then
            pos = InStr(path, Chr(0))
            BrowseFolder = Left(path, pos - 1)
        Else
            BrowseFolder = ""
        End If
    End Function'不用控件实现打开文件对话框
    Public Function OpenDlg(hwnd As Long, filter As String, FilterIndex As Integer) As String
        Dim pOpenfilename As OPENFILENAME
        Dim dd As Long, FileName As String, pos As Integer
        With pOpenfilename
            .flags = OFN_ALLOWMULTISELECT Or OFN_EXPLORER Or OFN_FILEMUSTEXIST
            .lpstrTitle = "打开文件"
            .hwndOwner = hwnd
            .hInstance = App.hInstance
            .lpstrFilter = filter
            .lpstrInitialDir = App.path
            .nFilterIndex = FilterIndex
            .lpstrFile = Space(254)
            .nMaxFile = 255
            .lpstrFileTitle = .lpstrFile
            .nMaxFileTitle = 255
            .lStructSize = Len(pOpenfilename)
        End With
        dd = GetOpenFileName(pOpenfilename)
        If dd Then
            pos = InStrRev(pOpenfilename.lpstrFile, vbNullChar)
           FileName = Left(pOpenfilename.lpstrFile, pos - 2)
        Else
            FileName = ""
        End If
        OpenDlg = FileName
    End Function'取得系统文件夹
    Public Function GetSystemDir() As String    Dim nSize As Long
        Dim tmp As String
        tmp = Space$(256)
        nSize = Len(tmp)
        Call GetSystemDirectory(tmp, nSize)
        If Right(TrimNull(tmp), 1) <> "\" Then
           GetSystemDir = TrimNull(tmp) + "\"
        Else: GetSystemDir = TrimNull(tmp)
        End If
        
    End Function'取得windows文件夹
    Public Function GetWinDir() As String
        Dim nSize As Long
        Dim tmp As String
        tmp = Space$(256)
        nSize = Len(tmp)
        Call GetWindowsDirectory(tmp, nSize)
        
        If Right(TrimNull(tmp), 1) <> "\" Then
          GetWinDir = TrimNull(tmp) + "\"
        Else: GetWinDir = TrimNull(tmp)
        End If
        
    End Function'删除VBNullchar字符
    Private Function TrimNull(item As String)
        Dim pos As Integer
        pos = InStr(item, Chr$(0))
        If pos Then
              TrimNull = Left$(item, pos - 1)
        Else: TrimNull = item
        End If
      
    End Function'返回文件路径,包含"\"
    Public Function ExtractFilePath(ByVal FileName As String) As String
        Dim i As Integer
        i = InStrRev(FileName, "\")
        ExtractFilePath = Left(FileName, i)
    End Function'从全路径中返回文件名,包含扩展名
    Public Function ExtractFileName(ByVal FileName As String) As String
        Dim x
        x = Split(FileName, "\")
        ExtractFileName = x(UBound(x))
    End Function调用的方法:t = OpenDlg(Me.hwnd, "*.*", 0)
    'Me.hwnd是句柄;"*.*”表示要筛选怎么样的文件名和怎么样的文件类型;最后一个参数不知道有什么用反正我传0也没问题随便说一下,我用句柄查找软件去查了Word的打开对话框,发现他的对话框也是用comdlg32.dll的函数做的,而上面的代码也正是用这个DLL的接口做的。应该合你用了。最后附赠GetOpenFileName函数的MSDN说明(英文的自己翻译吧):GetOpenFileName
    The GetOpenFileName function creates an Open common dialog box that lets the user specify the drive, directory, and the name of a file or set of files to open. BOOL GetOpenFileName(
      LPOPENFILENAME lpofn   // address of structure with initialization 
                             // data
    );
     
    Parameters
    lpofn 
    Pointer to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetOpenFileName returns, this structure contains information about the user's file selection. 
    Return Values
    If the user specifies a filename and clicks the OK button, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and filename specified by the user.If the user cancels or closes the Open dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values: CDERR_FINDRESFAILURE CDERR_NOHINSTANCE 
    CDERR_INITIALIZATION CDERR_NOHOOK 
    CDERR_LOCKRESFAILURE CDERR_NOTEMPLATE 
    CDERR_LOADRESFAILURE CDERR_STRUCTSIZE 
    CDERR_LOADSTRFAILURE FNERR_BUFFERTOOSMALL 
    CDERR_MEMALLOCFAILURE FNERR_INVALIDFILENAME 
    CDERR_MEMLOCKFAILURE FNERR_SUBCLASSFAILURE 
    Res
    Beginning with Windows 95 and Windows NT version 4.0, the default Open dialog box provides user-interface features that are similar to the Windows Explorer. You can provide an OFNHookProc hook procedure for an Explorer-style Open dialog box. To enable the hook procedure, set the OFN_EXPLORER and OFN_ENABLEHOOK flags in the Flags member of the OPENFILENAME structure and specify the address of the hook procedure in the lpfnHook member. Windows 95 and Windows NT continue to support the old-style Open dialog box for applications that want to maintain a user-interface consistent with the Windows 3.1 or Windows NT 3.51 user-interface. To display the old-style Open dialog box, enable an OFNHookProcOldStyle hook procedure and ensure that the OFN_EXPLORER flag is not set.To display a dialog box that allows the user to select a directory instead of a file, call theSHBrowseForFolder function.Windows CE: Not all members of the OPENFILENAME structure are defined in Windows CE. For information about the defined members, see the reference topic for the OPENFILENAME structure.QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in commdlg.h.
      Import Library: Use comdlg32.lib.
      Unicode: Implemented as Unicode and ANSI versions on Windows NT.See Also
    Common Dialog Box Library Overview, Common Dialog Box Functions, CommDlgExtendedError, GetSaveFileName, OFNHookProc , OFNHookProcOldStyle, OPENFILENAME,SHBrowseForFolder 
      

  3.   

    最上面的代码,就是“调用方法”前的代码放到一个模块里,然后按照调用方法里的语句调用就会出来一个对话框,返回的t是文件路径+文件名,中间使用空格隔开的。
    再附赠一份这个函数要用到的OPENFILENAME类型的MSDN说明(中文的,度娘提供的资料):
    http://baike.baidu.com/view/2175167.htm