获取编辑框中显示出来的字符<br>function EditVisibleText(mEdit: TEdit): string;<br>var<br> X, Y, L: Integer;<br> S: string;<br>begin<br> result := '';<br> if not Assigned(mEdit) then Exit;<br> with mEdit do try<br> S := Text;<br> L := Length(S);<br> X := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(2, 2));<br> X := X and $0000FFFF;<br> Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(ClientWidth - 4, 2));<br> Y := Y and $0000FFFF;<br> for X := X to Y - 1 do if (Y >= 0) and (X < L) then<br> result := result + S[X + 1];<br> except<br> result := '';<br> end;<br>end; { EditVisibleText }<br><br><br><br>function MemoVisibleText(mMem TMemo; mStrings: TStrings): Boolean;<br>var<br> I, X, Y: Integer;<br> L, H, W: Integer;<br> S: string;<br> T: string;<br>begin<br> result := False;<br> if (not Assigned(mMemo)) or (not Assigned(mStrings)) then Exit;<br> with TControlCanvas.Create do try<br> Control := mMemo;<br> H := TextHeight('|');<br> finally<br> Free;<br> end;<br> mStrings.Clear;<br> with mMemo do try<br> S := Text;<br> L := Length(S);<br> W := ClientWidth;<br> for I := 0 to (ClientHeight div H) - 1 do begin<br> X := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(3, I * H + 2));<br> X := X and $0000FFFF;<br> Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(5, I * H + 2));<br> Y := Y and $0000FFFF;<br> if Abs(Y - X) > 1 then Inc(X);<br> if not ((X = 0) or ((X < L) and (S[X - 1] in [#13, #10]))) then Inc(X);<br> Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(W - 2, I * H + 2));<br> Y := Y and $0000FFFF;<br> T := '';<br> for X := X to Y - 1 do if (Y >= 0) and (X < L) then<br> T := T + S[X + 1];<br> mStrings.Add(T);<br> end;<br> except<br> Exit;<br> end;<br> result := True;<br>end; { MemoVisibleText }<br>////////end Source<br><br><br><br>////////begin Demo<br><br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> MemoVisibleText(Memo1, Memo2.Lines);<br>end;<br><br><br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> Caption := EditVisibleText(Edit1);<br>end;<br>////////end Demo<br><br>