Getting the Webgadget content?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi,

I want to get the text on the webgadget, i found this source but dont know how to do it in PureBasic, hope that somebody could help, here is with the explanation:

*I dont need the url because i want to read the actual content, suppouse its a mail writing that is unsing webgadget, then there is no url.
---------------------------------------------------------------------

This interface retrieves information about the document, and examines and modifies the HTML elements and text within the document..
So, to get the pointer to the IHTMLDocument2 interface, we will send a 'WM_HTML_GETOBJECT' window message to the 'Internet Explorer_Server' window and pass the result to the ObjectFromLresult() method. A successful call to the ObjectFromLresult() method gives us a pointer to the IHTMLDocument2 interface. Finally, to get the entire text in our application, we call the body property of IHTMLDocument2, which returns us a pointer to the IHTMLElement interface and calls the innerText property of the IHTMLElement interface, which returns us the entire text contained in the conversation text. If you want to get this in its original HTML form, you can call the innerHTML property of IHTMLElement. This will be clear from the following code snippet.

Code: Select all

char wndowclass[CLASS_SIZE];
if (GetClassName(hwnd,wndowclass,CLASS_SIZE)==0)
  return TRUE;
string strTemp(wndowclass);
if (strTemp==string("Internet Explorer_Server"))
{
  CoInitialize(NULL);
  HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
  string strTemp;
  CComPtr spDoc;
  LRESULT lRes;
  strTemp="";
  UINT nMsg = ::RegisterWindowMessage( 
                        _T("WM_HTML_GETOBJECT") );
  ::SendMessageTimeout( hwnd,
                        nMsg,
                        0L, 
                        0L,
                        SMTO_ABORTIFHUNG,
                        1000,
                        (DWORD*)&lRes );
  LPFNOBJECTFROMLRESULT pfObjectFromLresult =
      (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst,
                           _T("ObjectFromLresult") );
  if ( pfObjectFromLresult != NULL )
  {
     HRESULT hr;
     hr = (*pfObjectFromLresult)( lRes,
                                  IID_IHTMLDocument2,
                                  0, 
                                  (void**)&spDoc );
     if ( SUCCEEDED(hr) )
     {
       CComPtr pHTMLElement;
       hr=spDoc->get_body(&pHTMLElement);
       BSTR bstrText;
       pHTMLElement->get_innerText(&bstrText);
       strTemp=(char *)_bstr_t(bstrText);
       pChatText->SetWindowText(strTemp.c_str());
    }
  }
  ::FreeLibrary( hInst );
}
Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by CoderLaureate.

Hey Ricardo.

Did you want to get the text only from the web gadget, or the whole html? Because if you want to do that look into the InternetOpen_() and InternetOpenUrl_() API functions. I believe you can use these to just open up a web page and load it's contents directly into memory.

Probably pretty usefull for Bot programs.


-Jim

---------------------------------------------
AMD Duron 950Mhz/Windows XP Pro
http://www.BlueFireStudios.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by CoderLaureate.

Sorry Ricardo.

Plz disregard my last post. As I re-read your request I realized that wasn't what you were looking for. Sorry :).


-Jim

---------------------------------------------
AMD Duron 950Mhz/Windows XP Pro
http://www.BlueFireStudios.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

@CodeLaureate

Hi,

In fact resolving this question we can have enough control over webgadget because in this very case i want to use GetInnerText, but you can call many other procedures. I mean, resolving this problem we will have access to entire DOM model of a web page, and then we can work it in many ways.
I use DOM model via VB many times and its incredible the things that can be done, i could be nice to find a way to have access to DOM model.

Best Regards

Ricardo

Dont cry for me Argentina...
Post Reply