Article ID: 259963 - Last Review: May 11, 2006 - Revision: 3.0

How To Obtain Width and Height Supplied to Window.open Inside the Visual C++ WebBrowser Host

This article was previously published under Q259963
Expand all | Collapse all

SUMMARY

C++ applications that host the WebBrowser control can catch a window.open() call that is generated from script by handling the NewWindow2 event on the DWebBrowserEvents2 interface. However, it is not immediately obvious how your application can obtain the width and height values passed to the features argument of window.open() so that the WebBrowser host can resize the window correctly.

MORE INFORMATION

Your WebBrowser control container must implement the OnPosRectChange() method of the IOleInPlaceSite interface. The WebBrowser control will call this method on its host shortly after instantiating the new window.

Developers who insert a WebBrowser control directly onto a Microsoft Foundation Classes (MFC) dialog box have this functionality provided for them by MFC. Active Template Library (ATL) developers and MFC developers who write their own hosting code must implement this themselves.

The following ATL code resizes both the WebBrowser control and its containing window to fit the parameters supplied to window.open(). The code assumes your WebBrowser control host is derived from ATL's CWindow class.
STDMETHODIMP OnPosRectChange(LPCRECT lprcPosRect) {
	CComQIPtr<IOleInPlaceObject> ieIP;
	HRESULT hr = S_OK;
		
	ATLTRACE("new width and height for this WebOC instance are %d and %d\n", lprcPosRect->right, lprcPosRect->bottom);
	if (webOC) {
		ieIP = webOC;
		if (ieIP) {
                        hr = ieIP->SetObjectRects(lprcPosRect, lprcPosRect);
                        if (SUCCEEDED(hr) {
                                // Change the height of the window to match the webOC's height.
                                // ResizeClient() calls the Win32 function
                                // Set WindowPos()
                               BOOL bRet = ResizeClient(lprcPosRect->right, lprcPosRect->bottom, TRUE);
                               if (!bRet) {
                                       hr = E_FAIL;
                               }
                        }
		} else {
                        hr = E_FAIL;
                }
	}
	return hr;
}
				

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn.microsoft.com/ie/ (http://msdn.microsoft.com/ie/)

http://support.microsoft.com/iep (http://support.microsoft.com/iep)


APPLIES TO
  • Microsoft Internet Explorer 4.0 128-Bit Edition
  • Microsoft Internet Explorer 4.01 Service Pack 2
  • Microsoft Internet Explorer 4.01 Service Pack 1
  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer 5.5
Keywords: 
kbhowto kbwebbrowser KB259963
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations

 

Related Support Centers