PRB: Tabbing Broken in WebBrowser Hosted in MFC Regular DLL

Last reviewed: December 2, 1997
Article ID: Q175502
The information in this article applies to:
  • Microsoft Internet Explorer (Programming), versions 3.0, 3.01, 3.02, 4.0
  • The Microsoft Foundation Classes (MFC) included with:

        - Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.0a, 4.1, 4.2,
          4.2b, 5.0
    

SYMPTOMS

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

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.

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);
   }

STATUS

This behavior is by design.

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.

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

   Article ID: Q165074
   TITLE     : PRB: Keystroke Problems in CView/CWnd Web Browser Control

The MFC sample that demonstrates this technique is called DLLTRACE and can be found at:

Visual C++ Online Documentation: Developer Products; Visual C++; Visual C++ Samples; MFC Samples; Advanced MFC Samples; DLLTRACE

Keywords          : AXSDKIEAutomation AXSDKWebBrowser kbcode
Technology        : kbInetDev kbole
Version           : WINDOWS:3.0,3.01,3.02,4.0; WINNT:4.0,4.0a,4.1,4.2,4.2b,5.0
Platform          : WINDOWS winnt
Issue type        : kbprb


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.