Partager via


Navigating to a Specified URL (Windows CE 5.0)

Send Feedback

After you register the event sink with the Web browser object, as described in Setting Up Event Sinks, you can use the browser to navigate to a specified URL.

The following code example shows a method defined in the browser class, NavigateToURL, that navigates to the specified URL by using Web browser methods such as Navigate2 and GoHome. If a URL is not provided, then the browser shows the default home page.

HRESULT CBrowser::NavigateToURL(LPWSTR szURL)
{
  HRESULT hr;
  // Check for the browser.
  if (!_pWB2)
      return E_FAIL; 
  // Package the URL as a BSTR for Navigate.
  VARIANT varURL;
  V_VT(&varURL) = VT_EMPTY;
  if(szURL && szURL[0] != L'\0')
  {
    V_VT(&varURL) = VT_BSTR;
    varURL.bstrVal = SysAllocString(szURL);
    if(varURL.bstrVal)
    {
        // Call IWebBrowser2::Navigate2 with no special options.
        hr = _pWB2->Navigate2(&varURL, NULL, NULL, NULL, NULL);
    }
  }
  else
  {
// If there is no URL, go to the default homepage. 
    hr = _pWB2->GoHome();
  }
  // Clean up the BSTR if it exists.
  VariantClear(&varURL);
  return hr;
}

See Also

Creating an Internet Browser

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.