這個就是我的主程式(問題在我今天發的第一個文章中)

來源:互聯網
上載者:User
這個就是我的主程式(問題在我今天發的第一個文章中) Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061117132223208.html
Hook.dll代碼在我今天發的第一個文章中  
   
  unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls;  
   
  type  
      TForm1   =   class(TForm)  
          Button1:   TButton;  
          Memo1:   TMemo;  
          Memo2:   TMemo;  
          procedure   Button1Click(Sender:   TObject);  
          procedure   WMCOPYDATA(Var   Msg:TMessage);message   WM_COPYDATA;  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
   
  implementation  
   
  {$R   *.dfm}  
      function   StartSpyMessage(AHSpyWnd,   AHRevWnd:   THandle):   Boolean;   stdcall;external   'hook.dll';  
      procedure   StopSpyMessage;stdcall;external   'hook.dll';  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
      MWnd:THandle;  
      CWnd:THandle;  
      EWnd:THandle;  
  begin  
      memo1.Lines.Clear;  
      MWnd:=FindWindow(nil,'BMML   Window:   COM1   Stack');     //擷取視窗控制代碼  
      CWnd:=FindWindowEx(MWnd,0,'AfxMDIFrame40',nil);       //擷取一級控制代碼  
      EWnd:=FindWindowEx(CWnd,0,'Edit',nil);                         //擷取Edit控制項控制代碼  
   
      If   EWnd=0   then  
          showmessage('程式沒運行')  
      Else  
          memo1.Lines.Add(inttostr(EWnd));  
   
      if   StartSpyMessage(EWnd,form1.Handle)   then  
            showmessage('啟動成功');  
  end;  
   
  procedure   TForm1.WMCOPYDATA(var   Msg:   TMessage);  
  Var  
      Data:CopyDataStruct;  
      S:String;  
  begin  
      Data:=PCopyDataStruct(Msg.LParam)^;  
      with   Data   do  
      Begin  
          S:='資料類別代碼'+inttostr(cbData)+'       '+'訊息實際資料'+PChar(lpData);  
      end;  
      Memo2.Lines.Add(s);  
  end;  
   
  end.

該程式的確可以攔截那個程式中Edit控制項的訊息,但顯示的卻為空白的  
   
  裡面主要是用到WM_COPYDATA訊息來傳遞我要的訊息,因為對訊息作業不熟悉,所以不知道在怎麼寫了  
  Hook.dll中攔截到訊息以後,通過WM_COPYDATA訊息發送到我的主程式  
  在主程式中我寫了一個訊息過程,也的確是收到效果,可就是得到的是空的,麻煩高手們幫我看看問題出在那裡了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.