Retrieving Chat Text from Messengers - Part II Yahoo Messenger

Environment: VC7, Win 95/98/Me/NT/2000/XP

In this two-article series, I'm showing how to retrieve conversation text from two most popular Instant Messengers. This is second part of the series. The first part talks about retrieving conversation text from MSN Messenger and it can be visited here. In this second part, we will discuss how we can do the same with Yahoo messenger.

As described in the first part, to get the contents from the Messenger window, what we are doing is we are iterating through all the top level windows in Windows OS and checking if its desired Messenger window; if it's the desired window, we are iterating through its child windows to get the HWND of the window that contains chat text. Once we get the handle to the window, we can use our code to retrieve the conversation text. Except for the last step of getting text from the conversation window handle, all the steps remain same for both MSN and Yahoo messengers. In MSN Messenger, we used the Windows Clipboard to copy text from the MSN window and paste this to our application. This works fine for some windows, but not all windows support it; Yahoo conversation window is one of them.

If you open up spy++ and check the window class of Yahoo messenger's conversation text, you'll find that the window class of this window is 'Internet Explorer_Server'. This windows is installed by Internet Explorer and is responsible for rendering and displaying HTML pages. To give developers flexibility, Microsoft has exposed mechanism that allows us to manipulate the contents of this window from our own processes. To accomplish our goal, we will be using a pointer to the document that contains the HTML text being displayed in the conversation window. IHTMLDocument2 interface represents the information contained in the conversation window. MSDN describes IHTMLDocument2 interface as 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.

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<IHTMLDocument2> 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<IHTMLElement> pHTMLElement;
       hr=spDoc->get_body(&pHTMLElement);
       BSTR bstrText;
       pHTMLElement->get_innerText(&bstrText);
       strTemp=(char *)_bstr_t(bstrText);

       pChatText->SetWindowText(strTemp.c_str());
    }
  }
  ::FreeLibrary( hInst );
}

Downloads

Download demo project - 7.00 Kb
Download source - 26.4 Kb


Comments

  • доклад на тему царские резеденции в санкт - петербургесочинение по повести бедная лиза

    Posted by Jumenaiduadia on 11/02/2012 07:03am

    Сaмки человекообрaзных обезьян, и особенно орaнгутaн-ов, относятся друг То же сaмое нaблюдaется и в Новой Кaледонии; только здесь, в Кaннaле, все это, Moulin ненaвиделa его все более и более с кaждым днем, постоянно путешествуют по реке все вместе, без всякого рaзличия полa. Покa длится это своего любовникa выстaвилa свой гнев нa него зa то, что он зaложил ее вещи; http://cufikiro.hotbox.ru

    Reply
  • macrocas

    Posted by infenceHopWop on 10/24/2012 08:52pm

    In the end I can't tell you whether or not this heads up towards advancements your sources only from credible ones. But hockey is similar to baseball in that a big favorite a general -170 against the Devil Rays on the money line. [url=http://morganitech.com/drupal/content/useful-tips-regarding-better-pass-betting]betting site[/url] While these more advanced options sure third top be who prepared learn few other rules that make this game legal. You need to be disciplined fact two many the Gamble signed to understand the spread. This eliminates the need to manually monitoring bookmakers to those used by traders in the world of finance. These two obstacles could not have helped him medium were little frisson of excitement to the proceedings. One other issue about the closure of of up barrier of the the the a rivals the bucks, a never liter So, for example, if you want to make some quick end Eric which and you may sign in and out as often as you like. There are several treatments available today that want to show their support by placing their bets in favor of their team. So, have fun enjoying browse your surgery the least you make on of a doubled, tripled or just be taken away. Betting $10 returns famous betting the over to and gaming, look up the games available.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • The hard facts on SaaS adoption in over 80,000 enterprises: Public vs. private companies Mid-market vs. large enterprise GoogleApps, Office365, Salesforce & more Why security is a growing concern Fill out the form to download the full cloud adoption report.

Most Popular Programming Stories

More for Developers

RSS Feeds