changeset 2021:0cce5fed4594

Win: get_HWND method does not seem to be working, so use Set/GetProperty() to save the browser window handle for use in the DWebBrowserEvents2 callbacks.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 09 Nov 2019 06:33:08 +0000
parents 59dfb86fb3b1
children 28809bf17957
files win/browser.c win/dw.c
diffstat 2 files changed, 34 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/win/browser.c	Fri Nov 08 13:06:47 2019 +0000
+++ b/win/browser.c	Sat Nov 09 06:33:08 2019 +0000
@@ -1162,12 +1162,15 @@
 			// Params are in the variant array from right to left wrt how they are defined in the documentation.
 			LPCWSTR pszURL = pDispParams->rgvarg[5].pvarVal->bstrVal;
 			IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref;
-			LONG_PTR tmp;
+			VARIANT vWindow;
+			BSTR bstrProp = SysAllocString(L"DWindow");
 			HWND hwnd;
 
 			/* Get the window handle and URL */
-			pwb->lpVtbl->get_HWND(pwb, &tmp);
-			hwnd = (HWND)tmp;
+			vWindow.vt = VT_UI8;
+			pwb->lpVtbl->GetProperty(pwb, bstrProp, &vWindow);
+			hwnd = (HWND)vWindow.ullVal;
+			SysFreeString(bstrProp);
 			/* Send the event for signal handling */
 			_wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), (LPARAM)WideToUTF8((LPWSTR)pszURL));
 
@@ -1178,13 +1181,16 @@
 		case DISPID_DOCUMENTCOMPLETE:
 		{
 			IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref;
-			LONG_PTR tmp;
+			VARIANT vWindow;
+			BSTR bstrProp = SysAllocString(L"DWindow");
 			HWND hwnd;
 			BSTR locationURL;
 
 			/* Get the window handle and URL */
-			pwb->lpVtbl->get_HWND(pwb, &tmp);
-			hwnd = (HWND)tmp;
+			vWindow.vt = VT_UI8;
+			pwb->lpVtbl->GetProperty(pwb, bstrProp, &vWindow);
+			hwnd = (HWND)vWindow.byref;
+			SysFreeString(bstrProp);
 			pwb->lpVtbl->get_LocationURL(pwb, &locationURL);
 			/* Send the event for signal handling */
 			_wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), (LPARAM)WideToUTF8((LPWSTR)locationURL));
@@ -1809,6 +1815,8 @@
 			IConnectionPointContainer	*container;
 			IConnectionPoint			*point;
 			HRESULT						hr;
+			VARIANT						vWindow;
+			BSTR							bstrProp;
 
 			// Ok, now the pointer to our IWebBrowser2 object is in 'webBrowser2', and so its VTable is
 			// webBrowser2->lpVtbl.
@@ -1822,6 +1830,14 @@
 			webBrowser2->lpVtbl->put_Width(webBrowser2, rect.right);
 			webBrowser2->lpVtbl->put_Height(webBrowser2, rect.bottom);
 
+			// Save the window handle as a property for later use
+			VariantInit(&vWindow);
+			vWindow.vt = VT_UI8;
+			vWindow.ullVal = (ULONGLONG)hwnd;
+			bstrProp = SysAllocString(L"DWindow");
+			webBrowser2->lpVtbl->PutProperty(webBrowser2, bstrProp, vWindow);
+			SysFreeString(bstrProp);
+
 			// Get IWebBrowser2' IConnectionPointContainer sub-object. We do this by calling
 			// IWebBrowser2' QueryInterface, and pass it the standard GUID for an
 			// IConnectionPointContainer VTable
--- a/win/dw.c	Fri Nov 08 13:06:47 2019 +0000
+++ b/win/dw.c	Sat Nov 09 06:33:08 2019 +0000
@@ -2386,16 +2386,22 @@
                   break;
                case WM_USER+100:
                   {
-                      int (DWSIGNAL *htmlresultfunc)(HWND, int, char *, void *, void *) = tmp->signalfunction;
-                      
-                      return htmlresultfunc(tmp->window, mp1 ? DW_ERROR_NONE : DW_ERROR_UNKNOWN, (char *)mp1, (void *)mp2, tmp->data);
+                     if(hWnd == tmp->window)
+                     {
+                        int (DWSIGNAL *htmlresultfunc)(HWND, int, char *, void *, void *) = tmp->signalfunction;
+
+                        return htmlresultfunc(tmp->window, mp1 ? DW_ERROR_NONE : DW_ERROR_UNKNOWN, (char *)mp1, (void *)mp2, tmp->data);
+                     }
                   }
                   break;
                case WM_USER+101:
                   {
-                      int (DWSIGNAL *htmlchangedfunc)(HWND, int, char *, void *) = tmp->signalfunction;
-                      
-                      return htmlchangedfunc(tmp->window, DW_POINTER_TO_INT(mp1), (char *)mp2, tmp->data);
+                     if(hWnd == tmp->window)
+                     {
+                        int (DWSIGNAL *htmlchangedfunc)(HWND, int, char *, void *) = tmp->signalfunction;
+
+                        return htmlchangedfunc(tmp->window, DW_POINTER_TO_INT(mp1), (char *)mp2, tmp->data);
+                     }
                   }
                   break;
             }