Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / ATL
Article

Retrieving Conversations from Yahoo Messenger

Rate me:
Please Sign up or sign in to vote.
4.06/5 (15 votes)
27 Feb 20032 min read 134.2K   3.6K   40   18
Describes how to retreive text from the Yahoo Messenger chat window using the MSHTML COM interfaces.

Sample Image - maximum width is 600 pixels

Introduction

In this second article I'm showing how to retrieve conversation text from Yahoo messenger. The first article talks about retrieving conversation text from MSN Messenger and it can be viewed here. In this second article, we will discuss how we can do the same with Yahoo messenger.

As described in first article, 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 its the desired window then 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 the last step of getting text from 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 pasting this on our application. This works fine for some windows but not all windows support it; the 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 mechanisms 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 HTML text being displayed in the conversation window. IHTMLDocument2 interface represents the information contained in the conversation window. MSDN describes the 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 IHTMLDocument2 interface, we will send WM_HTML_GETOBJECT window message to 'Internet Explorer_Server' window and pass the result to the ObjectFromLresult() method. A successful call to ObjectFromLresult() method gives us a pointer to IHTMLDocument2 interface. Finally, to get the entire text in our application we get the body property of IHTMLDocument2 which returns us a pointer to the IHTMLElement interface and getting the <code lang="c++">innerText property of IHTMLElement interface returns us the entire text contained in the conversation text. If you want to get this in original HTML form then you can call innerHTML property of IHTMLElement.

This should be clear from the following code snippet:

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

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
www.d2labs.com
blogs.d2labs.com

Comments and Discussions

 
Generalym 11 compatibility Pin
fls_tr28-Apr-11 15:59
fls_tr28-Apr-11 15:59 
Generalfor yahoo 10 Pin
dangngocbinh_11-May-10 3:48
dangngocbinh_11-May-10 3:48 
QuestionHow can we send a message to friend? Pin
luutran.it21-Nov-06 17:59
luutran.it21-Nov-06 17:59 
Generalon MAC OS X Pin
Krish Nimmagadda16-Jan-06 7:18
Krish Nimmagadda16-Jan-06 7:18 
GeneralRe: on MAC OS X Pin
macuser55511-Nov-07 6:00
macuser55511-Nov-07 6:00 
Questiondoes not work Pin
rajan_ singh11-Oct-05 23:13
rajan_ singh11-Oct-05 23:13 
Questiondoes not work Pin
rajan_ singh11-Oct-05 23:11
rajan_ singh11-Oct-05 23:11 
QuestionCan not get any text! ? Pin
Member 3672122-Sep-05 17:27
Member 3672122-Sep-05 17:27 
Generalcapture friend list Pin
munyuk18-May-05 17:47
munyuk18-May-05 17:47 
GeneralA question Pin
ThatsAlok17-Mar-05 20:09
ThatsAlok17-Mar-05 20:09 
Hello Friend,
the backbone of your app "ObjectFromLresult" is onbly supported on Window 2000/xp.

could you please suggest me similiar function for window single user plateform

Thanks


[Vote One Here, Complete my Survey....]

Alok Gupta
visit me at http://www.thisisalok.tk

         "I Think Believe this Will Help"
QuestionHow do we change the status text? Pin
Core Dumped3-Feb-04 6:18
Core Dumped3-Feb-04 6:18 
AnswerRe: How do we change the status text? Pin
asa si ?18-Jun-04 8:52
asa si ?18-Jun-04 8:52 
GeneralRe: How do we change the status text? Pin
Lunatikul25-Jan-05 12:06
Lunatikul25-Jan-05 12:06 
GeneralRe: How do we change the status text? Pin
haha62417-Feb-05 22:34
haha62417-Feb-05 22:34 
GeneralBUG - Memory lick Pin
crowe3-Nov-03 1:46
crowe3-Nov-03 1:46 
GeneralMSN 6 Pin
myself150627-Jul-03 1:58
myself150627-Jul-03 1:58 
GeneralGet chat text from AOL Pin
Saquib Razak12-Jun-03 5:14
Saquib Razak12-Jun-03 5:14 
GeneralNot just a 'mechanism'... Pin
Heath Stewart27-Feb-03 19:11
protectorHeath Stewart27-Feb-03 19:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.