Hi Folks,
In C++, I am creating an IE window (IE7) with CoCreateInstance, and using Navigate2 to navigate to a web page. I want to be able to get the handle to the IE window created by Navigate2. Notice in Navigate2, I give a window name as a parameter. Using get_HWND() is not working. I'm getting a handle to an IE window but not the one that has the URL I navigated to. I want to use this handle to restore the IE Window if it happens to be minimized. But so far, while I do get an IE handle (which I suspect is the "main" ie window") calling functions with this handle do nothing to the IE window I care about, the one with the newly navigated to page. Any idea what I'm doing wrong? Code below.
IWebBrowser2* pIE;
hr = CoCreateInstance(CLSID_InternetExplorer,
NULL,
CLSCTX_LOCAL_SERVER,
IID_IWebBrowser2,
(void**)&pIE);
if( SUCCEEDED(hr) )
{
VARIANT vtEmpty;
VARIANT vtTarget;
VARIANT vtUrl;
VariantInit(&vtEmpty);
VariantInit(&vtTarget);
VariantInit(&vtUrl);
vtTarget.vt = VT_BSTR;
vtTarget.bstrVal = SysAllocString(L"RAD_AUTHIE_WINDOW");
vtUrl.vt = VT_BSTR;
vtUrl.bstrVal = SysAllocString(strAuthURL);
hr = pIE->Navigate2(&vtUrl,&vtEmpty,&vtTarget,&vtEmpty,&vtEmpty);
HWND hWnd = NULL;
pIE->get_HWND((SHANDLE_PTR*)&hWnd);
if (hWnd != NULL)
{
//not the right window handle
::ShowWindow(hWnd,SW_NORMAL);
}
VariantClear(&vtTarget);
VariantClear(&vtUrl);
pIE->Quit();
pIE->Release();