Retrieving Conversation text from Instant Messengers - Part I

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

In this two-article series, I will show you how to retrieve conversation text from two most popular Instant Messengers (MSN and Yahoo). In the first article, we will talk about MSN Messenger. In the second article, we will discuss Yahoo Messenger. So without wasting any time, let's explore MSN Messenger now.

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 WM_COPY a message. Because the Clipboard is available to all the applications in Windows, if some text is copied from an application, it's available to all Windows applications. So, to retrieve text from a MSN Conversation window, simply copy the text from the MSN Conversation window to the Clipboard and paste it into your application. Simple, isn't it? But, sending the WM_COPY message to this window requires HWND of the 'RichEdit20W' Windows class window.

To get the HWND, first we need to check whether there is a MSN Conversation window open. This can be done by using the EnumWindows() API. If it's open, get its HWND and check its child windows to find a window having the window class 'RichEdit20W' or 'RichEdit20A'; this can be done by using the EnumChildWindows() API. After getting the HWND of the conversation text window, we need to send WM_COPY a message. But, sending WM_COPY a 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. The first will select all the text in the conversation window by sending EM_SETSEL message with 0 for WPARAM and -1 for LPARAM; the second will copy the selected text in the Clipboard by sending WM_COPY a message and third will deselect the selected text by sending EM_SETSEL a message with -1 for WPARAM and 0 for the LPARAM value. This will be clear from the code snippet given below...

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")) ||
      (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 e-mail MSN conversations of someone to you or whatever you can think of!

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

Downloads

Download demo project - 4.50 Kb
Download source - 28.3 Kb


Comments

  • NikeFree again four shoes warm in autumn and winter adopt relieve is very documentation

    Posted by Speadyday on 04/19/2013 05:23am

    Nike Free TR Becoming 2 Bulwark upper of textile materials in line with seasonal requirements, enhances the love and durability, and meditating constituents, in [url=http://www.nikeskoroutlet.se/nike-free-trainer-50-c-48/]nike free trainer[/url] rotten visibility when happy and DWR (sturdy tone down resistant) coating to carry out breathability while, cause to feet wilt in wet weather. Shoe upper welt on the inside of the bow suds enhances foot take up the cudgels for and stability. Complexion proportion of the Nike Permitted shoe Slot lay out provides flexible like bare feet handle and sturdiness of multi-direction movement while [url=http://www.nikeskornatet.se/nike-air-max-97-hyperfuse-c-80/]air max hyperfuse[/url] retaining tenure and shockproof main attraction essential in training shoes. Lightweight Phylite midsole can deliver and tons of durability, which increments the benefit exponentially outsole, which significantly reduces the bulk of the shoe. Tail and foot rubber grooves made of environmentally buddy-buddy materials, stop to reinforce its [url=http://www.nikeskorrea.se/nike-free-50-v4-c-3/]nike free 5.0 v4[/url] multi-directional understanding on all kinds of roadway surfaces.

    Reply
  • need help.

    Posted by shrirangps on 02/10/2005 12:23am

    i want to check the online status for any given msn user.. the contact may not be in my contact list.. can anyone help me doing it! thanks and regards.

    Reply
  • retrieving messages???

    Posted by Legacy on 02/13/2004 12:00am

    Originally posted by: Jim

    I want to retrive a conversation that I wrote with a friend on msn messenger. This conversation took place a few days ago. where would I look to find this conversation or how can I retrieve it? not much of a techy and i didn't have any of the above stuff on my puter. any help would be great.

    Many thanks

    Jim

    Reply
  • MSN 6.0?

    Posted by Legacy on 09/25/2003 12:00am

    Originally posted by: Umashankar

    Does anybody know how to get chat window text in MSN 6.0?
    Thanks
    -Umesh

    Reply
  • !!!!msn 6 its DirectUIHWND ...not these."RichEdit20W.."...

    Posted by Legacy on 08/26/2003 12:00am

    Originally posted by: sibilsalim

    msn 6 its DirectUIHWND ...not these-->"RichEdit20W.."..
    even after changing to this new class ..its not working help ..me
    bye..
    help me at sibilsalim@operamail.com

    • How to send out message from my program on MSN6.0?

      Posted by zhgfhz on 07/16/2004 06:54pm

      In MSN5.0, I can send out message by setwindowtext and click button. But on MSN6.0, how to do it? Since it is DirectUIHWND. Very helpful to me. Thanks first. Juck

      Reply
    Reply
  • C++ Code under Linux?

    Posted by Legacy on 06/15/2003 12:00am

    Originally posted by: toby

    Has anyone every tried using it with Linux?

    Reply
  • Separate files

    Posted by Legacy on 05/27/2003 12:00am

    Originally posted by: AlejoCL

    Hi,
    I'd like to save the conversations into a file. One file per conversation. Also, I'd like to "get" the mail (at least) of the other part.

    Thank you for your help.

    Alejo

    Reply
  • Does this really work..?

    Posted by Legacy on 04/29/2003 12:00am

    Originally posted by: Gizzy

    I am a little confusd. Now, Does this enable you to spy on someone else's conversation with a third person...? As if you are physically not there, but still able to read the converstaion between 2 people...?

    Reply
  • cont retrieve saved msn conversations

    Posted by Legacy on 03/23/2003 12:00am

    Originally posted by: courtney

    i had a conversation with a friend of mine and my parents would like to see it. all our msn conversations are saved on our computer but we dont know where to look if anyone cant help pleeze its very important!!!

    ~*Courtie*~

    Reply
  • need help

    Posted by Legacy on 02/26/2003 12:00am

    Originally posted by: ranvijay

    i need ur help in my application.i am developing yahoo messenger like application and i'm using rtf control for giving text formatting capability.but how could i maintain text format of messages on destination side.
    
    please help me.
    ranvijay

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds