Hello.
James Hawkins wrote:
Hi,
Changelog
- Add the WebBrowser implementation.
- Load the default Url in the HTML Pane.
...
+static HRESULT STDMETHODCALLTYPE UI_ShowContextMenu(IDocHostUIHandler *iface, DWORD dwID, POINT __RPC_FAR *ppt, IUnknown __RPC_FAR *pcmdtReserved, IDispatch __RPC_FAR *pdispReserved)
You don't need to add __RPC_FAR here. Same in few other places.
+BOOL WB_EmbedBrowser(WBInfo *pWBInfo, HWND hwndParent) +{
- IOleClientSiteImpl *iOleClientSiteImpl;
- IOleObject *browserObject;
- IWebBrowser2 *webBrowser2;
- HRESULT hr;
- RECT rc;
- static const WCHAR hostNameW[] = {'H','o','s','t',' ','N','a','m','e',0};
- iOleClientSiteImpl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(IOleClientSiteImpl));
- if (!iOleClientSiteImpl)
return FALSE;
- iOleClientSiteImpl->ref = 0;
- iOleClientSiteImpl->lpVtbl = &MyIOleClientSiteTable;
- iOleClientSiteImpl->lpvtblOleInPlaceSite = &MyIOleInPlaceSiteTable;
- iOleClientSiteImpl->lpvtblOleInPlaceFrame = &MyIOleInPlaceFrameTable;
- iOleClientSiteImpl->hwndWindow = hwndParent;
- iOleClientSiteImpl->lpvtblDocHostUIHandler = &MyIDocHostUIHandlerTable;
- hr = OleCreate(&CLSID_WebBrowser, &IID_IOleObject, OLERENDER_DRAW, 0,
(IOleClientSite *)iOleClientSiteImpl, &MyIStorage,
(void **)&browserObject);
- if (FAILED(hr)) goto error;
- /* make the browser object accessible to the IOleClientSite implementation */
- iOleClientSiteImpl->pBrowserObject = browserObject;
- IOleObject_SetHostNames(browserObject, hostNameW, 0);
- GetClientRect(hwndParent, &rc);
- hr = OleSetContainedObject((struct IUnknown *)browserObject, TRUE);
- if (FAILED(hr)) goto error;
- hr = OleSetContainedObject((struct IUnknown *)browserObject, TRUE);
- if (FAILED(hr)) goto error;
Why do you call OleSetContainedObject twice?
- hr = IOleObject_DoVerb(browserObject, OLEIVERB_SHOW, NULL,
(IOleClientSite *)iOleClientSiteImpl,
-1, hwndParent, &rc);
- if (FAILED(hr)) goto error;
- hr = IOleObject_QueryInterface(browserObject, &IID_IWebBrowser2,
(void **)&webBrowser2);
- if (SUCCEEDED(hr))
- {
IWebBrowser2_put_Left(webBrowser2, 0);
IWebBrowser2_put_Top(webBrowser2, 0);
IWebBrowser2_put_Width(webBrowser2, rc.right);
IWebBrowser2_put_Height(webBrowser2, rc.bottom);
pWBInfo->pOleClientSite = (IOleClientSite *)iOleClientSiteImpl;
pWBInfo->pBrowserObject = browserObject;
pWBInfo->pWebBrowser2 = webBrowser2;
pWBInfo->hwndParent = hwndParent;
return TRUE;
- }
+error:
- WB_UnEmbedBrowser(pWBInfo);
- if (webBrowser2)
IWebBrowser2_Release(webBrowser2);
- HeapFree(GetProcessHeap(), 0, iOleClientSiteImpl);
- return FALSE;
+}
...
+BOOL WB_Navigate(WBInfo *pWBInfo, LPCWSTR szUrl) +{
- IWebBrowser2 *pWebBrowser2 = pWBInfo->pWebBrowser2;
- VARIANT myURL;
- if (!pWebBrowser2)
return FALSE;
- VariantInit(&myURL);
- myURL.n1.n2.vt = VT_BSTR;
- myURL.n1.n2.n3.bstrVal = SysAllocString(szUrl);
It's better to use macros to use VARIANT type: V_VT(&myURL) = VT_BSTR; V_BSTR(&myURL) =SysAllocString(szUrl);
- if (!myURL.n1.n2.n3.bstrVal)
return FALSE;
- IWebBrowser2_Navigate2(pWebBrowser2, &myURL, 0, 0, 0, 0);
- VariantClear(&myURL);
- return TRUE;
+}
Jacek