But for Modern-applications everything is different. Let's take, for example, the Weather app from the standard Windows8 set. Suppose we opened it in the sidebar and want to somehow find out from our usual (Desktop) application, and what temperature it shows. If you look at the Weather window using Spy ++, you will see the parent window of the Windows.UI.Core.CoreWindow type and the Web Platform Embedding window attached to it. So we have a Modern-application written in HTML \ Js and living inside the embedded browser component. That is, the above-described manipulations with Windows controls do not make sense - they are simply not in this window, since all of its contents are rendered entirely.ObjectFromLresult they are trying to take the wrong interface and in the end nothing works. But this is generally MSDN style, you have to get used to it.
 #include "stdafx.h" #include <iostream> #include <sstream> #include <mshtml.h> #include <atlbase.h> #include <oleacc.h> #include "conio.h" using namespace std; BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam) { TCHAR buf[100]; ::GetClassName( hwnd, (LPTSTR)&buf, 100 ); if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 ) { *(HWND*)lParam = hwnd; return FALSE; } else return TRUE; }; void GetDocInterface(HWND hWnd) { CoInitialize( NULL ); // Explicitly load MSAA so we know if it's installed HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") ); if ( hInst != NULL ) { if ( hWnd != NULL ) { HWND hWndChild=NULL; // Get 1st document window ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild ); if ( hWndChild ) { CComPtr<IHTMLDocument2> spDoc; LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") ); ::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, "ObjectFromLresult" ); if ( pfObjectFromLresult != NULL ) { HRESULT hr; hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument2, 0, (void**)&spDoc ); if ( SUCCEEDED(hr) ) { BSTR bstrContent = NULL; IHTMLElement *p = 0; spDoc->get_body(&p); if (p) { p->get_innerHTML( &bstrContent ); std::wstring ws(bstrContent, SysStringLen(bstrContent)); std::string s(ws.begin(), ws.end()); cout << s; p->Release(); } } } } // else document not ready } // else Internet Explorer is not running ::FreeLibrary( hInst ); } // else Active Accessibility is not installed CoUninitialize(); } int _tmain(int argc, _TCHAR* argv[]) { wstring windowTitle, windowClass; wcout << "Please enter parent window title (you can find it by Spy++):" << endl; std::getline(std::wcin, windowTitle); wcout << "Please enter parent window class (you can find it by Spy++):" << endl; std::getline(std::wcin, windowClass); HWND hwnd = FindWindow(windowClass.c_str(), windowTitle.c_str()); wcout << "HWND is " << hwnd << endl; GetDocInterface(hwnd); _getch(); return 0; } Source: https://habr.com/ru/post/206656/
All Articles