Re: capturing text

Posted by WAllison on December 01, 2001:

In Reply to: capturing text posted by ace on November 06, 2001:

: ive got this code that captures text from a window that a mouse is over, can someone modify this code so that you can get the text from a specific window, like MSN Instant Messenger

: procedure TForm1.Timer1Timer(Sender: TObject);
: var Point : TPoint;
: //handle of the edit
: H : LongInt;
: //the window EdText
: EdText: pchar;
: ControlParent,AU: LongInt;
: begin
: //Get the current cursor position
: GetCursorPos(Point);
: //get the window at that point
: H := WindowFromPoint(Point);

: //get 300 char space in the memory
: Getmem(EdText,300);
: //GetWindowText(h,classe,300);
: SendMessage(H, WM_GETTEXT, 300, LongInt(EdText));
: //get controls parent
: Au := h;
: while ControlParent <> 0 do begin
: ControlParent := GetParent(AU);
: if ControlParent = 0 then begin
: ControlParent := AU;
: break;
: end;
: AU := ControlParent;
: end;

: Memo1.Text := string(EdText);
: //free the reserved memory
: freemem(EdText);
: end;

function EnumWindowsProc(wnd: hwnd; lb: TListBox): Boolean ;StdCall;
var lpBuffer: array [0..127] of Char;
begin
  GetWindowText(wnd, lpBuffer, 128);
  If Strlen(lpBuffer) <> 0 Then lb.Items.AddObject(lpBuffer, TObject( Wnd ));
  Result := True;
end;
procedure TMainForm.Button1Click(Sender: TObject);
begin
 ENumWindows(@ENumWindowsProc, longint(listbox1));
end;

This might help you - enumerates through all open windows saving the window handle in a TListBox...


[ DelphiLand FAQ ] [ Delphi Tutorials ]