No announcement yet.

Find Dialog

  • Filter
  • Time
  • Show
Clear All
new posts

  • Find Dialog

    When using the embedded browser, I want to use the Find dialog that is available using pCmdTarget.Exec.

    But I also want to restore the Find Dialog to it's last used location and I want to restore the last text used in the Find Dialog.

    The notifications that Find Dialog is supposed to send the parent window via dwMsgFindReplace are not being received - see the code below. The notifications are being received if I open a Find Dialog outside the browser, but that won't let me search/highlight text within the browser.

    Does anyone know how to ensure that the notifications are received in "Case dwMsgFindReplace"? Or as an alternative, is there a way to search the browser content without using the built-in Find Dialog?

    'Compilable Example:
    #Compile Exe
    #Dim All
    %Unicode = 1
    %UseWebBrowser = 1            ' // Use the WebBrowser control
    #Include Once ""   ' // CWindow class
    #Include Once ""
    %IDC_WebBrowser = 1001
    %IDC_Pierre     = 1002
    %IDC_Gary       = 1003
    Global hDlg, hBrowser, OldBrowserProc As Dword
    Global FindDialogText As WStringZ * 50
    Function PBMain
       Local pWindow As IWindow
       Dialog Default Font "Tahoma", 12, 1
       Dialog New Pixels, 0, "WebBrowser", , , 600, 400, %WS_OverlappedWindow To hDlg
       Control Add Button, hDlg,%IDC_Pierre, "Pierre", 10,10,60,30
       Control Add Button, hDlg,%IDC_Gary, "Gary", 110,10,60,30
       pWindow = Class "CWindow"
       hBrowser = pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, "",Nothing, 0, 50, 600,350)
       'OldBrowserProc = SetWindowLong(hbrowser, %GWL_WndProc, CodePtr(NewBrowserProc)) 'subclass a control
       Dialog Show Modal hDlg, Call DlgProc
    End Function
    CallBack Function DlgProc() As Long
        Static pFindReplace        As FINDREPLACE Pointer
        Static FindStruct          As FINDREPLACE
        Static zToFind             As WStringZ * 81
        Static dwMsgFindReplace    As Dword
        Local RetVal              As Long
       Select Case Cb.Msg
          Case %WM_InitDialog
             dwMsgFindReplace = RegisterWindowMessage($FindMsgString) '$FindMsgString is defined as "commdlg_FindReplace" in
          Case %WM_Command
             If Cb.Ctl = %IDC_Pierre Then
               zToFind                     = "The"
               FindStruct.lStructSize      = SizeOf(FINDREPLACE)
               FindStruct.hWndOwner        = hDlg
               FindStruct.Flags            = %FR_DOWN
               FindStruct.lpstrFindWhat    = VarPtr(zToFind) 'Static
               FindStruct.wFindWhatLen     = SizeOf(zToFind) 'Not LEN()
               RetVal = FindText(FindStruct)
             End If
             If Cb.Ctl = %IDC_Gary Then
               FindDialogText = "and"
             End If
          Case dwMsgFindReplace
             ? "BingoMain"
       End Select
    End Function
    Sub w_OpenFindDialog
       Local pIWebBrowser2 As IWebBrowser2
       Local CGID_WebBrowser As Guid
       Local pDisp As IDispatch
       Local pCmdTarget As IOleCommandTarget
       Local vIn As Variant
       Local vOut As Variant
       Local hFindText  As Dword
       Local hFindTextEdit  As Dword
       Local szText        As WStringZ * %Max_Path
       CGID_WebBrowser = Guid$("{ED016940-BD5B-11CF-BA4E-00C04FD70816}")
       pIWebBrowser2 = OC_GetDispatch(hBrowser)
       pDisp = pIWebBrowser2.Document
       pCmdTarget = pDisp
       pCmdTarget.Exec(CGID_WebBrowser, 1, 0, vIn, vOut)
       szText = FindDialogText
       hFindText     = FindWindow("#32770", "Find")
       hFindTextEdit = FindWindowEx(hFindText, 0, "Edit", "")
       SendMessage(hFindTextEdit, %WM_SETTEXT, 0, VarPtr(szText))
    End Sub
    'Function NewBrowserProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    '   Local dwMsgFindReplace    As Dword
    '   Select Case Msg
    '      Case dwMsgFindReplace
    '         ? "BingoBrowser"
    '   End Select
    '   Function = CallWindowProc(OldBrowserProc, hWnd, Msg, wParam, lParam)
    'End Function

  • #2
    Does this apply? I don't know if they use ieframe.dll and can both be used?
    CMD shortcut to open any location:
    %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
    Change to run as administrator
    How long is an idea? Write it down.


    • #3
      > The notifications that Find Dialog is supposed to send the parent window via dwMsgFindReplace are not being received

      You aren't giving any chance to process them. It will never work with a DDT modal dialog box. You need to use a modeless dialog and a message pump, e.g. this SDK message pump:

      ' // Processes window messages
      LOCAL uMsg AS tagMsg
      WHILE GetMessage(uMsg, %NULL, 0, 0)
         ' // Needed to process Find and Find/Replace dialog messages
         IF <handle of the Find dialog> = 0 OR ISFALSE IsDialogMessage(<handle of the Find dialog>, uMsg) THEN
            ' // Determines whether a message is intended for the specified
            ' // dialog box and, if it is, processes the message.
            IF IsDialogMessage(hwndMain, uMsg) = 0 THEN
               ' // Translates virtual-key messages into character messages.
               TranslateMessage uMsg
               ' // Dispatches a message to a window procedure.
               DispatchMessage uMsg
            END IF
         END IF
      If using a SDK message pump, be aware that you also need to use a SDK style callback procedure and forget DDT for a while.


      hFindText = FindWindow("#32770", "Find")

      be aware that it will only work with English versions of Windows. For example, in the Spanish version the caption is "Buscar", not "Find".


      • #4
        Howdy, Jose!

        Thanks for stopping in and for the information. I'll go give it a try!