Navigating to a Specified URL (Windows Embedded CE 6.0)
1/6/2010
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 that is defined in the browser class, NavigateToURL, that browses to the specified URL by using Web browser methods such as Navigate2 and GoHome. If a URL is not provided, 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;
}