如何得到其他程序的richedit中的数据

 我来答
鸢梨的小布丁
2015-11-08 · TA获得超过2.8万个赞
知道大有可为答主
回答量:2.3万
采纳率:21%
帮助的人:2243万
展开全部
跨进程获得RichEdit Text参考:

Delphi(Pascal) code
uses RichEdit;

function Process_ReadRichEditText(AHandle: THandle): WideString;
var
vGetTextEx: GETTEXTEX;
vGetTextLengthEx: GETTEXTLENGTHEX;
L: Integer;

vProcessId: DWORD;
vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
begin
Result := '';
if not IsWindow(AHandle) then Exit;
GetWindowThreadProcessId(AHandle, @vProcessId);
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
try
vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
vGetTextLengthEx.flags := GTL_DEFAULT;
vGetTextLengthEx.codepage := 1200; // Unicode
WriteProcessMemory(vProcess, vPointer, @vGetTextLengthEx,
SizeOf(vGetTextLengthEx), vNumberOfBytesRead);
L := SendMessage(AHandle, EM_GETTEXTLENGTHEX, Integer(vPointer), 0);
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
end;
if L <= 0 then Exit;
vPointer := VirtualAllocEx(vProcess, nil, SizeOf(vGetTextEx) + L * 2 + 2,
MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
try
SetLength(Result, L);
vGetTextEx.cb := L * 2 + 2; // 加上结束符号
vGetTextEx.flags := GT_DEFAULT;
vGetTextEx.codepage := 1200; // Unicode
vGetTextEx.lpDefaultChar := nil;
vGetTextEx.lpUsedDefChar := nil;
WriteProcessMemory(vProcess, vPointer, @vGetTextEx,
SizeOf(vGetTextEx), vNumberOfBytesRead);
SendMessage(AHandle, EM_GETTEXTEX, Integer(vPointer),
Integer(vPointer) + SizeOf(vGetTextEx));
ReadProcessMemory(vProcess, Pointer(Integer(vPointer) + SizeOf(vGetTextEx)),
@Result[1], L * 2, vNumberOfBytesRead);
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
end;
finally
CloseHandle(vProcess);
end;
end; { Process_ReadRichEditText }

调试代码(环境是XP):

Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
var
vHandle: THandle;
begin
vHandle := FindWindow('WordPadClass', nil);
if vHandle = 0 then Exit;
vHandle := FindWindowEx(vHandle, 0, 'RICHEDIT50W', nil);
if vHandle = 0 then Exit;
Memo1.Text := Process_ReadRichEditText(vHandle);
end;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
可以叫我表哥
推荐于2016-08-30 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
采纳数:25897 获赞数:1464989
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。

向TA提问 私信TA
展开全部
原帖地址:http://topic.csdn.net/u/20080709/18/389bf9eb-f694-4cf2-84c4-4bd6c778b19e.html
跨进程获得RichEdit Text参考:

Delphi(Pascal) code
uses RichEdit;

function Process_ReadRichEditText(AHandle: THandle): WideString;
var
vGetTextEx: GETTEXTEX;
vGetTextLengthEx: GETTEXTLENGTHEX;
L: Integer;

vProcessId: DWORD;
vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
begin
Result := '';
if not IsWindow(AHandle) then Exit;
GetWindowThreadProcessId(AHandle, @vProcessId);
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
try
vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
vGetTextLengthEx.flags := GTL_DEFAULT;
vGetTextLengthEx.codepage := 1200; // Unicode
WriteProcessMemory(vProcess, vPointer, @vGetTextLengthEx,
SizeOf(vGetTextLengthEx), vNumberOfBytesRead);
L := SendMessage(AHandle, EM_GETTEXTLENGTHEX, Integer(vPointer), 0);
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
end;
if L <= 0 then Exit;
vPointer := VirtualAllocEx(vProcess, nil, SizeOf(vGetTextEx) + L * 2 + 2,
MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
try
SetLength(Result, L);
vGetTextEx.cb := L * 2 + 2; // 加上结束符号
vGetTextEx.flags := GT_DEFAULT;
vGetTextEx.codepage := 1200; // Unicode
vGetTextEx.lpDefaultChar := nil;
vGetTextEx.lpUsedDefChar := nil;
WriteProcessMemory(vProcess, vPointer, @vGetTextEx,
SizeOf(vGetTextEx), vNumberOfBytesRead);
SendMessage(AHandle, EM_GETTEXTEX, Integer(vPointer),
Integer(vPointer) + SizeOf(vGetTextEx));
ReadProcessMemory(vProcess, Pointer(Integer(vPointer) + SizeOf(vGetTextEx)),
@Result[1], L * 2, vNumberOfBytesRead);
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
end;
finally
CloseHandle(vProcess);
end;
end; { Process_ReadRichEditText }

调试代码(环境是XP):

Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
var
vHandle: THandle;
begin
vHandle := FindWindow('WordPadClass', nil);
if vHandle = 0 then Exit;
vHandle := FindWindowEx(vHandle, 0, 'RICHEDIT50W', nil);
if vHandle = 0 then Exit;
Memo1.Text := Process_ReadRichEditText(vHandle);
end;
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ya...3@163.com
2015-01-10
知道答主
回答量:9
采纳率:0%
帮助的人:10.8万
展开全部
唯有源头活水来。水是没有生命的,
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
魔脑1688
2016-03-24
知道答主
回答量:14
采纳率:0%
帮助的人:3.4万
展开全部
具体问题具体分析,每个程序RICHEDIT用的方法不一样.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式