views:

173

answers:

0

I try to load various URL in IE but always in the same tab (under IE7/8). The code works well except that it opens a new blank IE window every time. If I do not give a frame name to Navigate2, the new window is not created but I get a new tab every time which is not what I want.

if (SUCCEEDED(OleInitialize(NULL)))
{
 IWebBrowser2*    pBrowser2;
 CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (void**)&pBrowser2);
 if (pBrowser2)
 {
  VARIANT vEmpty,vFrameName,vFlags,vURL;
  VariantInit(&vEmpty);

  BSTR bstrURL = SysAllocString(L"http://www.google.com");
  vURL.vt = VT_BSTR; vURL.bstrVal = bstrURL;

  // vFrameName reuse the windows/tab if it already exists)
  BSTR bstrFrameName = SysAllocString(L"MyTab");
  vFrameName.vt = VT_BSTR; vFrameName.bstrVal = bstrFrameName;


  // navOpenInNewTab : opens a new tab to navigate
  vFlags.vt = VT_UI4;
  vFlags.ulVal = navOpenInNewTab;

  HRESULT hr = pBrowser2->Navigate2(&vURL, &vFlags, &vFrameName, &vEmpty, &vEmpty);
  if (SUCCEEDED(hr))
  {
   pBrowser2->put_Visible(VARIANT_TRUE);
  }
  else
  {
   pBrowser2->Quit();
  }

  SysFreeString(bstrURL);
  SysFreeString(bstrFrameName);
  pBrowser2->Release();
 }

 OleUninitialize();
}

I tried the following combinaisons :
- FrameName = NULL & Flag = 0 :I get a new window with each call
- FrameName = MyTab & Flag = 0 : I get the new window created (but blank)
- FrameName = NULL & Flag = navOpenInNewTab : I get a new tab created with each call
- FrameName = MyTab & Flag = navOpenInNewTab : I get the new window