高手请进,关于SendMessage(,WM_GETTEXT,,)的问题

onhu 2006-12-15 12:51:18
我需要读取外部程序的多个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值变了,这是为什么?指针?
...全文
229 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wudi_1982 2006-12-15
  • 打赏
  • 举报
回复
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;
hangzhou_hammer 2006-12-15
  • 打赏
  • 举报
回复
new()?
cangwu_lee 2006-12-15
  • 打赏
  • 举报
回复
指针类型的,是不是要先分配空间?