Click here to Skip to main content
15,890,506 members
Articles / Programming Languages / C++
Article

Retrieving Conversations from MSN Messenger

Rate me:
Please Sign up or sign in to vote.
2.69/5 (20 votes)
27 Feb 20032 min read 110.2K   2.6K   47   13
Uses a simple copy/paste routine to get chat text from MSN Messenger.

Screenshot

Introduction

In this article I will show you how to retrieve conversation text from MSN Messenger. In another article I have shown how the same can be done with Yahoo Messenger which can be accessed here. So without wasting any time, lets explore MSN messenger.

In MSN Messenger, the window class of the window that contains conversation text is 'RichEdit20W' for Windows NT/2K and 'RichEdit20A' for Windows 95/98. These classes support copying their content to the clipboard by sending the WM_COPY message. Since the clipboard is available to all the applications in Windows any text copied from another application is available to all the applications in Windows. So to retrieve text from the MSN conversation window, simply copy text from the MSN Conversation window to the clipboard and paste it in your application. Simple isn't it? But sending WM_COPY message to this window requires an HWND of the 'RichEdit20W' window class window.

To get the HWND, first we need to check if there is any MSN conversation windows open, this can be done by using EnumWindows() API. If its open then get its HWND and check its child windows to find a window having the window class 'RichEdit20W' or 'RichEdit20A', this can be done using the EnumChildWindows() API. After getting the HWND of conversation text window, we need to send WM_COPY message. But sending WM_COPY message alone will be of no use if we don't select all the text in this window. I mean simulating 'Ctrl+A'. So, in total we need to send three window messages to the conversation window. First for selecting all the text in the conversation window by sending EM_SETSEL message with 0 for the WPARAM and -1 for the LPARAM; second for copying the selected text in clipboard by sending WM_COPY message; and third for deselecting the selected text by sending EM_SETSEL message with -1 for WPARAM and 0 for LPARAM value. This will be clear from the code snippet given below:

C++
//Code snippet
void CMSNChatTextDlg::OnGetnow() 
{
    if (! EnumWindows((WNDENUMPROC )EnumWindowsProc,0))
    return;
}

BOOL CALLBACK CMSNChatTextDlg::EnumWindowsProc(HWND hwnd,
LPARAM lParam)
{
    TCHAR buff[1000];
    int buffsize=100;
    HWND hMSNWnd;
    hMSNWnd=NULL;

    ::GetWindowText(hwnd,buff,buffsize);
    if (strlen(buff)<1)
        return TRUE;

    string strTemp(buff);

    //CHECK for MSN MESSENGER CHAT WINDOW
    string::size_type pos=0;
    pos=strTemp.rfind("- Conversation",strTemp.length());
    if (pos!=-1)
        EnumChildWindows(hwnd,ChildWndProc,0);

    return TRUE;
}

BOOL CALLBACK CMSNChatTextDlg::ChildWndProc(HWND hwnd,
LPARAM lParam)
{
    static int i=0;
    LPTSTR lptstr; 
    HGLOBAL hglb; 
    char wndowclass[CLASS_SIZE];

    if (GetClassName(hwnd,wndowclass,CLASS_SIZE)==0)
        return TRUE;

    string strTemp(wndowclass);
    if ((strTemp==string("RichEdit20W")) ||<BR>        (strTemp==string("RichEdit20A")))
    {
        ::SendMessage(hwnd,EM_SETSEL,0,-1); //start selecting
        ::SendMessage(hwnd,WM_COPY,0,0);
        ::SendMessage(hwnd,EM_SETSEL,-1,0); //end selecting 

        if (!IsClipboardFormatAvailable(CF_TEXT)) 
            return TRUE; 

        if (! ::OpenClipboard(NULL)) 
            return TRUE; 

        hglb = GetClipboardData(CF_TEXT); 
        if (hglb != NULL) 
        {
            lptstr = (LPTSTR)GlobalLock(hglb); 
            GlobalUnlock(hglb); 
            EmptyClipboard();
            CloseClipboard();

            pChatText->SetWindowText(lptstr);

            return FALSE;
        }
    }
    return TRUE;
}

This gives us the opportunity to make some fantastic SPYING applications that can email MSN conversations of someone to you or whatever you can think of!

In my next article, we will discuss how the same can be done with Yahoo messenger. Remember, WM_COPY messages does not work in Yahoo. We need to put some extra efforts to accomplish this.

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

 
Generaltrying to develop: adult content filter for protecting my kids. Pin
ZUPERKOOL7-Feb-10 5:05
ZUPERKOOL7-Feb-10 5:05 
QuestionHelp? Pin
heavenlyangelkf14-Apr-09 12:55
heavenlyangelkf14-Apr-09 12:55 
GeneralMessage Removed Pin
14-Apr-09 11:53
Mandai14-Apr-09 11:53 
Questionthe window class Pin
yadanwutuobang23-Apr-08 16:24
yadanwutuobang23-Apr-08 16:24 
Questionnew Pin
jade8-Dec-07 10:08
jade8-Dec-07 10:08 
QuestionHow do i use the code? [modified] Pin
batousaioiqw98-Apr-07 18:53
batousaioiqw98-Apr-07 18:53 
GeneralHelp Pin
Tj.15-Nov-06 23:16
Tj.15-Nov-06 23:16 
Generalwould this work for windows live messenger Pin
xsouldeath18-Sep-06 14:06
xsouldeath18-Sep-06 14:06 
Generalin msn7.5 or 8.0... Pin
lsmart12-Jun-06 21:43
lsmart12-Jun-06 21:43 
Generalnot working Pin
amanwas9-Jan-05 11:06
amanwas9-Jan-05 11:06 
Generalthanx Pin
EPulse29-Nov-04 18:01
EPulse29-Nov-04 18:01 
Generalcool Pin
zhongxunyang3-Oct-03 21:48
zhongxunyang3-Oct-03 21:48 
Generalgetting the e-mail Pin
AlejoCL28-May-03 8:37
AlejoCL28-May-03 8:37 
Generalcool stuff Pin
matty1595-Mar-03 23:12
matty1595-Mar-03 23:12 

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.