Microsoft KB Archive/324419

= BUG: Scroll Bars and Borders Appear in Framesets When You Navigate Again in BeforeNavigate =

Article ID: 324419

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q324419



SYMPTOMS
An empty scroll bar and sometimes a border appear if the following conditions are true:
 * You display a frameset in an application that hosts the WebBrowser control. -and-


 * You navigate to a frame in the frameset elsewhere in the BeforeNavigate or the BeforeNavigate2 event handler.

These items should not appear in the frame.



RESOLUTION
To work around the problem with the scroll bar, use one of the following methods:
 * In the HTML source for the frame page, manually add the &quot;auto&quot; or the &quot;no&quot; value to the scroll attribute in the tag.
 * Add the scroll attribute dynamically through Dynamic HTML (DHTML).
 * Delay the navigation by posting a user-defined message and by performing the navigation in the user-defined message handler.

To work around the problem with the border, use one of the following methods:
 * Post a user-defined message, and then perform the navigation in the user-defined message handler.
 * Implement the IDocHostUIHandler interface, and then return DOCHOSTUIFLAG_NO3DBORDER in the GetHostInfo method.

For more information, see the &quot;More Information&quot; section of this article.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
NOTE: These steps are written for Microsoft Visual C++ 6.0.   Use the following code to create the frameset page, and then name the page frameset.htm:          </HTML> </li> <li>Copy frameset.htm to the Web server.</li> <li> Use the following code to create a frame page, and then name the page framesetChild.htm: <HTML> This is a frame </HTML> </li> <li>Copy framesetChild.htm to the Web server.</li> <li>Create a default Microsoft Foundation Classes (MFC) dialog-based application.</li> <li>Right-click the dialog, and then click Insert ActiveX Control. Click Microsoft Web Browser Control.</li> <li>To add a control data member for the WebBrowser control, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>Open the Class Wizard, and then click the Member Variables tab.</li> <li>Make sure that the dialog class is selected in the Class name list.</li> <li>Click IDC_EXPLORER1 (which is the default ID of the WebBrowser control), and then click Add Variable.</li> <li>You receive a message that states that the control has not been inserted into the project. Click OK to add the control to the project. Click OK again to accept the defaults for the CWebBrowser2 class in the Confirm Class dialog box.</li> <li>Name your member variable m_webBrowser, and then click OK.</li> <li>Close the Class Wizard.</li></ol> </li> <li>To add the BeforeNavigate2 event handler, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>Open the Class Wizard, and then click the Message Maps tab.</li> <li>Make sure that the dialog class is selected in the Class name list.</li> <li>Click IDC_EXPLORER1 in the Object IDs list, and then click BeforeNavigate2 in the Messages list.</li> <li>Click Add Function to add the handler.</li></ol> </li> <li> Add the following code: void CMFCReproDlg::OnBeforeNavigate2Explorer1(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel) {   static int nCount = 0;

nCount++; if (nCount == 2) // this should be the navigate for the first frame in frameset {       IWebBrowser* pWB = NULL; HRESULT hr = pDisp->QueryInterface(IID_IWebBrowser, (void**)&pWB); COleVariant ve((long)0); pWB->Navigate(::SysAllocString(L&quot;http://myserver/mydirectory/framesetChild.htm&quot;), &ve, &ve, &ve, &ve); *Cancel = VARIANT_TRUE; } }                   </li> <li> Add the following code to navigate to the frame page in the end of the OnInitDialog function. BOOL CMFCReproDlg::OnInitDialog {   ...    m_webBrowser.Navigate(&quot;http://myserver/mydirectory/frameset.htm&quot;, NULL, NULL, NULL, NULL); </li> <li>Build the application, and then run it. Notice that the first frame has a scroll bar and a border on the right side.</li></ol>

Remove the Scroll Bar
To remove the scroll bar, use one of following methods: <ul> <li> Add scroll attribute value of &quot;auto&quot; or &quot;no&quot; to the framesetChild.htm page as follows: <HTML> <body scroll=&quot;auto&quot;> This is a frame </HTML> </li> <li> Dynamically add the scroll attribute value of &quot;auto&quot; or &quot;no&quot; in your code through DHTML as follows: // For brevity, this code adds the attribute to all documents. void CMFCReproDlg::OnDocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT FAR* URL) {   HRESULT hr = S_OK; IWebBrowser2* pWB = NULL;
 * 1) include <mshtml.h>

