求助高人啊,怎么才能在程序中调用出‘查找’关键词的对话框?这两天在网上一直没有搜到,急。若有高手相助的话非常感谢。

解决方案 »

  1.   

    Private Type FINDREPLACE
    lStructSize As Long 
    hwndOwner As Long 
    hInstance As Long 
    flags As Long
    lpstrFindWhat As String 
    lpstrReplaceWith As String
    wFindWhatLen As Integer
    wReplaceWithLen As Integer
    lCustData As Long 
    lpfnHook As Long 
    lpTemplateName As String 
    End Type'调用 Common Dialog DLL 
    Private Declare Function FindText Lib "comdlg32.dll" Alias "FindTextA" _
    (pFindreplace As FINDREPLACE) As Long
    Private Declare Function ReplaceText Lib "comdlg32.dll" Alias "ReplaceTextA" _
    (pFindreplace As FINDREPLACE) As Long
    Dim frText As FINDREPLACE Private Sub cmdFind_Click()
    FindText frText '调用查找对话框
    End Sub
    Private Sub cmdReplace_Click()
    ReplaceText frText '调用替换对话框
    End Sub
    Private Sub form_Load()
    With frText
    .lpstrReplaceWith = "Replace Text"
    .lpstrFindWhat = "Find Text"
    .wFindWhatLen = 9
    .wReplaceWithLen = 12
    .hInstance = App.hInstance
    .hwndOwner = Me.hWnd
    .lStructSize = LenB(frText)
    End With
    End Sub
    看下这个行不
      

  2.   

    '打开选择文件对话框Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As LongPrivate 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 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 Const MAX_PATH = 260
    Private Const BIF_USENEWUI = &H40Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As LongPrivate Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As LongPrivate Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long'浏览文件夹
    Public Function BrowseForFolder(hwndOwner As Long, _
                                    sPrompt As String) As String   Dim iNull As Integer
       Dim lpIDList As Long
       Dim lResult As Long
       Dim sPath As String
       Dim udtBI As BrowseInfo
       With udtBI
          .hwndOwner = hwndOwner
          .lpszTitle = lstrcat(sPrompt, "")
          .ulFlags = BIF_USENEWUI
       End With   lpIDList = SHBrowseForFolder(udtBI)   If lpIDList Then
          sPath = String$(MAX_PATH, 0)
          lResult = SHGetPathFromIDList(lpIDList, sPath)
          Call CoTaskMemFree(lpIDList)
          iNull = InStr(sPath, vbNullChar)
          
          If iNull Then
             sPath = Left$(sPath, iNull - 1)
          End If
       End If
       
       If Right$(sPath, 1) <> "\" And sPath <> "" Then
          sPath = sPath & "\"
       End If
       
       BrowseForFolder = sPathEnd Function'打开选择文件的对话框
    Public Function BrowseForFile(lngHwnd As Long, _
                                  ByVal Title As String) As String
       Dim uOpenFile As OPENFILENAME
       Dim lReturn As Long
       Dim sFilter As String
       
       With uOpenFile
          .lStructSize = Len(uOpenFile)
          .hwndOwner = lngHwnd
          .hInstance = App.hInstance
          sFilter = "数据库文件(*.mdb)" & Chr(0) & "*.mdb" & Chr(0)
          .lpstrFilter = sFilter
          .nFilterIndex = 1
          .lpstrFile = String(257, 0)
          .nMaxFile = Len(.lpstrFile) - 1
          .lpstrFileTitle = .lpstrFile
          .nMaxFileTitle = .nMaxFile
          .lpstrInitialDir = App.Path
          .lpstrTitle = Title
          .flags = 0
       End With
       
       lReturn = GetOpenFileName(uOpenFile)
       
       '等于0为用户选择了"取消"
       If lReturn = 0 Then
          BrowseForFile = ""
          'add on
          Frm_CnnAccess.CmdYes.Enabled = False
          
       Else
          BrowseForFile = Trim(uOpenFile.lpstrFile)
          'add on
          Frm_CnnAccess.TxtServerName.Text = Trim(uOpenFile.lpstrFile)
          Frm_CnnAccess.CmdYes.Enabled = True
          
       End If
       
    End Function
      

  3.   

    谢谢各位热心人,我的问题应该是aspower_的回复比较正确。因为我调用的是快捷键"ctrl+f"调用的从窗体中查询关键词对话框。思成先生的意思是关于查找文件的系统调用。
    不管怎么说,谢谢大家。有请aspower_多多包涵。