• [ZT]如何得到其他程序的Richedit中的RTF数据


    原帖地址: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;



  • 相关阅读:
    .net正在终止线程异常
    js判断客户浏览器类型,版本
    C#中ToString格式大全
    WPF TextBox 搜索框 自定义
    C#:获取设备电量相关信息
    C#中的委托与事件并存的理由
    WPF中的Pack URI
    SQLServer中的数据库备份和还原
    使用Aspose.Cells读取Excel
    SQLServer存储过程事务用法
  • 原文地址:https://www.cnblogs.com/rainbow57/p/1441831.html
Copyright © 2020-2023  润新知