Microsoft KB Archive/175502

= PRB: Tabbing Broken in WebBrowser Hosted in MFC Regular DLL =

Article ID: 175502

Article Last Modified on 5/2/2001

-

APPLIES TO

 Microsoft Internet Explorer 3.0 Microsoft Internet Explorer 3.01 Microsoft Internet Explorer 3.02 Microsoft Internet Explorer 4.0 128-Bit Edition Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q175502

<div class="symptoms_section">

SYMPTOMS
When an application creates the WebBrowser control in an MFC Regular DLL, tabbing within the WebBrowser control does not function correctly.

<div class="cause_section">

CAUSE
The TAB key and other dialog navigation keys are not getting processed in the context of the DLL by the IsDialogMessage function. Consequently, the proper dialog events are not being generated for the WebBrowser control.

<div class="resolution_section">

RESOLUTION
In the DLL that is hosting the WebBrowser control, override the PreTranslateMessage for the CWnd-derived class as follows: BOOL CDllWnd::PreTranslateMessage(MSG* pMsg) {  if (IsDialogMessage(pMsg)) return TRUE;

return CWnd::PreTranslateMessage(pMsg); } Next, export a function that can be used by a controlling application to call PreTranslateMessage as follows: extern "C" DllExport BOOL FAR PASCAL FilterDllMsg(LPMSG lpMsg) {  AFX_MANAGE_STATE(AfxGetStaticModuleState) TRY {     return AfxGetApp->PreTranslateMessage(lpMsg); }  END_TRY

return FALSE; } In the controlling application, override the PreTranslateMessage method of your CView-derived class and call the FilterDllMsg as follows: BOOL CWBView::PreTranslateMessage(MSG* pMsg) {  if (CView::PreTranslateMessage(pMsg)) return TRUE;

return FilterDllMsg(pMsg); }

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
Typically, the Web Browser Control is embedded in a dialog box or CView- derived class that resides as part of a standard application. When moving WebBrowser control hosting code into an MFC Regular DLL, certain problems related to messages may occur.

A MFC Regular DLL does not have a main message pump, as does the CWinApp object of an application. When the DLL contains code that creates and hosts the WebBrowser control, dialog messages are not automatically translated for the WebBrowser control. If IsDialogMessage is not called for these messages by the DLL, the WebBrowser control will not properly handle tabbing-related messages.

<div class="references_section">