CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> Visual C++ / C++ >> Internet & Networking >> Internet Protocols >> Instant Messaging


Retrieving Conversation text from Instant Messengers - Part I
Rating: none

Deepesh Dhapola (view profile)
February 21, 2003


(continued)



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

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
need help. - shrirangps (02/10/2005)
How to send out message from my program on MSN6.0? - zhgfhz (07/16/2004)
retrieving messages??? - Legacy CodeGuru (02/13/2004)
MSN 6.0? - Legacy CodeGuru (09/25/2003)
!!!!msn 6 its DirectUIHWND ...not these."RichEdit20W.."... - Legacy CodeGuru (08/26/2003)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES