How to check if the browser has focus ?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to check if the browser has focus ?

Postby silver » Sun Jul 05, 2015 12:43 am

Hi

SendFocusEvent/SetFocus can be used to put the browser "control" under focus.
Is there a function that can tell if it has focus or not ?
User avatar
silver
Techie
 
Posts: 48
Joined: Tue Feb 24, 2015 5:39 am

Re: How to check if the browser has focus ?

Postby amaitland » Sun Jul 05, 2015 3:12 pm

You can implement `CefFocusHandler` from which you can track the focus. Make sure to read the method descriptions in detail.

apidocs3/projects/%28default%29/CefFocusHandler.html
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: How to check if the browser has focus ?

Postby silver » Sun Jul 05, 2015 11:04 pm

amaitland wrote:You can implement `CefFocusHandler` from which you can track the focus. Make sure to read the method descriptions in detail.

http://magpcss.org/ceforum/apidocs3/pro ... ndler.html


The OnGotFocus method seems to be called when SetFocus is invoked on the browser.

However the OnTakeFocus method of CefFocusHandler is not being called when the focus is moved away from the browser component,
so its not possible to track if the browser does not have focus.

Tried on Windows 7 64bit
User avatar
silver
Techie
 
Posts: 48
Joined: Tue Feb 24, 2015 5:39 am

Re: How to check if the browser has focus ?

Postby amaitland » Sun Jul 05, 2015 11:49 pm

If you require more than being notified when the user tabs out of the browser then you'll have to look at a lower level approach.

The following should work even though it's asking in relation to `CEF1`
viewtopic.php?f=6&t=10033&p=14469&hilit=OnTakeFocus#p14687
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: How to check if the browser has focus ?

Postby silver » Tue Jul 07, 2015 1:52 am

amaitland wrote:If you require more than being notified when the user tabs out of the browser then you'll have to look at a lower level approach.

The following should work even though it's asking in relation to `CEF1`
http://magpcss.org/ceforum/viewtopic.ph ... cus#p14687


I am using multi_threaded_message_loop = true ,
I guess my application's main event loop will not receive WM_SETFOCUS/WM_KILLFOCUS that happen on the browser control
User avatar
silver
Techie
 
Posts: 48
Joined: Tue Feb 24, 2015 5:39 am

Re: How to check if the browser has focus ?

Postby magreenblatt » Tue Jul 07, 2015 10:26 am

The WinAPI GetFocus function will tell you what window has focus. You can then walk the window hierarchy using GetAncestor to determine if it's the browser window or some other application window.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to check if the browser has focus ?

Postby amaitland » Tue Jul 07, 2015 11:35 pm

Would it be feasible to expand `OnTakeFocus` to provide notification for more than just tabbing out of the browser?
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: How to check if the browser has focus ?

Postby silver » Wed Jul 08, 2015 12:06 am

magreenblatt wrote:The WinAPI GetFocus function will tell you what window has focus. You can then walk the window hierarchy using GetAncestor to determine if it's the browser window or some other application window.


Thanks. The Winapi GetFocus function seems to work.
User avatar
silver
Techie
 
Posts: 48
Joined: Tue Feb 24, 2015 5:39 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 85 guests