BrowsInfo结构的LpFn设置为回调函数
BrowseCallbackProc
的地址,
Function BrowseCallbackProc(Hwnd as Long,Msg as Long,Lparam as long,Data as long) as integerHwnd 为以下可能的值
当Hwnd 为BFFM_ENABLEOK 时
 回调函数通过设置Hwnd的值为0或非0来控制OK按钮的状态。
算了,相信您英语比我好,下面贴出来您自己看吧,
实在不行我中午写个例子。现在太忙了,不好意思#define BFFM_INITIALIZED        1
#define BFFM_SELCHANGED         2
#define BFFM_VALIDATEFAILEDA    3   // lParam:szPath ret:1(cont),0(EndDialog)
#define BFFM_VALIDATEFAILEDW    4   // lParam:wzPath ret:1(cont),0(EndDialog)// messages to browser
#define BFFM_SETSTATUSTEXTA     (WM_USER + 100)
#define BFFM_ENABLEOK           (WM_USER + 101)
#define BFFM_SETSELECTIONA      (WM_USER + 102)
#define BFFM_SETSELECTIONW      (WM_USER + 103)
#define BFFM_SETSTATUSTEXTW     (WM_USER + 104)

解决方案 »

  1.   

    BrowseCallbackProc
    int CALLBACK BrowseCallbackProc(
        HWND hwnd, 
        UINT uMsg, 
        LPARAM lParam, 
        LPARAM lpData
        ); Specifies an application-defined callback function used with the SHBrowseForFolder function. The browse dialog box calls this function to notify it about events. Returns zero. 
    hwnd 
    Window handle to the browse dialog box. The callback function can send the following messages to this window: BFFM_ENABLEOK  Enables or disables the dialog's OK button. If the message's lParam is nonzero, the button is enabled. If the message's lParam is zero, the button is disabled.  
    BFFM_SETSELECTION  Selects the specified folder. The message's lParam is the PIDL of the folder to select if wParam is FALSE, or the path of the folder otherwise.  
    BFFM_SETSTATUSTEXT  Sets the status text to the null-terminated string specified by the message's lParam parameter.  uMsg 
    Value identifying the event. This can be one of the following values: BFFM_INITIALIZED  Indicates the browse dialog box has finished initializing. The lParam parameter is NULL.  
    BFFM_SELCHANGED  Indicates the selection has changed. The lParam parameter contains the address of the item identifier list for the newly selected folder.  
    BFFM_VALIDATEFAILED  Version 4.71. Indicates the user typed an invalid name into the edit box of the browse dialog. The lParam parameter is the address of a character buffer that contains the invalid name. An application can use this message to inform the user that the name entered was not valid. Return zero to allow the dialog to be dismissed or nonzero to keep the dialog displayed.  lParam 
    Value dependent upon the message contained in the uMsg parameter. 
    lpData 
    Application-defined value that was specified in the lParam member of the BROWSEINFO structure. 
      

  2.   

    To : handsomge(和尚) 
    中午给个vb的例子吧,好吗,谢谢
      

  3.   

    这么原理简单、代码量多的程序实在是没有兴趣写
    有个类似的
    自己看吧http://www.applevb.com/sourcecode/2054_EBrowseF.zip
    SHBrowseForFolder函数大家可能用过,这个代码展示了一个扩充用法,可以让你在Dialog中选择的时候就显示选择了那个目录。'=====================================================================================
    ' Browse for a Folder using SHBrowseForFolder API function with a callback
    ' function BrowseCallbackProc.
    '
    ' This Extends the functionality that was given in the
    ' MSDN Knowledge Base article Q179497 "HOWTO: Select a Directory
    ' Without the Common Dialog Control".
    '
    ' After reading the MSDN knowledge base article Q179378 "HOWTO: Browse for
    ' Folders from the Current Directory", I was able to figure out how to add
    ' a callback function that sets the starting directory and displays the
    ' currently selected path in the "Browse For Folder" dialog.
    '
    ' I used VB 6.0 (SP3) to compile this code.  Should work in VB 5.0.
    ' However, because it uses the AddressOf operator this code will not
    ' work with versions below 5.0.
    '
    ' This code works in Window 95a so I assume it will work with later versions.
    '
    ' Stephen Fonnesbeck
    [email protected]
    ' http://www.xmission.com/~steev
    ' Feb 20, 2000
    '
    '=====================================================================================
    ' Usage:
    '
    '    Dim folder As String
    '    folder = BrowseForFolder(Me, "Select A Directory", "C:\startdir\anywhere")
    '    If Len(folder) = 0 Then Exit Sub  'User Selected Cancel
    '
    '=====================================================================================Option ExplicitPrivate Const BIF_STATUSTEXT = &H4&
    Private Const BIF_RETURNONLYFSDIRS = 1
    Private Const BIF_DONTGOBELOWDOMAIN = 2
    Private Const MAX_PATH = 260Private Const WM_USER = &H400
    Private Const BFFM_INITIALIZED = 1
    Private Const BFFM_SELCHANGED = 2
    Private Const BFFM_SETSTATUSTEXT = (WM_USER + 100)
    Private Const BFFM_SETSELECTION = (WM_USER + 102)Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As LongPrivate Type BrowseInfo
      hWndOwner      As Long
      pIDLRoot       As Long
      pszDisplayName As Long
      lpszTitle      As Long
      ulFlags        As Long
      lpfnCallback   As Long
      lParam         As Long
      iImage         As Long
    End TypePrivate m_CurrentDirectory As String   'The current directory
    'Public Function BrowseForFolder(owner As Form, Title As String, StartDir As String) As String
      'Opens a Treeview control that displays the directories in a computer  Dim lpIDList As Long
      Dim szTitle As String
      Dim sBuffer As String
      Dim tBrowseInfo As BrowseInfo
      m_CurrentDirectory = StartDir & vbNullChar  szTitle = Title
      With tBrowseInfo
        .hWndOwner = owner.hWnd
        .lpszTitle = lstrcat(szTitle, "")
        .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN + BIF_STATUSTEXT
        .lpfnCallback = GetAddressofFunction(AddressOf BrowseCallbackProc)  'get address of function.
      End With  lpIDList = SHBrowseForFolder(tBrowseInfo)
      If (lpIDList) Then
        sBuffer = Space(MAX_PATH)
        SHGetPathFromIDList lpIDList, sBuffer
        sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
        BrowseForFolder = sBuffer
      Else
        BrowseForFolder = ""
      End If
      
    End Function
     
    Private Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lp As Long, ByVal pData As Long) As Long
      
      Dim lpIDList As Long
      Dim ret As Long
      Dim sBuffer As String
      
      On Error Resume Next  'Sugested by MS to prevent an error from
                            'propagating back into the calling process.
         
      Select Case uMsg
      
        Case BFFM_INITIALIZED
          Call SendMessage(hWnd, BFFM_SETSELECTION, 1, m_CurrentDirectory)
          
        Case BFFM_SELCHANGED
          sBuffer = Space(MAX_PATH)
          
          ret = SHGetPathFromIDList(lp, sBuffer)
          If ret = 1 Then
            Call SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0, sBuffer)
          End If
          
      End Select
      
      BrowseCallbackProc = 0
      
    End Function' This function allows you to assign a function pointer to a vaiable.
    Private Function GetAddressofFunction(add As Long) As Long
      GetAddressofFunction = add
    End Function
      

  4.   

    在上面的代码中我根据提示,改动如下
        Case BFFM_SELCHANGED
          sBuffer = Space(MAX_PATH)
          
          ret = SHGetPathFromIDList(lp, sBuffer)
          If ret = 1 Then
            Call SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0, sBuffer)
          End If
          path = Trim(sBuffer)
          path = Replace(path, Chr(0), "")
          If Len(Dir(path & "\*.mdb")) > 0 Then
            Call SendMessage(hWnd, BFFM_ENABLEOK, 1, 1)
        Else
            Call SendMessage(hWnd, BFFM_ENABLEOK, 0, 0)
        End If
    可是ok按钮总是没有变化!请高手帮人帮到底,谢谢
      

  5.   

    你是想在SHBrowseForFolder 的时候把对话框中的"确定"按钮enable=false但是当SHBrowseForFolder 执行完后,到下一条语句时对话框已经不见了,所以根本不可行,除非你可以在SHBrowseForFolder 执行中让enable=false掉
      

  6.   

    你没注意那个程序的SendMessage声明有问题吗(只能发送字符串)?
    应该这样:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As LongBFFM_ENABLEOK要声明
    Private Const BFFM_ENABLEOK As Long = (WM_USER + 101)
    Private Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lp As Long, ByVal pData As Long) As Long
      
      Dim lpIDList As Long
      Dim ret As Long
      Dim sBuffer As String
      
      On Error Resume Next  'Sugested by MS to prevent an error from
                            'propagating back into the calling process.
         
      Select Case uMsg
      
        Case BFFM_INITIALIZED
          Call SendMessage(hWnd, BFFM_SETSELECTION, 1, ByVal m_CurrentDirectory) '由于SendMessage的声明改了,所以加ByVal
          'SendMessage hWnd, BFFM_ENABLEOK, 0, ByVal 0&
          
        Case BFFM_SELCHANGED
          sBuffer = Space(MAX_PATH)
          
          ret = SHGetPathFromIDList(lp, sBuffer)
          If ret = 1 Then
            Call SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0, ByVal sBuffer) '由于SendMessage的声明改了,所以加ByVal
            
            sBuffer = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1) '截取\0中止符
            If Right$(sBuffer, 1) <> "\" Then sBuffer = sBuffer + "\"
            SendMessage hWnd, BFFM_ENABLEOK, 0, ByVal CLng(((Dir$(sBuffer + "*.txt") <> "") And 1&)) '注意我把查找文件格式设为*.txt了,这样好测试些,你要注意改回*.mdb
            'Debug.Print ((Dir$(sBuffer + "*.txt") <> "") And 1&)
            
          End If
          
      End Select
      
      BrowseCallbackProc = 0
      
    End Function