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?
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?
Code:
'Compilable Example: #Compile Exe #Dim All %Unicode = 1 %UseWebBrowser = 1 ' // Use the WebBrowser control #Include Once "CWindow.inc" ' // CWindow class #Include Once "commdlg.inc" %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, "http://www.garybeene.com/sw/gbthreads.htm",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 CommDlg.inc 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" w_OpenFindDialog 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
Comment