我需要读取外部程序的多个Edit上的数据
用SendMessage可以读到一个,但下一个就出问题了
=====================================
var
  hChildWin1:HWND;
  txtLength:integer;
  p,p2:pchar;
//////////////
    SendMessage(hChildWin1,WM_GETTEXT,15,longint(p)) ;//
    Edit6.Text:=string(p);
    hChildWin1 := GetWindow(hChildWin1, GW_HWNDNEXT); // 16
    SendMessage(hChildWin1,WM_GETTEXT,15,integer(p2));
    Edit7.Text:=string(p2);
结果只能出来第一个,把第一个注释掉,第二个却能出来了。
还有本来我是两个都用p的,结果两个都变乱码了,好像是p不能更改,一更改就Edit值变了,这是为什么?指针?

解决方案 »

  1.   

    WM_GETTEXT
    This message is sent by an application to copy the text that corresponds to a window into a buffer provided by the caller. WM_GETTEXT wParam = (WPARAM) cchTextMax; 
      lParam = (LPARAM) lpszText;
    Parameters
    cchTextMax 
    Specifies the maximum number of characters to be copied, including the terminating null character. 
    lpszText 
    Long pointer to the buffer that is to receive the text.procedure 
    用指针记得分配空间
    TForm1.Button2Click(Sender: TObject);
    var
      Mwd,Cwd :LongInt ;  p : pchar;
    begin
      Mwd :=FindWindow(nil,'Form1');  Cwd :=FindWindowEx(Mwd,0,'TEdit',nil);
      p := AllocMem(15*sizeof(char));
      SendMessage(Cwd,WM_GETTEXT,15,longint(p));  Edit1.Text := p;
      SendMessage(Cwd,WM_GETTEXT,15,longint(p));  Edit1.Text := p;
      FreeMem(p);
    end;