Hi, I am trying to modify some code that grabs the contents of a chat window. Unfortunately the code is for MSN Messenger, and I'd like to try it with AIM. Basically, when executed, it takes the text from the window, copies it to the clipboard and then prints it out.
It basically gets the HWND by checking whether there is a MSN Conversation window open. This is done by using the EnumWindows() API. If it's open, it gets its HWND and checks its child windows to find a window having the window class 'RichEdit20W' or 'RichEdit20A'; this is done by using the EnumChildWindows() API. After getting the HWND of the conversation text window, it sends WM_COPY a message.
The problem is that AIM doesn't use RichEdit20W, it uses AteWindow. In Spy++ the hierarchy looks like:
[top_level] "ScreenName - Instant Message" AIM_IMessage
[child] "AteWindow" WndAte32Class
[childchild] '"' Ate32Class
The code responsible for finding the code is:
Code:
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 HERE
string::size_type pos=0;
pos=strTemp.rfind(" - Instant Message",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);
// THE OLD MSN MESSENGER USED THIS WINDOW
// I suppose I would change this string to find Ate32Class?
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;
}
Thanks for any input if you can help