Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#3

Re: [nonVCL] Textlänge & GetWindowText, ExtTextOut Probl

  Alt 16. Mär 2006, 09:37
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  Buffer : PChar;
  len : Integer;
begin
  len := GetWindowTextLength(Handle);
  if len > 0 then
  begin
    try
      GetMem(Buffer, len);
      GetWindowText(Handle, Buffer, len);
      TextOut(Canvas.Handle, 10, 10, Buffer, len);
    finally
      FreeMem(Buffer);
    end;
  end
  else
    ShowMessage(SysErrorMessage(GetLastError));
end;
Aber beachte:
Zitat:
GetWindowTextLength cannot retrieve the length of the text of an edit control in another application.
Und:
Zitat:
Under certain conditions, the GetWindowTextLength function may return a value that is larger than the actual length of the text. [..] It can also occur when an application uses the ANSI version of GetWindowTextLength with a window whose window procedure is Unicode, or the Unicode version of GetWindowTextLength with a window whose window procedure is ANSI.
Zitat:
To obtain the exact length of the text, use the WM_GETTEXT, LB_GETTEXT, or CB_GETLBTEXT messages, or the GetWindowText function.
Und zu GetWindowText:
Zitat:
This function cannot retrieve the text of an edit control in another application.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat