All pastes #2046752 Raw Edit

Stuff

public text v1 · immutable
#2046752 ·published 2011-04-15 10:43 UTC
rendered paste body
function TVrMessageDlg.GetTextSize(hWnd, hFont: HWND; const Text: String): TSize;
var
 p1, p2, LineCnt: Integer;
 hDC: THandle;
 Line: string;
 Size: TSize;
begin
 Result.cx:= 0;
 Result.cy:= 0;
 if IsWindow(hWnd) and (FhFont <> 0) then
  begin
   hDC:= GetDC(hWnd);
   SelectObject(hDC, FhFont);
   LineCnt:= 0; //количество строк в тексте

     p2:= 1;
     while p2 <= length(Text) do
      begin
       while (p2 <= length(Text)) and (Text[p2] in [#13]) do inc(p2);
       if p2 <= length(Text) then
        begin
         p1:= p2;
         while (p2 <= length(Text)) and not(Text[p2] in [#13]) do inc(p2);

         Line:= Copy(Text, p1, p2 - p1);
         if GetTextExtentPoint32(hDC, PChar(Line), Length(Line), Size) then
          begin
          if Result.cx < Size.cx then
           Result.cx:= Size.cx;
           Result.cy:= Size.cy;
          end;
         inc(LineCnt);
        end;
      end;
    Result.cy:= Result.cy * LineCnt;
  end;
end;