CWebView::GetFocus Method  
 
BOOL GetFocus(
  BOOL *lpbHasFocus  
);

The GetFocus method returns whether the browser has focus.

Parameters

lpbHasFocus
A pointer to a BOOL which will contain TRUE (non-zero) if the browser window has focus and FALSE (zero) if it does not have focus. This parameter cannot be NULL.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The GetFocus method queries whether the browser control currently has input focus. This is useful for determining if keyboard input will be directed to the content area of the browser or handled by the host window. The focus state can change dynamically as the user interacts with the application, and applications that track focus should also monitor the WEBVIEW_EVENT_FOCUS_CHANGED event.

This method only reports the focus state of the embedded browser, not of the host window itself. For example, a host window may be the active foreground window, but if another control within the host has focus, the browser will not be considered focused. To explicitly give focus to the browser, call SetFocus.

Example

BOOL bHasFocus = FALSE;

if (pWebView->GetFocus(&bHasFocus))
{
    if (!bHasFocus)
    {
        // Give the browser control focus if it does not have it
        pWebView->SetFocus();
    }
}
else
{
    // Handle error
    DWORD dwError = pWebView->GetLastError();
    _tprintf(_T("GetFocus failed, error=0x%lx\n"), dwError);
}       

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib

See Also