Mercurial > dwindows
comparison win/browser.c @ 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 | 583c2d62845c |
children | 28809bf17957 |
comparison
equal
deleted
inserted
replaced
2020:59dfb86fb3b1 | 2021:0cce5fed4594 |
---|---|
1160 case DISPID_BEFORENAVIGATE2: | 1160 case DISPID_BEFORENAVIGATE2: |
1161 { | 1161 { |
1162 // Params are in the variant array from right to left wrt how they are defined in the documentation. | 1162 // Params are in the variant array from right to left wrt how they are defined in the documentation. |
1163 LPCWSTR pszURL = pDispParams->rgvarg[5].pvarVal->bstrVal; | 1163 LPCWSTR pszURL = pDispParams->rgvarg[5].pvarVal->bstrVal; |
1164 IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref; | 1164 IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref; |
1165 LONG_PTR tmp; | 1165 VARIANT vWindow; |
1166 BSTR bstrProp = SysAllocString(L"DWindow"); | |
1166 HWND hwnd; | 1167 HWND hwnd; |
1167 | 1168 |
1168 /* Get the window handle and URL */ | 1169 /* Get the window handle and URL */ |
1169 pwb->lpVtbl->get_HWND(pwb, &tmp); | 1170 vWindow.vt = VT_UI8; |
1170 hwnd = (HWND)tmp; | 1171 pwb->lpVtbl->GetProperty(pwb, bstrProp, &vWindow); |
1172 hwnd = (HWND)vWindow.ullVal; | |
1173 SysFreeString(bstrProp); | |
1171 /* Send the event for signal handling */ | 1174 /* Send the event for signal handling */ |
1172 _wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), (LPARAM)WideToUTF8((LPWSTR)pszURL)); | 1175 _wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), (LPARAM)WideToUTF8((LPWSTR)pszURL)); |
1173 | 1176 |
1174 // Make sure you don't accidently cancel the navigation. | 1177 // Make sure you don't accidently cancel the navigation. |
1175 *V_BOOLREF(&pDispParams->rgvarg[0]) = VARIANT_FALSE; | 1178 *V_BOOLREF(&pDispParams->rgvarg[0]) = VARIANT_FALSE; |
1176 break; | 1179 break; |
1177 } | 1180 } |
1178 case DISPID_DOCUMENTCOMPLETE: | 1181 case DISPID_DOCUMENTCOMPLETE: |
1179 { | 1182 { |
1180 IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref; | 1183 IWebBrowser2* pwb = (IWebBrowser2*)pDispParams->rgvarg[pDispParams->cArgs - 1].byref; |
1181 LONG_PTR tmp; | 1184 VARIANT vWindow; |
1185 BSTR bstrProp = SysAllocString(L"DWindow"); | |
1182 HWND hwnd; | 1186 HWND hwnd; |
1183 BSTR locationURL; | 1187 BSTR locationURL; |
1184 | 1188 |
1185 /* Get the window handle and URL */ | 1189 /* Get the window handle and URL */ |
1186 pwb->lpVtbl->get_HWND(pwb, &tmp); | 1190 vWindow.vt = VT_UI8; |
1187 hwnd = (HWND)tmp; | 1191 pwb->lpVtbl->GetProperty(pwb, bstrProp, &vWindow); |
1192 hwnd = (HWND)vWindow.byref; | |
1193 SysFreeString(bstrProp); | |
1188 pwb->lpVtbl->get_LocationURL(pwb, &locationURL); | 1194 pwb->lpVtbl->get_LocationURL(pwb, &locationURL); |
1189 /* Send the event for signal handling */ | 1195 /* Send the event for signal handling */ |
1190 _wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), (LPARAM)WideToUTF8((LPWSTR)locationURL)); | 1196 _wndproc(hwnd, WM_USER+101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), (LPARAM)WideToUTF8((LPWSTR)locationURL)); |
1191 break; | 1197 break; |
1192 } | 1198 } |
1807 !browserObject->lpVtbl->QueryInterface(browserObject, &IID_IWebBrowser2, (void**)&webBrowser2)) | 1813 !browserObject->lpVtbl->QueryInterface(browserObject, &IID_IWebBrowser2, (void**)&webBrowser2)) |
1808 { | 1814 { |
1809 IConnectionPointContainer *container; | 1815 IConnectionPointContainer *container; |
1810 IConnectionPoint *point; | 1816 IConnectionPoint *point; |
1811 HRESULT hr; | 1817 HRESULT hr; |
1818 VARIANT vWindow; | |
1819 BSTR bstrProp; | |
1812 | 1820 |
1813 // Ok, now the pointer to our IWebBrowser2 object is in 'webBrowser2', and so its VTable is | 1821 // Ok, now the pointer to our IWebBrowser2 object is in 'webBrowser2', and so its VTable is |
1814 // webBrowser2->lpVtbl. | 1822 // webBrowser2->lpVtbl. |
1815 | 1823 |
1816 // Let's call several functions in the IWebBrowser2 object to position the browser display area | 1824 // Let's call several functions in the IWebBrowser2 object to position the browser display area |
1819 // also note that the first arg we pass to each is the pointer to the IWebBrowser2 object. | 1827 // also note that the first arg we pass to each is the pointer to the IWebBrowser2 object. |
1820 webBrowser2->lpVtbl->put_Left(webBrowser2, 0); | 1828 webBrowser2->lpVtbl->put_Left(webBrowser2, 0); |
1821 webBrowser2->lpVtbl->put_Top(webBrowser2, 0); | 1829 webBrowser2->lpVtbl->put_Top(webBrowser2, 0); |
1822 webBrowser2->lpVtbl->put_Width(webBrowser2, rect.right); | 1830 webBrowser2->lpVtbl->put_Width(webBrowser2, rect.right); |
1823 webBrowser2->lpVtbl->put_Height(webBrowser2, rect.bottom); | 1831 webBrowser2->lpVtbl->put_Height(webBrowser2, rect.bottom); |
1832 | |
1833 // Save the window handle as a property for later use | |
1834 VariantInit(&vWindow); | |
1835 vWindow.vt = VT_UI8; | |
1836 vWindow.ullVal = (ULONGLONG)hwnd; | |
1837 bstrProp = SysAllocString(L"DWindow"); | |
1838 webBrowser2->lpVtbl->PutProperty(webBrowser2, bstrProp, vWindow); | |
1839 SysFreeString(bstrProp); | |
1824 | 1840 |
1825 // Get IWebBrowser2' IConnectionPointContainer sub-object. We do this by calling | 1841 // Get IWebBrowser2' IConnectionPointContainer sub-object. We do this by calling |
1826 // IWebBrowser2' QueryInterface, and pass it the standard GUID for an | 1842 // IWebBrowser2' QueryInterface, and pass it the standard GUID for an |
1827 // IConnectionPointContainer VTable | 1843 // IConnectionPointContainer VTable |
1828 if ((hr = webBrowser2->lpVtbl->QueryInterface(webBrowser2, &IID_IConnectionPointContainer, &container))) | 1844 if ((hr = webBrowser2->lpVtbl->QueryInterface(webBrowser2, &IID_IConnectionPointContainer, &container))) |