Hi folks. Unfortunately I'm a complete novice when it comes to this kind of native windows programming. I have been tasked with attempting to figure this out within our group alas. Essentially I need an activex control to open a new browser window. In addition to this I would like to have a reference to the new windows hwnd when its done. I've had some success with IWebBrowser2->Navigate but I really like the look of the features available with IHTMLDocument2->open.
The navigate code is fairly straightforward and works well:
VARIANT targetFrameName;
::VariantInit(&targetFrameName);
V_VT(&targetFrameName) = VT_BSTR;
V_BSTR(&targetFrameName) = bstrTarget;
BSTR url = (BSTR)wParam;
VARIANT vtEmpty;
::VariantInit(&vtEmpty);
hr = spWebBrowser->Navigate(url, &vtEmpty, &targetFrameName, &vtEmpty, &vtEmpty);
::SysFreeString(url);
::VariantClear(&targetFrameName);
Unfortunately this doesn't give me the hwnd of the new window (unless I'm doing it wrong?) or access to all of those handy javascript parameters. (which is what we want ideally) In any case, I attempted to use the following code:
IDispatch* pHtmlDocDispatch = NULL;
IHTMLDocument2 * pHtmlDoc = NULL;
hr = spWebBrowser->get_Document(&pHtmlDocDispatch);
if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL)) {
hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pHtmlDoc);
if (SUCCEEDED (hr) && (pHtmlDoc != NULL)) {
VARIANT targetFrameName;
::VariantInit(&targetFrameName);
V_VT(&targetFrameName) = VT_BSTR;
V_BSTR(&targetFrameName) = bstrTarget;
BSTR url = (BSTR)wParam;
BSTR bstrFT = L"";
VARIANT vtEmpty;
::VariantInit(&vtEmpty);
IDispatch* pNewHtmlDocDispatch = NULL;
pHtmlDoc->open(url, targetFrameName, vtEmpty, vtEmpty, &pNewHtmlDocDispatch);
::SysFreeString(url);
::VariantClear(&targetFrameName);
}
}
This causes a runtime "Debug Assertion Failed!" in atlwin.h.
Any pointers on using this function properly would be very much appreciated as documentation seems to be pretty thin on the ground.