zoukankan      html  css  js  c++  java
  • [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;



  • 相关阅读:
    迭代器和生成器
    函数嵌套
    页面调用dll
    C++MFC之picture control控件铺满图片
    C++中去掉string字符串中的 等
    C++之map使用
    C++之条形码,windows下zint库的编译及应用(二)
    C++之条形码,windows下zint库的编译及应用(一)
    C++通过HTTP请求Get或Post方式请求Json数据(转)
    从长字符串中获取想要的字符串
  • 原文地址:https://www.cnblogs.com/rainbow57/p/1441831.html
Copyright © 2011-2022 走看看