hr = pDisp->QueryInterface(IID_IWebBrowser2, reinterpret_cast<void**>(&pWB)); IDispatch* pDocDisp = NULL; hr = pWB->get_Document(&pDocDisp); if (pDocDisp) {       VARIANT v;        VariantInit(&v);

IHTMLDocument2* pDoc = NULL; hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, reinterpret_cast<void **>(&pDoc));

IHTMLElement* pElement = NULL; hr = pDoc->get_body(&pElement);

IHTMLBodyElement* pBodyElement = NULL; hr = pElement->QueryInterface(IID_IHTMLBodyElement, (void**)&pBodyElement);

if (pBodyElement) {           pBodyElement->put_scroll(::SysAllocString(L&quot;auto&quot;)); pBodyElement->Release; }       pElement->Release; pDoc->Release; pDocDisp->Release; }   pWB->Release; }

NOTE: These first two options only remove the scroll bar. The border may still persist. </li> <li> Post a user-defined message, and then perform the navigation in the user-defined message handler to delay the navigation.

Add the following code to the header file: class CMFCReproDlg : public CDialog { ...   afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); }; Add the following code to the implementation file: BEGIN_MESSAGE_MAP(CMFCReproDlg, CDialog) //AFX_MSG_MAP ON_MESSAGE(WM_MYMESSAGE, OnMyMessage) END_MESSAGE_MAP
 * 1) define WM_MYMESSAGE (WM_USER + 1)

struct CMyData {   IWebBrowser2* m_pWB; BSTR m_pUrl; };

void CMFCReproDlg::OnBeforeNavigate2Explorer1(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel) {   static int nCount = 0;

nCount++; if (nCount == 2) // this should be the navigate for the first frame in frameset {       *Cancel = VARIANT_TRUE; CMyData *data = new CMyData; HRESULT hr = pDisp->QueryInterface(IID_IWebBrowser2, (void**)(&data->m_pWB)); data->m_pUrl = ::SysAllocString(L&quot;http://myserver/mydirectory/framesetChild.htm&quot;); PostMessage(WM_MYMESSAGE, (WPARAM)data, 0); } } LRESULT CMFCReproDlg::OnMyMessage(WPARAM wParam, LPARAM lParam) {   CMyData *data = (CMyData*)wParam; COleVariant ve((long)0); data->m_pWB->Navigate(data->m_pUrl, &ve, &ve, &ve, &ve); delete data; return 1; }                   </li></ul>

Remove the Border
To remove the borders, use one of following methods: <ul> <li>Post a user-defined message, and then perform the navigation in the user-defined message handler.</li> <li>Follow the steps in Microsoft Knowledge Base article Q196835 to provide the custom control site in which you can add the IDocHostUIHandler interface. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

196835 HOWTO: Override the MFC Default Control Containment

After you implement all the functions, you must add DOCHOSTUIFLAG_NO3DBORDER to the DOCHOSTUIINFO stucture in the dwFlags field for the GetHostInfo method. It is beyond the scope of this article to provide the steps to implement IDocHostUIHandler.</li></ul>

NOTE: The border problem does not appear in an Active Template Library (ATL) container because the ATL class, CAxHostWindow, already implements the IDocHostUIHandler interface. By default, CAxHostWindow enables this flag.

Additional query words: scrollbar frame navigate

Keywords: kbbug kbpending KB324419

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.