Unit1.cpp
上传用户:icamtech04
上传日期:2007-03-13
资源大小:278k
文件大小:5k
源码类别:

ICQ弱点检测代码

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Clipbrd.hpp>
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "EditValue"
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. HANDLE parent;    //RICHEDIT的父窗口句柄
  12. HANDLE rich;      //RICHEDIT的句柄
  13. HANDLE rich_s;      //用于查找 RICHEDIT
  14. HANDLE hSend_s;   //用于查找 发送 按钮
  15. HANDLE hSend;     //保存发送按钮句柄
  16. static bool anniu = true;
  17. static int index1 = 0;
  18. bool CALLBACK EnumProc(HWND,long);  //枚举窗口
  19. bool CALLBACK EnumChildProc(HWND,LPARAM); //枚举子窗口
  20. struct Node          //设置一结构,用于保存聊天窗口,RICHEDIT和发送句柄
  21. {
  22.   HANDLE Savehwnd[20];
  23.   HANDLE Saverich[20];
  24.   HANDLE SavehSend[20];
  25. }Saveinfo;
  26. //---------------------------------------------------------------------------
  27. __fastcall TForm1::TForm1(TComponent* Owner)
  28.   : TForm(Owner)
  29. {
  30. }
  31. //---------------------------------------------------------------------------
  32. void __fastcall TForm1::Button2Click(TObject *Sender)
  33. {
  34. Close();  
  35. }
  36. //---------------------------------------------------------------------------
  37. bool CALLBACK EnumProc(HWND hwnd,long lp)
  38. {
  39.   char biaoti[80];
  40.   GetWindowText(hwnd,biaoti,81);
  41.   if ( AnsiString(biaoti).Pos("与") || AnsiString(biaoti).Pos("群"))
  42.   { //判断标题是否是QQ聊天窗口,如果你还开着其他窗口与这样的查找设置巧合
  43.     //的话。。。。。。 唉~~
  44.     Form1->ComboBox1->Items->Add(biaoti);
  45.     Saveinfo.Savehwnd[index1++] = hwnd;    //保存聊天窗口句柄
  46.   }
  47.   EnumChildWindows(hwnd,reinterpret_cast<WNDENUMPROC>(EnumChildProc),0L);
  48.     return true;
  49. }
  50. bool CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
  51. {
  52.   char buf[80];
  53.   GetClassName(hwnd, buf, sizeof(buf));
  54.   hSend_s = FindWindowEx(hwnd, NULL, "Button", "发送(&S)");
  55.   if (hSend_s != NULL)
  56.   {
  57.     Saveinfo.SavehSend[index1-1] = hSend_s;
  58.     hSend = hSend_s;
  59.   }
  60.   if ( AnsiString(buf).Pos("AfxWnd42") )
  61.   { //QQ发送消息的RICHEDIT的父窗口类名是 AfxWnd42
  62.     parent = hwnd;
  63.     rich_s =  FindWindowEx(parent, NULL, "RICHEDIT",0);
  64.     if (GetParent(rich_s) == parent)  //RICHEDIT类名有很多,关键看他的父窗口是否是AfxWnd42
  65.     {
  66.       Saveinfo.Saverich[index1-1] = rich_s;
  67.     }      
  68.     return true;
  69.   }
  70.   else
  71.   {
  72.     EnumChildWindows(hwnd,reinterpret_cast<WNDENUMPROC>(EnumChildProc),0L);
  73.     return true;
  74.   }
  75. }
  76. void __fastcall TForm1::FormCreate(TObject *Sender)
  77. {
  78.   EnumWindows(reinterpret_cast<WNDENUMPROC>(EnumProc),0L);
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  82. {
  83.   RichEdit1->SelectAll();            //本程序的‘消息内容’全选
  84.   RichEdit1->CopyToClipboard();      //复制到剪贴板
  85.   if (IsWindow(Saveinfo.Savehwnd[ComboBox1->ItemIndex]))  //判断句柄是否有效
  86.   {
  87.     SendMessage(Saveinfo.Saverich[ComboBox1->ItemIndex], WM_PASTE, 0, 0);
  88.     SendMessage(Saveinfo.SavehSend[ComboBox1->ItemIndex],WM_LBUTTONDOWN,MK_LBUTTON ,0);
  89.     SendMessage(Saveinfo.SavehSend[ComboBox1->ItemIndex],WM_LBUTTONUP,MK_LBUTTON,0);
  90.   }
  91.   else
  92.   {
  93.     Timer1->Enabled = false;
  94.     ShowMessage("该聊天窗口已经无效了!");
  95.   }
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TForm1::Button1Click(TObject *Sender)
  99. {
  100.   if (anniu)
  101.   {
  102.     if (ComboBox1->GetTextLen() !=0 )  //判断是否选择了窗口
  103.     {
  104.       Button1->Caption = "停止";
  105.       Timer1->Enabled = true;
  106.       int x = StrToInt(Edit2->Text);
  107.       if (x<500 )
  108.       { //时间间隔太小的话对网速不利,限制在500ms
  109.         ShowMessage("时间间隔太小,最好不低于500ms");
  110.         x = 500;
  111.       }
  112.       Timer1->Interval = x;
  113.     }
  114.     else
  115.     {
  116.       ShowMessage("没有找到QQ聊天窗口");
  117.       return;
  118.     }
  119.   }
  120.   else
  121.   {
  122.     Button1->Caption = "发送";
  123.     Timer1->Enabled = false;
  124.   }
  125.   anniu = !anniu;
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TForm1::Button3Click(TObject *Sender)
  129. {  //重新找窗口时做的事情
  130. index1 = 0;
  131. ComboBox1->Items->Clear();
  132. ComboBox1->Text = "";
  133. ::EnumWindows(reinterpret_cast<WNDENUMPROC>(EnumProc),0L);   
  134. }
  135. //---------------------------------------------------------------------------
  136. void __fastcall TForm1::Edit2KeyPress(TObject *Sender, char &Key)
  137. { //只容许‘发生时间间隔’ 的输入为数字,原本这个编辑已有禁止输入字符的功能了
  138.   if (Key == (char)'.')
  139.     Key =0;
  140. }
  141. //---------------------------------------------------------------------------
  142. void __fastcall TForm1::ComboBox1KeyPress(TObject *Sender, char &Key)
  143. { //禁止向ComboBox1输入字符,只容许选择
  144.   Key = 0;  
  145. }
  146. //---------------------------------------------------------------------------