Results 1 to 13 of 13

Thread: [RESOLVED] How to set focus to "Find" form created by WebBrowser control?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Resolved [RESOLVED] How to set focus to "Find" form created by WebBrowser control?

    I have VB6 form with MS Webbrowser control on it.
    When I click the Webbrowser and after that press Ctrl+F the "Find" form pops-up. This "Find" form is created by Microsoft and is triggered by Webbrowser. I checked that "Find" form is not listed in the Forms collection.

    Problem is - the focus of application usually is not switched to this "Find" form. It's title bar stays gray and user has to manually click it before typing the word he/she wants to find.

    Can anyone advice me please how I can switch focus to this "Find" form immediately after it's pop-up.

    Thanks!

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to set focus to "Find" form created by WebBrowser control?

    I haven't had a single case where the "Find" window pops up without the focus. I don't even see how it can occur unless you are doing something that causes the focus to move away from the window.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Re: How to set focus to "Find" form created by WebBrowser control?

    Thank you for reply. Actually you right. I realized that problem is in statement HTMLDOC.focus that occurs in HTMLDOC_onmousemove procedure. I added this statement to let user to scroll the WB page with mouse without initial clicking the WB control. It works fine. But when user clicks the Ctrl+F and "Find" window pops-up, the mouse pointer is still in WB and focus is switched back to WB control. Interesting that _onmousemove occurs in WB even if I do not move the mouse, just keep it inside the control.

    Additional problem is the _onkeyup procedure does not respond to Ctrl+F ! It somehow "reserved". The _onkeyup fires for "Ctrl" or "F" press and release, or for Ctrl+S etc. But not for Ctrl+F. As a result I can not detect the "Find" form presence, unless I use "FindWindow" API in _onmousemove or in Timer, what is resource consuming.

    Form_KeyUp is also not fired when I press Ctrl+F in WB control (even if Form.KeyPreview is true).

    Any suggestions or ideas?
    Last edited by ma14; May 12th, 2016 at 11:26 AM.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to set focus to "Find" form created by WebBrowser control?

    If all you are interested in is knowing when user entered Ctrl+F to bring up the "Find" dialog box then you can use this:

    Code:
    Private Sub WebBrowser1_PropertyChange(ByVal szProperty As String)
     If szProperty = "__IE_FindDialog" Then
       Caption = "You invoked the 'Find Dialog Window'"
     End If
    End Sub


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Re: How to set focus to "Find" form created by WebBrowser control?

    Problem solved!
    I simple added GetAsyncKeyState into HTMLDOC_onmousemove to not focus on WB if Ctrl+F is pressed. Very simple. In this case focus is switched to "Find" form instantly and HTMLDOC_onmousemove is not triggered any more. When I move mouse back to WB the HTMLDOC.focus works again and WB page scrolling becomes available again.


    Private Sub HTMLDOC_onmousemove()

    If Not (GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyF) <> 0) Then
    HTMLDOC.focus
    End If

    End Sub

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Re: How to set focus to "Find" form created by WebBrowser control?

    Quote Originally Posted by jmsrickland View Post
    If all you are interested in is knowing when user entered Ctrl+F to bring up the "Find" dialog box then you can use this:

    Code:
    Private Sub WebBrowser1_PropertyChange(ByVal szProperty As String)
     If szProperty = "__IE_FindDialog" Then
       Caption = "You invoked the 'Find Dialog Window'"
     End If
    End Sub
    Thank you for advice. Unfortunately on my computer WebBrowser1_PropertyChange does not respond to "Find" dialog pop-up. There is response like
    szProperty = {265b75c1-4158-11d0-90f6-00c04fd497ea}
    to navigation , but not to "Find" dialog pop-up.

    I will use the method
    If Not (GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyF) <> 0) Then , which I posted an about hour ago.

    Thank you any way!

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to set focus to "Find" form created by WebBrowser control?

    Why wouldn't you put your code in _onkeydown instead of _onmousemove
    Last edited by jmsrickland; May 12th, 2016 at 02:07 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Re: How to set focus to "Find" form created by WebBrowser control?

    Sub _onmousemove calls the HTMLDOC.focus that needed to let user to scroll the WB page with mouse wheel without clicking the WB control. When user clicks the Ctrl+F I need immediately to stop this .focus.

    Probably I can run FindWindow API in _onkeydown and set focus on "Find" dialog box by it's hWnd. I did not try it yet. I could be less resource consuming

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to set focus to "Find" form created by WebBrowser control?

    Also it seems like you should use

    If (GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyF) <> 0) Then

    instead of

    If Not (GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyF) <> 0) Then

    Reason: using the Not allows vbKeyControl to enter the If Clause regardless of vbKeyF while leaving off the Not allows the If clause to be entered only if both keys are pressed


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Re: How to set focus to "Find" form created by WebBrowser control?

    Just tested.

    The
    If (GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyF) <> 0)
    does not work.

    I also checked that my inversed statement
    If (GetAsyncKeyState(vbKeyControl) = 0 Or GetAsyncKeyState(vbKeyF) = 0) Then
    HTMLDOC.focus
    End If

    works fine.

  11. #11
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to set focus to "Find" form created by WebBrowser control?

    Wierd!

    You say your version of WB doesn't respond to If szProperty = "__IE_FindDialog" Then but mine does. You say that If (GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyF) <> 0)
    does not work for you but it does for me and that If (GetAsyncKeyState(vbKeyControl) = 0 Or GetAsyncKeyState(vbKeyF) = 0) Then works for you but it doesn't work for me.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Re: How to set focus to "Find" form created by WebBrowser control?

    Hmm. Interesting...

    I use IE 11 on Windows 7. What is your environment?

    Regarding If (GetAsyncKeyState(vbKeyControl) = 0 Or GetAsyncKeyState(vbKeyF) = 0). Possible here is some simple misunderstanding: I use this condition to focus to WB. Indeed, if there is no key press or pressed not Ctrl+F then app sets focus to WB control. If both keys are pressed (i.e. GetAsyncKeyState(vbKeyControl) <> 0 AND GetAsyncKeyState(vbKeyF) <> 0) then app does not set focus back to WB. In another words code detects not the case when Ctrl+F is pressed, but when it is NOT pressed, because I need to set focus to WB to allow scrolling without clicking. It is in my code above.
    Last edited by ma14; May 12th, 2016 at 03:06 PM.

  13. #13
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to set focus to "Find" form created by WebBrowser control?

    OK, I see now. I didn't think about it to test for when it is not pressed in which case yours is correct.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width